question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResponsiveLine strange refresh when updating data

See original GitHub issue

Describe/explain the bug I have a Chart component for the ResponsiveLine which receives some parameters and data series. I’m calculating the ticks accordingly to the length of my series and the dates (for example, dynamically saying like every 7 days, every 2 months, and so on ).

I’m not remounting the component when the data changes. I’m just passing the updates settings to the props, because I wanted it to animate when the data changes.

However, it seems to have a strange behavious when the data length is greater than 40 data points. When it’s less than that, the component refreshes and animate smoothly, but if I pass something like 2 series of 42 and 50 points the animation crashes, the app slows down, the labels start to overlap, like in this example gif:

chart-refresh

On the other hand, if I force the component to re-mount the problem does not happen (but then I dont have the animation)

chart-refresh2

Expected behavior Chart animation occurs normally

Desktop (please complete the following information):

  • OS: MacOS 10.15.4
  • Browser Chrome, Firefox…
  • Version: "@nivo/line": "^0.61.1",

Additional context This is my component

<ResponsiveLine
      data={data as Serie[]}
      margin={{
        top: 20, right: 30, bottom: 80, left: 50,
      }}
      xScale={{
        type: 'time', format: '%Y-%m-%d', precision: 'day', useUTC: false,
      }}
      yScale={{
        type: 'linear', min: 0, max: maxYScale, stacked: false, reverse: false,
      }}
      tooltip={LineTooltip}
      axisBottom={{
        orient: 'bottom',
        renderTick: LineDateTick,
        tickValues: xScaleTickValues,
      }}
      axisLeft={{
        orient: 'left',
        tickSize: 0,
        tickPadding: 15,
        tickRotation: 0,
        tickValues,
        legend: '',
        legendOffset: -40,
        legendPosition: 'middle',
        format: (value): string => formatLeftAxis(value, divisor, unit),
      }}
      colors={{ datum: 'color' }}
      pointSize={5}
      pointColor="#FFFF"
      pointBorderWidth={2}
      pointBorderColor={{ from: 'serieColor' }}
      pointLabelYOffset={-15}
      enableSlices={false}
      useMesh
      onMouseMove={handleMouseMove}
      crosshairType="cross"
      motionStiffness={280}
      legends={enableLegends ? [{
        anchor: 'bottom',
        direction: 'row',
        justify: false,
        translateX: 20,
        translateY: 75,
        itemsSpacing: 0,
        itemDirection: 'left-to-right',
        itemWidth: 190,
        itemHeight: 30,
        itemOpacity: 0.75,
        symbolSize: 12,
        symbolShape: 'circle',
        symbolBorderColor: 'rgba(0, 0, 0, .5)',
      }] : []}
      theme={{
        axis: {
          domain: {
            line: {
              stroke: '#F3F3F3',
              strokeWidth: 1,
            },
          },
        },
        grid: {
          line: {
            stroke: '#FFFF',
            strokeWidth: 1,
          },
        },
      }}
    />

In case it is something not possible to fix, is there any kind of “intro” animation for the chart once it gets mounted?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
asaeedcommented, Mar 11, 2021

My workaround with React Hooks is to have a useEffect to watch for changes to data (whether it’s coming from app state or a prop) and assign to a local state variable, eg:

const [localData, setLocalData] = useState([])

useEffect(() => {
    setLocalData(data)
  }, [data])

return (
      <ResponsiveLine
        data={localData}
        ...
7reactions
nigellimacommented, Aug 24, 2020

@plouc Hello. How are you? Do you have any updates on this issue? Or, could you point me to where this issue is possibly present so I could help to fix this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is nivo's responsive line chart not rendered in jsdom ...
If i am not wrong; nivo doesnt render custom data-* props. So giving it a data-testid might not work.
Read more >
Excel Pivot Table Refresh Steps and Fixes - Contextures
A quick and easy way to refresh a pivot table after the data changes is to manually update it: Right-click any cell in...
Read more >
[Solved]-ReactJS/Nivo Graphs - How to modify the x-axis to be ...
Coding example for the question ReactJS/Nivo Graphs - How to modify the x-axis to be ascending date order when data contains "incomplete" data?-Reactjs....
Read more >
Refresh Pivot Tables Automatically When Source Data Changes
I also share a non-macro solution to update the pivot tables when the file is opened. Includes video tutorial and Excel file download....
Read more >
The line chart display wrong when I change data and refresh ...
When click in Refresh button, I will clear the DataPointList and add new data with only data for Tue, Wed, Thu, Sat and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found