chartjs / chartjs-plugin-zoom

Zoom and pan plugin for Chart.js
MIT License
598 stars 327 forks source link

Inconsistent behavior when using limits and new data points #813

Open estanglerbm opened 7 months ago

estanglerbm commented 7 months ago

Let's say that you have a chart with limits min/max = 'original', so that panning/zooming never exceeds the range of data points.

Then new data points arrive. (Like another day of data points with time x-axis, and we drop the oldest day of data points.)

  1. In the initial chart display--or after a resetZoom()--when the new data points arrive, they get displayed.

  2. But if you're zoomed and/or panned, and new data points arrive, then you cannot visit the new data points (by zooming out or panning over); the original range of data points is set in stone due to storeOriginalScaleLimits().

A partial workaround for zooming out is to call resetZoom() once you've zoomed all the way out:

onZoomComplete: ({chart}) => {

    if( !this.is_resetting_zoom && chart.getZoomLevel() == 1 ) {

        this.is_resetting_zoom = true;
        chart.resetZoom();
        this.is_resetting_zoom = false;
    }
}

No workaround for when you're zoomed in or panning.

I know you could update limits min/max with the range of the new data (like in #649), as it arrives, but that information may not be available, and not as convenient.