leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.48k stars 370 forks source link

Is there a way to reset scales programmatically? #924

Open trufflesprouts opened 2 months ago

trufflesprouts commented 2 months ago

I'm trying to add a button to reset all scales similar to the way that double click works. Is there way to invoke the built in implementation of double click? or any clean way of doing this?

My current solution is saving the initial min and max in _range then setting the scale to be that value.

Another solution is emitting a double click event on u-over which seems a bit hacky.

leeoniya commented 2 months ago

you can autorange/reset any scale by setting its min and max to null. the x scale is special, and setting it to any min/max will also reset/re-range all the y scales (assuming that they still have their original range fns). if you want to simulate what double-click does, you can do u.setScale('x', {min: null, max: null}) or u.setScale('x', {min: u.data[0][0], max: u.data[0].at(-1)}).

trufflesprouts commented 2 months ago

i tried setting it to null but it doesn't work as expected https://jsfiddle.net/7pzqbdy1/61/ the second solution works

leeoniya commented 2 months ago

let's leave this open. since i think null/null should work.