diff --git a/htdocs/index.html b/htdocs/index.html
index 21c7044..350636c 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -467,6 +467,12 @@
Show tooltip programmatically
+
diff --git a/htdocs/samples/api_zoom.html b/htdocs/samples/api_zoom.html
new file mode 100644
index 0000000..d0a349b
--- /dev/null
+++ b/htdocs/samples/api_zoom.html
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/api.zoom.js b/src/api.zoom.js
index cbcf6bf..286912b 100644
--- a/src/api.zoom.js
+++ b/src/api.zoom.js
@@ -7,11 +7,16 @@ c3_chart_fn.zoom = function (domain) {
if ($$.isTimeSeries()) {
domain = domain.map(function (x) { return $$.parseDate(x); });
}
- $$.brush.extent(domain);
- $$.redraw({withUpdateXDomain: true, withY: $$.config.zoom_rescale});
+ if ($$.config.subchart_show) {
+ $$.brush.selectionAsValue(domain);
+ }
+ else {
+ $$.updateXDomain(null, true, false, false, domain);
+ $$.redraw({withY: $$.config.zoom_rescale, withSubchart: false});
+ }
$$.config.zoom_onzoom.call(this, $$.x.orgDomain());
}
- return $$.brush.extent();
+ return domain;
};
c3_chart_fn.zoom.enable = function (enabled) {
var $$ = this.internal;
@@ -20,8 +25,13 @@ c3_chart_fn.zoom.enable = function (enabled) {
};
c3_chart_fn.unzoom = function () {
var $$ = this.internal;
- $$.brush.clear().update();
- $$.redraw({withUpdateXDomain: true});
+ if ($$.config.subchart_show) {
+ $$.brush.clear();
+ }
+ else {
+ $$.updateXDomain(null, true, false, false, $$.subX.domain());
+ $$.redraw({withY: $$.config.zoom_rescale, withSubchart: false});
+ }
};
c3_chart_fn.zoom.max = function (max) {
diff --git a/src/subchart.js b/src/subchart.js
index ee6f956..becb141 100644
--- a/src/subchart.js
+++ b/src/subchart.js
@@ -6,11 +6,13 @@ c3_chart_internal_fn.initBrush = function (scale) {
var $$ = this, d3 = $$.d3;
// TODO: dynamically change brushY/brushX according to axis_rotated.
$$.brush = ($$.config.axis_rotated ? d3.brushY() : d3.brushX()).on("brush", function () {
- if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") { return; }
+ var event = d3.event.sourceEvent;
+ if (event && event.type === "zoom") { return; }
$$.redrawForBrush();
}).on("end", function () {
- if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") { return; }
- if ($$.brush.empty() && d3.event.sourceEvent.type !== 'end') { $$.brush.clear(); }
+ var event = d3.event.sourceEvent;
+ if (event && event.type === "zoom") { return; }
+ if ($$.brush.empty() && event && event.type !== 'end') { $$.brush.clear(); }
});
$$.brush.updateExtent = function () {
var range = this.scale.range(), extent;
@@ -42,7 +44,7 @@ c3_chart_internal_fn.initBrush = function (scale) {
if (selectionAsValue) {
if ($$.context) {
selection = [this.scale(selectionAsValue[0]), this.scale(selectionAsValue[1])];
- $$.brush.move($$.context.select('.' + CLASS.brush), selection);
+ $$.brush.move($$.context.select('.' + CLASS.brush).transition(), selection);
}
return [];
}
@@ -86,8 +88,7 @@ c3_chart_internal_fn.initSubchart = function () {
$$.axes.subx = context.append("g")
.attr("class", CLASS.axisX)
.attr("transform", $$.getTranslate('subx'))
- .attr("clip-path", config.axis_rotated ? "" : $$.clipPathForXAxis)
- .style("visibility", config.subchart_axis_x_show ? visibility : 'hidden');
+ .attr("clip-path", config.axis_rotated ? "" : $$.clipPathForXAxis);
};
c3_chart_internal_fn.initSubchartBrush = function () {
var $$ = this;