uPlot icon indicating copy to clipboard operation
uPlot copied to clipboard

Zooming fails when min and max set for y-axis

Open whtrbit opened this issue 4 years ago • 2 comments

Series are not drawn when zooming in the plot with the following configuration:

{
  scales: {
    y: {
      auto: false,
      min: -15,
      max: 15
    }
  }
}

After the zoom, y-axis is no longer visible and lines are not drawn. The bad guy here is the auto property set to false.

Reproduced in the example: https://jsfiddle.net/f1jayome/5/

whtrbit avatar Jan 20 '22 10:01 whtrbit

I have fixed this by setting range property instead of min and max.

{
  scales: {
    y: {
      auto: false,
      range: [-15, 15]
    }
  }
}

Before we close the issue I would like to ask what's the difference between min/max and range props for scales?

whtrbit avatar Jan 20 '22 10:01 whtrbit

let's leave this open, as it's very related to https://github.com/leeoniya/uPlot/issues/648. it's a bit of a wart, but one that is fixable with additional attention.

currently, scale min/max are kinda internal properties that are dynamic/mutable in nature. on every .setData() or .setScale() call they are initially reset to Infinity/-Infinity, and as the data is scanned in auto mode, they converge to the values found in the data. if auto: false, they still get reset (which is this bug and affects the other bug), but then are not re-ranged from data, and there is an expectation that a user-supplied scale.range will provide the proper min/max instead.

the fact that setting min/max works during the initial plot instantiation but not afterwards could still be useful to set some "initial" scale, if you have a pre-zoomed view that you still want to be zoomable afterwards, e.g. linked brush charts. but generally for completely static/unzoomable scales, you should use scale.range, which will always have the final word.

it might be reasonable to detect min/max in the initial settings and essentially convert it to a static range, but they're not 100% the same. ultimately it's possible to get the "initial zoomed but not static" behavior with the range api, but its a bit more code. i don't like this rather confusing situation, so will have to think about what makes sense to do.

leeoniya avatar Feb 08 '22 00:02 leeoniya