in packages/synchro-charts/src/components/charts/sc-webgl-base-chart/sc-webgl-base-chart.tsx [246:304]
onViewPortChange(newViewPort: ViewPortConfig, oldViewPort: ViewPortConfig) {
if (this.scene && !isEqual(newViewPort, oldViewPort)) {
const hasYRangeChanged = newViewPort.yMin !== oldViewPort.yMin || newViewPort.yMax !== oldViewPort.yMax;
if (hasYRangeChanged) {
/** Update active viewport. */
this.yMin = newViewPort.yMin;
this.yMax = newViewPort.yMax;
/** Apply Changes */
this.applyYRangeChanges();
}
// All charts are correctly synced.
const manuallyAppliedViewPortChange = newViewPort.lastUpdatedBy == null;
if (manuallyAppliedViewPortChange) {
/** Update active viewport */
this.start = isMinimalStaticViewport(newViewPort)
? new Date(newViewPort.start)
: new Date(Date.now() - parseDuration(newViewPort.duration));
this.end = isMinimalStaticViewport(newViewPort) ? new Date(newViewPort.end) : new Date();
/**
* Updates viewport to the active viewport
*/
this.scene.updateViewPort(this.activeViewPort());
/** Re-render scene */
// This is a necessary call to ensure that the view port group is correctly set.
// If `updateViewPorts` is **not** called, `updateAndRegisterChartScene` in an edge case may
// re-create the chart resources, and set the new viewport equal to the view port groups stale viewport.
webGLRenderer.updateViewPorts({
start: this.start,
end: this.end,
manager: this.scene,
duration: this.activeViewPort().duration,
preventPropagation: true,
});
this.updateAndRegisterChartScene({
hasDataChanged: false,
hasSizeChanged: false,
hasAnnotationChanged: false,
shouldRerender: false,
});
}
if (
this.shouldRerenderOnViewportChange &&
this.shouldRerenderOnViewportChange({ oldViewport: oldViewPort, newViewport: newViewPort })
) {
this.onUpdate({ start: this.start, end: this.end }, false, false, false, true);
}
}
const { duration } = this.activeViewPort();
if (this.scene != null && duration != null) {
webGLRenderer.stopTick({ manager: this.scene });
webGLRenderer.startTick({ manager: this.scene, duration, chartSize: this.chartSizeConfig() });
}
}