Skip to content

Commit b2f520d

Browse files
jledentubenmccann
authored andcommitted
Add speed option (#215)
Add speed option
1 parent d8a0e4b commit b2f520d

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To configure the zoom and pan plugin, you can simply add new config options to y
1818
// Boolean to enable panning
1919
enabled: true,
2020

21-
// Panning directions. Remove the appropriate direction to disable
21+
// Panning directions. Remove the appropriate direction to disable
2222
// Eg. 'y' would only allow panning in the y direction
2323
mode: 'xy',
2424
rangeMin: {
@@ -35,7 +35,7 @@ To configure the zoom and pan plugin, you can simply add new config options to y
3535
// Useful for dynamic data loading
3636
onPan: function({chart}) { console.log(`I was panned!!!`); }
3737
},
38-
38+
3939
// Container for zoom options
4040
zoom: {
4141
// Boolean to enable zooming
@@ -51,9 +51,10 @@ To configure the zoom and pan plugin, you can simply add new config options to y
5151
// backgroundColor: 'rgb(225,225,225)'
5252
// },
5353

54-
// Zooming directions. Remove the appropriate direction to disable
54+
// Zooming directions. Remove the appropriate direction to disable
5555
// Eg. 'y' would only allow zooming in the y direction
5656
mode: 'xy',
57+
5758
rangeMin: {
5859
// Format of min zoom range depends on scale type
5960
x: null,
@@ -64,6 +65,11 @@ To configure the zoom and pan plugin, you can simply add new config options to y
6465
x: null,
6566
y: null
6667
},
68+
69+
// Speed of zoom via mouse wheel
70+
// (percentage of zoom on a wheel event)
71+
speed: 0.1,
72+
6773
// Function called once zooming is completed
6874
// Useful for dynamic data loading
6975
onZoom: function({chart}) { console.log(`I was zoomed!!!`); }

samples/zoom-time.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
zoom: {
109109
enabled: true,
110110
drag: true,
111-
mode: 'x'
111+
mode: 'x',
112+
speed: 0.05
112113
}
113114
}
114115
};

src/plugin.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ var defaultOptions = zoomNS.defaults = {
2323
zoom: {
2424
enabled: true,
2525
mode: 'xy',
26-
sensitivity: 3
26+
sensitivity: 3,
27+
speed: 0.1
2728
}
2829
};
2930
// Stores the original options of the scales
@@ -454,11 +455,13 @@ var zoomPlugin = {
454455
y: offsetY
455456
};
456457

457-
if (event.deltaY < 0) {
458-
doZoom(chartInstance, 1.1, 1.1, center);
459-
} else {
460-
doZoom(chartInstance, 0.909, 0.909, center);
458+
var speedPercent = helpers.getValueOrDefault(chartInstance.options.zoom.speed, defaultOptions.zoom.speed);
459+
460+
if (event.deltaY >= 0) {
461+
speedPercent = -speedPercent;
461462
}
463+
doZoom(chartInstance, 1 + speedPercent, 1 + speedPercent, center);
464+
462465
// Prevent the event from triggering the default behavior (eg. Content scrolling).
463466
event.preventDefault();
464467
}

0 commit comments

Comments
 (0)