Browse Source

feat: restore zoom.disableDefaultBahavior option

pull/2447/head
Yoshiya Hinosawa 6 years ago
parent
commit
0e81f5899d
  1. 1
      src/config.js
  2. 14
      src/zoom.js

1
src/config.js

@ -15,6 +15,7 @@ ChartInternal.prototype.getDefaultConfig = function () {
zoom_enabled: false, zoom_enabled: false,
zoom_initialRange: undefined, zoom_initialRange: undefined,
zoom_type: 'scroll', zoom_type: 'scroll',
zoom_disableDefaultBehavior: false,
zoom_privileged: false, zoom_privileged: false,
zoom_rescale: false, zoom_rescale: false,
zoom_onzoom: function () {}, zoom_onzoom: function () {},

14
src/zoom.js

@ -22,7 +22,12 @@ ChartInternal.prototype.initZoom = function () {
var e = d3.event.sourceEvent; var e = d3.event.sourceEvent;
if (e && e.type === "brush") { return; } if (e && e.type === "brush") { return; }
$$.redrawForZoom.call($$);
if (!config.zoom_disableDefaultBehavior) {
$$.redrawForZoom.call($$);
}
config.zoom_onzoom.call($$.api, $$.x.orgDomain());
}) })
.on('end', function () { .on('end', function () {
if (config.zoom_type !== 'scroll') { if (config.zoom_type !== 'scroll') {
@ -73,7 +78,7 @@ ChartInternal.prototype.initDragZoom = function () {
return; return;
} }
const getZoomedDomain = selection => selection && selection.map(x => $$.x.invert(x)) const getZoomedDomain = selection => selection && selection.map(x => $$.x.invert(x));
const brush = $$.dragZoomBrush = d3.brushX() const brush = $$.dragZoomBrush = d3.brushX()
.on("start", () => { .on("start", () => {
@ -95,7 +100,9 @@ ChartInternal.prototype.initDragZoom = function () {
const zoomedDomain = getZoomedDomain(d3.event.selection); const zoomedDomain = getZoomedDomain(d3.event.selection);
$$.api.zoom(zoomedDomain); if (!config.zoom_disableDefaultBehavior) {
$$.api.zoom(zoomedDomain);
}
$$.svg $$.svg
.select("." + CLASS.dragZoom) .select("." + CLASS.dragZoom)
@ -142,5 +149,4 @@ ChartInternal.prototype.redrawForZoom = function () {
if (d3.event.sourceEvent && d3.event.sourceEvent.type === 'mousemove') { if (d3.event.sourceEvent && d3.event.sourceEvent.type === 'mousemove') {
$$.cancelClick = true; $$.cancelClick = true;
} }
config.zoom_onzoom.call($$.api, x.orgDomain());
}; };

Loading…
Cancel
Save