Commit ae1584aa authored by Masayuki Tanaka's avatar Masayuki Tanaka

Add zoom.enable API - #304

parent 0230172e
...@@ -2742,10 +2742,9 @@ ...@@ -2742,10 +2742,9 @@
return __axis_rotated ? this.y(scale) : this.x(scale); return __axis_rotated ? this.y(scale) : this.x(scale);
}; };
if (__zoom_enabled) {
zoom = d3.behavior.zoom() zoom = d3.behavior.zoom()
.on("zoomstart", function () { zoom.altDomain = d3.event.sourceEvent.altKey ? x.orgDomain() : null; }) .on("zoomstart", function () { zoom.altDomain = d3.event.sourceEvent.altKey ? x.orgDomain() : null; })
.on("zoom", __zoom_enabled ? redrawForZoom : null); .on("zoom", redrawForZoom);
zoom.scale = function (scale) { zoom.scale = function (scale) {
return __axis_rotated ? this.y(scale) : this.x(scale); return __axis_rotated ? this.y(scale) : this.x(scale);
}; };
...@@ -2758,7 +2757,6 @@ ...@@ -2758,7 +2757,6 @@
this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); this.scaleExtent([extent[0] * ratio, extent[1] * ratio]);
return this; return this;
}; };
}
/*-- Draw Chart --*/ /*-- Draw Chart --*/
...@@ -2933,8 +2931,7 @@ ...@@ -2933,8 +2931,7 @@
// Cover whole with rects for events // Cover whole with rects for events
eventRect = main.select('.' + CLASS.chart).append("g") eventRect = main.select('.' + CLASS.chart).append("g")
.attr("class", CLASS.eventRects) .attr("class", CLASS.eventRects)
.style('fill-opacity', 0) .style('fill-opacity', 0);
.style('cursor', __zoom_enabled ? __axis_rotated ? 'ns-resize' : 'ew-resize' : null);
// Define g for bar chart area // Define g for bar chart area
main.select('.' + CLASS.chart).append("g") main.select('.' + CLASS.chart).append("g")
...@@ -2988,7 +2985,6 @@ ...@@ -2988,7 +2985,6 @@
main.select('.' + CLASS.chart).append("g") main.select('.' + CLASS.chart).append("g")
.attr("class", CLASS.chartTexts); .attr("class", CLASS.chartTexts);
if (__zoom_enabled) { // TODO: __zoom_privileged here?
// if zoom privileged, insert rect to forefront // if zoom privileged, insert rect to forefront
main.insert('rect', __zoom_privileged ? null : 'g.' + CLASS.grid) main.insert('rect', __zoom_privileged ? null : 'g.' + CLASS.grid)
.attr('class', CLASS.zoomRect) .attr('class', CLASS.zoomRect)
...@@ -2997,7 +2993,6 @@ ...@@ -2997,7 +2993,6 @@
.style('opacity', 0) .style('opacity', 0)
.style('cursor', __axis_rotated ? 'ns-resize' : 'ew-resize') .style('cursor', __axis_rotated ? 'ns-resize' : 'ew-resize')
.call(zoom).on("dblclick.zoom", null); .call(zoom).on("dblclick.zoom", null);
}
// Set default extent if defined // Set default extent if defined
if (__axis_x_default) { if (__axis_x_default) {
...@@ -3914,7 +3909,8 @@ ...@@ -3914,7 +3909,8 @@
if (__interaction_enabled) { if (__interaction_enabled) {
// rect for mouseover // rect for mouseover
eventRect = main.select('.' + CLASS.eventRects); eventRect = main.select('.' + CLASS.eventRects)
.style('cursor', __zoom_enabled ? __axis_rotated ? 'ns-resize' : 'ew-resize' : null);
if (notEmpty(__data_xs) && !isSingleX(__data_xs)) { if (notEmpty(__data_xs) && !isSingleX(__data_xs)) {
if (!eventRect.classed(CLASS.eventRectsMultiple)) { if (!eventRect.classed(CLASS.eventRectsMultiple)) {
...@@ -4150,6 +4146,9 @@ ...@@ -4150,6 +4146,9 @@
}); });
} }
function redrawForZoom() { function redrawForZoom() {
if (!__zoom_enabled) {
return;
}
if (filterTargetsToShow(c3.data.targets).length === 0) { if (filterTargetsToShow(c3.data.targets).length === 0) {
return; return;
} }
...@@ -4790,6 +4789,12 @@ ...@@ -4790,6 +4789,12 @@
brush.clear().update(); brush.clear().update();
redraw({withUpdateXDomain: true}); redraw({withUpdateXDomain: true});
}; };
c3.zoom = function () {
};
c3.zoom.enable = function (enabled) {
__zoom_enabled = enabled;
updateAndRedraw();
};
c3.load = function (args) { c3.load = function (args) {
// update xs if specified // update xs if specified
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment