huww98/TimeChart

Event on zoom applied

NSV-dev opened this issue · 2 comments

I need to make realtime smooth chart, but points add only ~once a second(depends on server-side), so i can't use built in realtime.

I made interval to solve this problem

setInterval(() => {
    var time = Date.now() - this.startTime;
    this.charts.forEach(c => {
        c.chart.options.xRange = { min: time - 60000, max: time };
        c.chart.update();
    });
}, 1000 / fps);

To use zoom I need to kill this interval and set it when user clicks button.
To do it I need to listen for event called on zoom changed/aplied

Is there any way to listen for such event or another way of solving my problem?

P.S. While exploring the code base I found onScaleUpdated in ChartZoom but I don't know how to reach it

I think you cannot reach onScaleUpdated currently. But as you can see:

z.onScaleUpdated(() => {
chart.options.xRange = null;
chart.options.yRange = null;
chart.options.realTime = false;
chart.update();
});

xRange would be reset to null on this event. Maybe you can check if it is null before updating the xRange.

I will consider exposing this event in the next version.

Thanks for quick answer. And thanks for this briliant library)