@thewhitehaven04/chartjs-plugin-zoom 2.2.15 → 2.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core.d.ts +24 -0
- package/dist/src/defaults.d.ts +3 -0
- package/dist/src/hammer.d.ts +6 -0
- package/dist/src/handlers.d.ts +24 -0
- package/dist/src/index.umd.d.ts +3 -0
- package/dist/src/options.d.ts +196 -0
- package/dist/src/plugin.d.ts +25 -0
- package/dist/src/scale.types.d.ts +12 -0
- package/dist/src/scale.types.test.d.ts +2 -0
- package/dist/src/state.d.ts +53 -0
- package/dist/src/utils.d.ts +14 -0
- package/dist/src/utils.test.d.ts +2 -0
- package/package.json +2 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ScaleRange, type State } from './state.js';
|
|
2
|
+
import type { Chart, Point, Scale, UpdateMode } from 'chart.js';
|
|
3
|
+
import type { PanTrigger, ZoomTrigger } from './options.js';
|
|
4
|
+
import type { ZoomAmount } from './types.js';
|
|
5
|
+
export declare function zoom(chart: Chart, amount: ZoomAmount, transition?: UpdateMode, trigger?: ZoomTrigger): void;
|
|
6
|
+
export declare function zoomRect(chart: Chart, p0: Point, p1: Point, transition?: UpdateMode, trigger?: ZoomTrigger): void;
|
|
7
|
+
export declare function zoomScale(chart: Chart, scaleId: string, range: ScaleRange, transition?: UpdateMode, trigger?: ZoomTrigger): void;
|
|
8
|
+
export declare function resetZoom(chart: Chart, transition?: UpdateMode): void;
|
|
9
|
+
export declare function getZoomLevel(chart: Chart): number;
|
|
10
|
+
type PanAmount = number | Partial<Point>;
|
|
11
|
+
export declare function pan(chart: Chart, delta: PanAmount, enabledScales?: Scale[], transition?: UpdateMode, trigger?: PanTrigger): void;
|
|
12
|
+
export declare function getInitialScaleBounds(chart: Chart): Record<string, {
|
|
13
|
+
min?: number | undefined;
|
|
14
|
+
max?: number | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function getZoomedScaleBounds(chart: Chart): Record<string, {
|
|
17
|
+
min?: number | undefined;
|
|
18
|
+
max?: number | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function isZoomedOrPanned(chart: Chart): boolean;
|
|
21
|
+
export declare function isZoomingOrPanningState(state: State): boolean;
|
|
22
|
+
export declare function isZoomingOrPanning(chart: Chart): boolean;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Chart } from 'chart.js';
|
|
2
|
+
import type { ZoomPluginOptions } from './options';
|
|
3
|
+
export declare function startHammer(chart: Chart, options: ZoomPluginOptions): void;
|
|
4
|
+
export declare function stopHammer(chart: Chart): void;
|
|
5
|
+
export declare function hammerOptionsChanged(oldOptions: ZoomPluginOptions, newOptions: ZoomPluginOptions): boolean;
|
|
6
|
+
//# sourceMappingURL=hammer.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Chart } from 'chart.js';
|
|
2
|
+
import type { ModeOption, ZoomPluginOptions } from './options';
|
|
3
|
+
export declare function mouseMove(chart: Chart, event: MouseEvent): void;
|
|
4
|
+
export declare function mouseDown(chart: Chart, event: MouseEvent): void;
|
|
5
|
+
export declare function computeDragRect(chart: Chart, mode: ModeOption | undefined, pointEvents: {
|
|
6
|
+
dragStart: MouseEvent;
|
|
7
|
+
dragEnd: MouseEvent;
|
|
8
|
+
}, maintainAspectRatio: boolean | undefined): {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
zoomX: number;
|
|
12
|
+
zoomY: number;
|
|
13
|
+
top: number;
|
|
14
|
+
left: number;
|
|
15
|
+
right: number;
|
|
16
|
+
bottom: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function mouseUp(chart: Chart, event: MouseEvent): void;
|
|
19
|
+
export declare function wheel(chart: Chart, event: WheelEvent & {
|
|
20
|
+
target?: HTMLCanvasElement;
|
|
21
|
+
}): void;
|
|
22
|
+
export declare function addListeners(chart: Chart, options: ZoomPluginOptions): void;
|
|
23
|
+
export declare function removeListeners(chart: Chart): void;
|
|
24
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/// <reference types="hammerjs" />
|
|
2
|
+
import type { Chart, Color, Point } from 'chart.js';
|
|
3
|
+
export type Mode = 'x' | 'y' | 'xy';
|
|
4
|
+
export type ModeFn = (context: {
|
|
5
|
+
chart: Chart;
|
|
6
|
+
}) => Mode;
|
|
7
|
+
export type ModeOption = Mode | ModeFn;
|
|
8
|
+
export type ModifierKey = 'ctrl' | 'alt' | 'shift' | 'meta';
|
|
9
|
+
export type DrawTime = 'afterDraw' | 'afterDatasetsDraw' | 'beforeDraw' | 'beforeDatasetsDraw';
|
|
10
|
+
export type ZoomTrigger = 'api' | 'drag' | 'wheel' | 'pinch';
|
|
11
|
+
export type PanTrigger = 'api' | 'drag' | 'wheel' | 'other';
|
|
12
|
+
type RejectableStartEvent<T = Event | HammerInput> = (context: {
|
|
13
|
+
chart: Chart;
|
|
14
|
+
event: T;
|
|
15
|
+
point: Point;
|
|
16
|
+
}) => boolean | undefined;
|
|
17
|
+
type RejectEvent<T = Event | HammerInput> = (context: {
|
|
18
|
+
chart: Chart;
|
|
19
|
+
event: T;
|
|
20
|
+
}) => void;
|
|
21
|
+
type GenericEvent = (context: {
|
|
22
|
+
chart: Chart;
|
|
23
|
+
}) => void;
|
|
24
|
+
export interface WheelOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Enable the zoom via mouse wheel
|
|
27
|
+
*/
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Speed of zoom via mouse wheel
|
|
31
|
+
* (percentage of zoom on a wheel event)
|
|
32
|
+
*/
|
|
33
|
+
speed?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Modifier key required for zooming with mouse
|
|
36
|
+
*/
|
|
37
|
+
modifierKey?: ModifierKey | null;
|
|
38
|
+
}
|
|
39
|
+
export interface DragOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Enable the zoom via drag
|
|
42
|
+
*/
|
|
43
|
+
enabled?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Minimal zoom distance required before actually applying zoom
|
|
46
|
+
*/
|
|
47
|
+
threshold?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Border color of the drag area
|
|
50
|
+
*/
|
|
51
|
+
borderColor?: Color;
|
|
52
|
+
/**
|
|
53
|
+
* Border width of the drag area
|
|
54
|
+
*/
|
|
55
|
+
borderWidth?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Background color of the drag area
|
|
58
|
+
*/
|
|
59
|
+
backgroundColor?: Color;
|
|
60
|
+
/**
|
|
61
|
+
* Modifier key required for drag-to-zoom
|
|
62
|
+
*/
|
|
63
|
+
modifierKey?: ModifierKey | null;
|
|
64
|
+
/**
|
|
65
|
+
* Draw time required for drag-to-zoom
|
|
66
|
+
*/
|
|
67
|
+
drawTime?: DrawTime;
|
|
68
|
+
/**
|
|
69
|
+
* Maintain aspect ratio of the drag rectangle
|
|
70
|
+
*/
|
|
71
|
+
maintainAspectRatio?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export interface PinchOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Enable the zoom via pinch
|
|
76
|
+
*/
|
|
77
|
+
enabled?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Container for zoom options
|
|
81
|
+
*/
|
|
82
|
+
export interface ZoomOptions {
|
|
83
|
+
/**
|
|
84
|
+
* Zooming directions. Remove the appropriate direction to disable
|
|
85
|
+
* E.g. 'y' would only allow zooming in the y direction
|
|
86
|
+
* A function that is called as the user is zooming and returns the
|
|
87
|
+
* available directions can also be used:
|
|
88
|
+
* mode: function({ chart }) {
|
|
89
|
+
* return 'xy';
|
|
90
|
+
* },
|
|
91
|
+
*/
|
|
92
|
+
mode?: ModeOption;
|
|
93
|
+
/**
|
|
94
|
+
* Options of the mouse wheel mode
|
|
95
|
+
*/
|
|
96
|
+
wheel?: WheelOptions;
|
|
97
|
+
/**
|
|
98
|
+
* Options of the drag-to-zoom mode
|
|
99
|
+
*/
|
|
100
|
+
drag?: DragOptions;
|
|
101
|
+
/**
|
|
102
|
+
* Options of the pinch mode
|
|
103
|
+
*/
|
|
104
|
+
pinch?: PinchOptions;
|
|
105
|
+
scaleMode?: ModeOption;
|
|
106
|
+
/** @deprecated Use scaleMode instead */
|
|
107
|
+
overScaleMode?: ModeOption;
|
|
108
|
+
/**
|
|
109
|
+
* Function called while the user is zooming
|
|
110
|
+
*/
|
|
111
|
+
onZoom?: (context: {
|
|
112
|
+
chart: Chart;
|
|
113
|
+
trigger: ZoomTrigger;
|
|
114
|
+
amount?: {
|
|
115
|
+
x: number;
|
|
116
|
+
y: number;
|
|
117
|
+
} & {
|
|
118
|
+
focalPoint: Point;
|
|
119
|
+
};
|
|
120
|
+
}) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Function called once zooming is completed
|
|
123
|
+
*/
|
|
124
|
+
onZoomComplete?: GenericEvent;
|
|
125
|
+
/**
|
|
126
|
+
* Function called when wheel input occurs without modifier key
|
|
127
|
+
*/
|
|
128
|
+
onZoomRejected?: RejectEvent<Event>;
|
|
129
|
+
onZoomStart?: RejectableStartEvent<Event>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Container for pan options
|
|
133
|
+
*/
|
|
134
|
+
export interface PanOptions {
|
|
135
|
+
/**
|
|
136
|
+
* Boolean to enable panning
|
|
137
|
+
*/
|
|
138
|
+
enabled?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Panning directions. Remove the appropriate direction to disable
|
|
141
|
+
* E.g. 'y' would only allow panning in the y direction
|
|
142
|
+
* A function that is called as the user is panning and returns the
|
|
143
|
+
* available directions can also be used:
|
|
144
|
+
* mode: function({ chart }) {
|
|
145
|
+
* return 'xy';
|
|
146
|
+
* },
|
|
147
|
+
*/
|
|
148
|
+
mode?: ModeOption;
|
|
149
|
+
/**
|
|
150
|
+
* Modifier key required for panning with mouse
|
|
151
|
+
*/
|
|
152
|
+
modifierKey?: ModifierKey | null;
|
|
153
|
+
scaleMode?: ModeOption;
|
|
154
|
+
/** @deprecated Use scaleMode instead */
|
|
155
|
+
overScaleMode?: ModeOption;
|
|
156
|
+
/**
|
|
157
|
+
* Minimal pan distance required before actually applying pan
|
|
158
|
+
*/
|
|
159
|
+
threshold?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Function called while the user is panning
|
|
162
|
+
*/
|
|
163
|
+
onPan?: (context: {
|
|
164
|
+
chart: Chart;
|
|
165
|
+
trigger: PanTrigger;
|
|
166
|
+
delta: {
|
|
167
|
+
x: number;
|
|
168
|
+
y: number;
|
|
169
|
+
};
|
|
170
|
+
}) => void;
|
|
171
|
+
/**
|
|
172
|
+
* Function called once panning is completed
|
|
173
|
+
*/
|
|
174
|
+
onPanComplete?: GenericEvent;
|
|
175
|
+
/**
|
|
176
|
+
* Function called when pan fails because modifier key was not detected.
|
|
177
|
+
* event is the Hammer event that failed - see https://hammerjs.github.io/api#event-object
|
|
178
|
+
*/
|
|
179
|
+
onPanRejected?: RejectEvent<HammerInput>;
|
|
180
|
+
onPanStart?: RejectableStartEvent<HammerInput>;
|
|
181
|
+
}
|
|
182
|
+
export interface ScaleLimits {
|
|
183
|
+
min?: number | 'original';
|
|
184
|
+
max?: number | 'original';
|
|
185
|
+
minRange?: number;
|
|
186
|
+
}
|
|
187
|
+
export interface LimitOptions {
|
|
188
|
+
[axisId: string]: ScaleLimits;
|
|
189
|
+
}
|
|
190
|
+
export interface ZoomPluginOptions {
|
|
191
|
+
pan?: PanOptions;
|
|
192
|
+
limits?: LimitOptions;
|
|
193
|
+
zoom?: ZoomOptions;
|
|
194
|
+
}
|
|
195
|
+
export {};
|
|
196
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Chart, ChartEvent } from 'chart.js';
|
|
2
|
+
import type { ZoomPluginOptions } from './options';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
defaults: ZoomPluginOptions;
|
|
7
|
+
start(chart: Chart, _args: unknown, options: ZoomPluginOptions): void;
|
|
8
|
+
beforeEvent(chart: Chart, { event }: {
|
|
9
|
+
event: ChartEvent;
|
|
10
|
+
replay: boolean;
|
|
11
|
+
cancelable: true;
|
|
12
|
+
inChartArea: boolean;
|
|
13
|
+
}): boolean | void;
|
|
14
|
+
beforeUpdate(chart: Chart, _args: unknown, options: ZoomPluginOptions): void;
|
|
15
|
+
beforeDatasetsDraw(chart: Chart, _args: unknown, options: ZoomPluginOptions): void;
|
|
16
|
+
afterDatasetsDraw(chart: Chart, _args: unknown, options: ZoomPluginOptions): void;
|
|
17
|
+
beforeDraw(chart: Chart, _args: unknown, options: ZoomPluginOptions): void;
|
|
18
|
+
afterDraw(chart: Chart, _args: unknown, options: ZoomPluginOptions): void;
|
|
19
|
+
stop(chart: Chart): void;
|
|
20
|
+
panFunctions: Record<string, import("./scale.types").PanFunction>;
|
|
21
|
+
zoomFunctions: Record<string, import("./scale.types").ZoomFunction>;
|
|
22
|
+
zoomRectFunctions: Record<string, import("./scale.types").ZoomRectFunction>;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
|
25
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ScaleRange } from './state';
|
|
2
|
+
import type { Point, Scale } from 'chart.js';
|
|
3
|
+
import type { LimitOptions } from './options';
|
|
4
|
+
export type ZoomFunction = (scale: Scale, zoom: number, center: Point, limits: LimitOptions) => boolean;
|
|
5
|
+
export type ZoomRectFunction = (scale: Scale, from: number, to: number, limits: LimitOptions) => boolean;
|
|
6
|
+
export type PanFunction = (scale: Scale, delta: number, limits: LimitOptions) => boolean;
|
|
7
|
+
export declare function zoomDelta(val: number | undefined, min: number | undefined, range: number, newRange: number): ScaleRange;
|
|
8
|
+
export declare function updateRange(scale: Scale, { min, max }: ScaleRange, limits?: LimitOptions, zoom?: boolean, pan?: boolean): boolean;
|
|
9
|
+
export declare const zoomFunctions: Record<string, ZoomFunction>;
|
|
10
|
+
export declare const zoomRectFunctions: Record<string, ZoomRectFunction>;
|
|
11
|
+
export declare const panFunctions: Record<string, PanFunction>;
|
|
12
|
+
//# sourceMappingURL=scale.types.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Chart, type Point } from 'chart.js';
|
|
2
|
+
import type { ZoomPluginOptions } from './options';
|
|
3
|
+
export type ScaleRange = {
|
|
4
|
+
min: number;
|
|
5
|
+
max: number;
|
|
6
|
+
};
|
|
7
|
+
export type OriginalLimits = {
|
|
8
|
+
min: {
|
|
9
|
+
scale?: number;
|
|
10
|
+
options?: unknown;
|
|
11
|
+
};
|
|
12
|
+
max: {
|
|
13
|
+
scale?: number;
|
|
14
|
+
options?: unknown;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type OriginalScaleLimits = Record<string, OriginalLimits>;
|
|
18
|
+
export type UpdatedScaleLimits = Record<string, ScaleRange>;
|
|
19
|
+
export type HandlerFunctions = {
|
|
20
|
+
click: (chart: Chart, event: MouseEvent, options: ZoomPluginOptions) => void;
|
|
21
|
+
keydown: (chart: Chart, event: KeyboardEvent) => void;
|
|
22
|
+
mousedown: (chart: Chart, event: MouseEvent, options: ZoomPluginOptions) => void;
|
|
23
|
+
mousemove: (chart: Chart, event: MouseEvent, options: ZoomPluginOptions) => void;
|
|
24
|
+
mouseup: (chart: Chart, event: MouseEvent, options: ZoomPluginOptions) => void;
|
|
25
|
+
onZoomComplete: ({ chart }: {
|
|
26
|
+
chart: Chart;
|
|
27
|
+
}) => void;
|
|
28
|
+
wheel: (chart: Chart, event: WheelEvent) => void;
|
|
29
|
+
};
|
|
30
|
+
export type HandlerName = keyof HandlerFunctions;
|
|
31
|
+
export type HandlerFunction = HandlerFunctions[HandlerName];
|
|
32
|
+
export type Handler = EventListener;
|
|
33
|
+
export type Handlers = Partial<Record<HandlerName, Handler>>;
|
|
34
|
+
export type HandlerTarget = Partial<Record<HandlerName, HTMLCanvasElement | Document>>;
|
|
35
|
+
export interface State {
|
|
36
|
+
originalScaleLimits: OriginalScaleLimits;
|
|
37
|
+
updatedScaleLimits: UpdatedScaleLimits;
|
|
38
|
+
handlers: Handlers;
|
|
39
|
+
targets: HandlerTarget;
|
|
40
|
+
panDelta: Record<string, number>;
|
|
41
|
+
dragging: boolean;
|
|
42
|
+
panning: boolean;
|
|
43
|
+
options: ZoomPluginOptions;
|
|
44
|
+
dragStart?: MouseEvent;
|
|
45
|
+
dragEnd?: MouseEvent;
|
|
46
|
+
filterNextClick?: boolean;
|
|
47
|
+
scale?: number | null;
|
|
48
|
+
delta?: Point | null;
|
|
49
|
+
panScales?: string[];
|
|
50
|
+
}
|
|
51
|
+
export declare function getState(chart: Chart): State;
|
|
52
|
+
export declare function removeState(chart: Chart): void;
|
|
53
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Chart, Point, Scale } from 'chart.js';
|
|
2
|
+
import type { DragOptions, ModeOption, ModifierKey, PanOptions } from './options';
|
|
3
|
+
export declare const getModifierKey: (opts?: DragOptions | PanOptions) => ModifierKey | undefined;
|
|
4
|
+
export declare const keyPressed: (key: ModifierKey | undefined, event: TouchEvent | MouseEvent | PointerEvent) => boolean | undefined;
|
|
5
|
+
export declare const keyNotPressed: (key: ModifierKey | undefined, event: TouchEvent | MouseEvent | PointerEvent) => boolean | undefined;
|
|
6
|
+
export declare function directionEnabled(mode: ModeOption | undefined, dir: 'x' | 'y', chart: Chart): boolean;
|
|
7
|
+
export declare function debounce(fn: () => void, delay: number | undefined): () => number | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Evaluate the chart's mode, scaleMode, and overScaleMode properties to
|
|
10
|
+
* determine which axes are eligible for scaling.
|
|
11
|
+
* options.overScaleMode can be a function if user want zoom only one scale of many for example.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEnabledScalesByPoint(options: PanOptions | undefined, point: Point, chart: Chart): Scale[];
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thewhitehaven04/chartjs-plugin-zoom",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.16",
|
|
4
4
|
"description": "A fork of the ChartJS Zoom plugin that enables zoom and pan functionality in Chart.js charts",
|
|
5
5
|
"homepage": "https://www.chartjs.org/chartjs-plugin-zoom/",
|
|
6
6
|
"repository": {
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist/**/*.js",
|
|
26
|
-
"dist/src
|
|
27
|
-
"dist/src/types.d.ts",
|
|
26
|
+
"dist/src/*.d.ts",
|
|
28
27
|
"dist/**/*.map"
|
|
29
28
|
],
|
|
30
29
|
"scripts": {
|