uPlot icon indicating copy to clipboard operation
uPlot copied to clipboard

After continuous magnification, the coordinate axis becomes the same

Open aim-leo opened this issue 2 years ago • 2 comments

Is there any way to limit the magnification, such as limiting the magnification multiple, or when the selected range is less than a certain value, it is not allowed to enlarge. Screenshot from 2022-05-10 16-07-32

I try to set scale and set range for each coordinate axis. As in the example, unfortunately, only the x-axis setting takes effect, but the y-axis does not take effect, and the function does not seem to be called. My option:

{
  cursor: {
    drag: { x: true, y: true, uni: 10, dist: 5 },
  },
  scales: {
    x: {
      time: false,
      min: xRange[0],
      max: xRange[1],
      range: (self, newMin, newMax) => {
        let curMin = self.scales.x.min;
        let curMax = self.scales.x.max;

        // prevent zoom
        if (newMax - newMin < 10) return [curMin, curMax];

        // allow zoom
        return [newMin, newMax];
      },
    },
    y: {
      time: false,
      min: yRange[0],
      max: yRange[1],
      range: (self, newMin, newMax) => {
        let curMin = self.scales.y.min;
        let curMax = self.scales.y.max;

        // prevent zoom
        if (newMax - newMin < 5) return [curMin, curMax];

        // allow zoom
        return [newMin, newMax];
      },
    },
  },
}

My version of uplot is 1.6.13. Thank you very much for your work. This library is very cool.

aim-leo avatar May 10 '22 08:05 aim-leo

this seems to work as expected for me:

https://jsfiddle.net/r1vcL90n/

leeoniya avatar May 16 '22 13:05 leeoniya

Thanks for your reply, I modified your code slightly to allow selection zoom in both x and y directions: link, unfortunately, when I keep doing selection zoom on the canvas, x The axis will be fixed and the y-axis will keep changing until all numbers are the same. I just modified this part:

cursor: {
  drag: { x: true, y: true, uni: 4, dist: 2 },
}

aim-leo avatar May 17 '22 12:05 aim-leo