leeoniya / uPlot

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

xy zoom with static y scale cannot be unzoomed/reset #915

Open leeoniya opened 3 months ago

leeoniya commented 3 months ago

(followup to #914)

the problem here is a tricky, either we have to disallow y-zoom-in when the y scale range is statically defined, which would be odd / feel broken ux. or we have to return true from sc.auto() when the scale is static but we're viaAutoScaleX = true, which is weird (it means all static scales will scan the data but then pass through the ranging function which will throw the found min/max away). another reason why current auto needs to be split into scan and auto callbacks.

https://github.com/leeoniya/uPlot/blob/4b9b92788627724c13667228fab411ac9f638f4a/src/uPlot.js#L1289-L1290

https://github.com/leeoniya/uPlot/assets/43234/0fd393cf-f36a-403b-afd6-76fbdc9d609f

https://jsfiddle.net/vmy4hfq8/

let data = [
    [[], []],
    [[0, 1, 2], [2, 3, 5]],
];

const opts = {
    mode: 2,
    width: 800,
    height: 400,
    scales: {
        x: {
            time: false,
        },
        y: {
            range: [1, 10],
        }
    },
    series: [
        {},
        {
            stroke: "red"
        },
    ],
//    cursor: {
//        y: false,
//        drag: { y: false },
//    }
};

let u = new uPlot(opts, data, document.body);
jint23 commented 3 months ago

We just bumped into this exact same issue. Should the range function be called regardless of auto or not when we're resetting the zoom with double click?

Clam- commented 1 month ago

I also just ran into this issue. I'm assuming I need to "remember" my statically set range (already doing this), and reapply it on the resetting zoom event?