-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding typings for Zoom analog to chartjs-plugin-annotation (#438)
Co-authored-by: Zeugner, Thomas <Thomas.Zeugner@kuka.com>
- Loading branch information
1 parent
adef834
commit f537880
Showing
6 changed files
with
209 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Plugin, ChartType } from 'chart.js'; | ||
import { ZoomPluginOptions } from './options'; | ||
|
||
declare module 'chart.js' { | ||
interface PluginOptionsByType<TType extends ChartType> { | ||
zoom: ZoomPluginOptions; | ||
} | ||
} | ||
|
||
export declare const Zoom: Plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { Chart } from 'chart.js'; | ||
|
||
|
||
type Mode = 'x' | 'y' | 'xy' | 'xy'; | ||
|
||
interface DragEffectOptions { | ||
borderColor?: string; | ||
borderWidth?: number; | ||
backgroundColor?: string; | ||
animationDuration?: number; | ||
} | ||
|
||
interface XyValue { | ||
x?: number; | ||
y?: number; | ||
} | ||
|
||
interface ZoomOptions { | ||
/** | ||
* Boolean to enable zooming | ||
**/ | ||
enabled: boolean; | ||
|
||
/** | ||
* Enable drag-to-zoom behavior | ||
**/ | ||
drag: boolean | DragEffectOptions; | ||
|
||
|
||
// Zooming directions. Remove the appropriate direction to disable | ||
// Eg. 'y' would only allow zooming in the y direction | ||
// A function that is called as the user is zooming and returns the | ||
// available directions can also be used: | ||
// mode: function({ chart }) { | ||
// return 'xy'; | ||
// }, | ||
mode: Mode | { (char: Chart): Mode }; | ||
|
||
/** | ||
* Format of min zoom range depends on scale type | ||
*/ | ||
rangeMin?: XyValue; | ||
|
||
/** | ||
* Format of max zoom range depends on scale type | ||
*/ | ||
rangeMax?: XyValue; | ||
|
||
/** Speed of zoom via mouse wheel | ||
* (percentage of zoom on a wheel event) | ||
*/ | ||
speed?: number; | ||
|
||
/** | ||
* Minimal zoom distance required before actually applying zoom | ||
*/ | ||
threshold?: number; | ||
|
||
/** | ||
* On category scale, minimal zoom level before actually applying zoom | ||
*/ | ||
sensitivity?: number; | ||
|
||
/** | ||
* Function called while the user is zooming | ||
*/ | ||
onZoom?: (chart: Chart) => void; | ||
|
||
/** | ||
* Function called once zooming is completed | ||
*/ | ||
onZoomComplete?: (chart: Chart) => void; | ||
|
||
/** | ||
* Function called when wheel input occurs without modifier key | ||
*/ | ||
onZoomRejected?: (chart: Chart, event: Event) => void; | ||
|
||
} | ||
|
||
// Container for pan options | ||
interface PanOptions { | ||
/** | ||
* Boolean to enable panning | ||
*/ | ||
enabled: boolean; | ||
|
||
|
||
/** | ||
* Panning directions. Remove the appropriate direction to disable | ||
* Eg. 'y' would only allow panning in the y direction | ||
* A function that is called as the user is panning and returns the | ||
* available directions can also be used: | ||
* mode: function({ chart }) { | ||
* return 'xy'; | ||
* }, | ||
*/ | ||
mode: Mode | { (char: Chart): Mode }; | ||
|
||
/** | ||
* Format of min pan range depends on scale type | ||
*/ | ||
rangeMin?: XyValue; | ||
|
||
/** | ||
* Format of max pan range depends on scale type | ||
*/ | ||
rangeMax?: XyValue; | ||
|
||
|
||
/** | ||
* On category scale, factor of pan velocity | ||
*/ | ||
speed?: number; | ||
|
||
/** | ||
* Minimal pan distance required before actually applying pan | ||
*/ | ||
threshold?: number; | ||
|
||
/** | ||
* Function called while the user is panning | ||
*/ | ||
onPan?: (chart: Chart) => void; | ||
|
||
/** | ||
* Function called once panning is completed | ||
*/ | ||
onPanComplete?: (chart: Chart) => void; | ||
|
||
/** | ||
* Function called when pan fails because modifier key was not detected. | ||
* event is the a hammer event that failed - see https://hammerjs.github.io/api#event-object | ||
*/ | ||
onPanRejected: (chart: Chart, event: Event) => void; | ||
} | ||
|
||
|
||
export interface ZoomPluginOptions { | ||
pan?: PanOptions; | ||
zoom?: ZoomOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Chart } from 'chart.js'; | ||
import { Zoom } from '../index'; | ||
|
||
Chart.register(Zoom); | ||
Chart.unregister(Zoom); | ||
|
||
const chart = new Chart('id', { | ||
type: 'bar', | ||
data: { | ||
labels: [], | ||
datasets: [{ | ||
data: [] | ||
}] | ||
}, | ||
options: { | ||
plugins: { | ||
zoom: { | ||
pan: { | ||
enabled: true, | ||
mode: 'x' | ||
}, | ||
zoom: { | ||
enabled: true, | ||
sensitivity: 0.5, | ||
mode: 'x', | ||
|
||
} | ||
}, | ||
} | ||
}, | ||
plugins: [Zoom] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES6", | ||
"moduleResolution": "Node", | ||
"alwaysStrict": true, | ||
"noEmit": true | ||
}, | ||
"include": [ | ||
"*.ts", | ||
"../*.d.ts" | ||
] | ||
} |