From 8aca72ce0409aafc4827b8462d0e6d11bb878af5 Mon Sep 17 00:00:00 2001 From: glitch4347 Date: Tue, 12 Mar 2024 10:48:22 +0100 Subject: [PATCH] zoom out with ranges logic --- examples/zoom_out.html | 37 +++++++++++++++++++++++++++++++++++++ src/index.ts | 12 +++++++++++- src/types.ts | 10 +++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 examples/zoom_out.html diff --git a/examples/zoom_out.html b/examples/zoom_out.html new file mode 100644 index 0000000..8c601fe --- /dev/null +++ b/examples/zoom_out.html @@ -0,0 +1,37 @@ + + + + + + + + +
+ + + diff --git a/src/index.ts b/src/index.ts index 925b516..168b37a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -443,7 +443,17 @@ class LinePod extends ChartwerkPod { x: xAxisMiddleValue, y: yAxisMiddleValue } - this.options.callbackZoomOut(centers); + + // TODO: refactor core not to take _options explicitly + if( + this.options._options.eventsCallbacks !== undefined && + this.options._options.eventsCallbacks.zoomOut !== undefined + ) { + this.options._options.eventsCallbacks.zoomOut( + centers, + [this.state.xValueRange, this.state.yValueRange] + ); + } } } diff --git a/src/types.ts b/src/types.ts index 379763f..d094767 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import { Serie, Options } from '@chartwerk/core'; +import { AxisRange } from '@chartwerk/core/dist/types'; type LineTimeSerieParams = { maxLength: number, @@ -10,7 +11,14 @@ type LineTimeSerieParams = { } export type LineTimeSerie = Serie & Partial; -export type LineOptions = Options; +export type LineOptions = Options & { + eventsCallbacks? : { + zoomOut?: (centers: { + x: number; + y: number; + }, range: AxisRange[]) => void; + } +} export type MouseObj = { x: number,