zakodium-oss / react-plot

Library of React components to render SVG 2D plots. You can check the story book https://react-plot.pages.dev/ or have a look to the extensive documentation
https://react-plot.zakodium.com
MIT License
12 stars 6 forks source link

Ticks map using tick.position #437

Closed ghost closed 1 year ago

ghost commented 1 year ago

Edit: this is just a warning in the console but may be possible to fix?

Example

  <LineSeries data={[ {x:0, y:0}, {x:0, y:1} ]} />

There should not be x:0 repeated but this would be common when having multiple possible axis combinations:

Error seems to come from this line. where the getPositions takes an x value to make the ticks (it seems so.)

Console Log This is the text error from the console:

Warning: Encountered two children with the same key, `0`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Ticks@http://localhost:3000/static/js/bundle.js:34723:7
VerticalAxis@http://localhost:3000/static/js/bundle.js:34910:7
LinearAxis@http://localhost:3000/static/js/bundle.js:34522:7
Axis@http://localhost:3000/static/js/bundle.js:34113:7
targos commented 1 year ago

The stack trace shows that the error happens with VerticalAxis, so it seems that we should use the y position instead of x.

ghost commented 1 year ago

It seems to be always the axis for which the min and max value is the same, and disappear if there is max and min in the Axis props. From what I see here at least.

This line could be adding too many Ticks.

The problem seems to disappear with:

targos commented 1 year ago

I've tried the example you posted above and there's only one tick:

image

ghost commented 1 year ago

It seems that the warning happens if the data is modified while the live server is running (if it is started from scratch with it, there is no error. Maybe you can test that.)

The same thing seems to happen if a click button is allowed to change the data:

And the source.

targos commented 1 year ago

OK I see, thank you for the reproducible example. The bug is in https://github.com/zakodium-oss/react-d3-utils/blob/6bdf5d6c3983973352bc4a27c72332398cbda5f6/src/hooks/useLinearPrimaryTicks.ts#L27-L39 (we apply the new scale to old ticks from the state). Working on a fix...

ghost commented 1 year ago

Oh, I see. It makes more sense now. You are welcome.