Static scaling options not working on live chart?
See original GitHub issueI’m working with v1.0.11 and have setup a chart where the x and y scale use a static range scale, e.g:
let opts = { scales: { "x": { time: false, auto: false, range: [0, 100] }, "y": { auto: false, range: [0, 100] }, }, }
This works fine until I try to zoom and update the data.
To do that, I call e.g. setRange('y', { min: 4, max: 10})
setScale('y', { min: 4, max: 10})
.
When I now call setData
on my chart instance, it resets my previously set scale.
I also noted, that the API documentation states that there is a second parameter on setData
allowing to
prevent this behavior, but when I do that, it not only does not reset the scale, it also does not redraw anymore.
/** sets the chart data & redraws. (default resetScales = true) */
setData(data: uPlot.AlignedData, resetScales?: boolean): void;
I would have expected that it would accept the data and redraw it on the existing scaling.
The only way I could find to get the desired behavior so far was to set the data and then fix the scale, e.g.:
setData(myData, false);
setScale('y', { min: 4, max: 10})
But this can’t be the way it should be, can it?
I think the streaming-data demo has the same issue. Even though zooming seems to be possible, it doesn’t work.
Edited: Corrected the wrongly used: ‘setRange’ to what I actually meant: ‘setScale’.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
gonna close this since i’m not sure there’s anything left to do here, but feel free to discuss further if necessary.
i pushed a few commits, but they’ll make little difference for the streaming case.
well, not the way it works now, which is to grab the data min/max (in auto mode) and pass those to range() and respect whatever range() returns as the final answer. anything different would be pretty confusing.
the whole thing is rather nuanced because for streaming you may want x.auto: true, but only when “zoomed out”. there are a lot other behaviors you may need, and simply relying on auto is insufficient for a zoomable streaming case - you still need to do a custom range and call setData/false & setScale / redraw() granularly because there’s not one solution i can think of that is sensible for everyone given the vast array of options that can be active.