Skip to content

Commit

Permalink
refactor: remove zoom.disableDefaultBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Aug 3, 2018
1 parent 7196c26 commit e7eae91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
6 changes: 2 additions & 4 deletions htdocs/samples/zoom_type.html
Expand Up @@ -22,8 +22,7 @@
},
zoom: {
enabled: true,
type: 'scroll',
disableDefaultBehavior: false
type: 'scroll'
}
});

Expand All @@ -36,8 +35,7 @@
},
zoom: {
enabled: true,
type: 'drag',
disableDefaultBehavior: false
type: 'drag'
}
});

Expand Down
1 change: 0 additions & 1 deletion src/config.js
Expand Up @@ -15,7 +15,6 @@ ChartInternal.prototype.getDefaultConfig = function () {
zoom_enabled: false,
zoom_initialRange: undefined,
zoom_type: 'scroll',
zoom_disableDefaultBehavior: false,
zoom_privileged: false,
zoom_rescale: false,
zoom_onzoom: function () {},
Expand Down
16 changes: 6 additions & 10 deletions src/zoom.js
Expand Up @@ -62,17 +62,17 @@ ChartInternal.prototype.zoomTransform = function (range) {
};

ChartInternal.prototype.initDragZoom = function () {
if (!(this.config.zoom_type === 'drag' && this.config.zoom_enabled)) {
return;
}

const $$ = this;
const d3 = $$.d3;
const config = $$.config;
const context = $$.context = $$.svg;
const brushXPos = $$.margin.left + 20.5;
const brushYPos = $$.margin.top + 0.5;

if (!(config.zoom_type === 'drag' && config.zoom_enabled)) {
return;
}

const brush = $$.dragZoomBrush = d3.brushX()
.on("start", () => {
$$.api.unzoom();
Expand All @@ -88,16 +88,12 @@ ChartInternal.prototype.initDragZoom = function () {
})
.on("end", () => {
if (d3.event.selection == null) {
return
return;
}

const [x0, x1] = d3.event.selection;

if (!config.zoom_disableDefaultBehavior) {
$$.api.zoom([$$.x.invert(x0), $$.x.invert(x1)]);
} else {
$$.api.zoom([$$.x.invert(x0), $$.x.invert(x1)]);
}
$$.api.zoom([$$.x.invert(x0), $$.x.invert(x1)]);

$$.svg
.select("." + CLASS.dragZoom)
Expand Down

0 comments on commit e7eae91

Please sign in to comment.