Commit ab3c3826 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Enable zoom

parent 368573af
...@@ -421,8 +421,15 @@ ...@@ -421,8 +421,15 @@
return [hasBarType(yTargets) ? 0 : yDomainMin-padding_bottom, yDomainMax+padding_top]; return [hasBarType(yTargets) ? 0 : yDomainMin-padding_bottom, yDomainMax+padding_top];
} }
function getXDomainRatio () { function getXDomainRatio () {
if (brush.empty()) return 1; var domain, extent;
var domain = subX.domain(), extent = brush.extent(); if (__subchart_show) {
if (brush.empty()) return 1;
domain = subX.domain();
extent = brush.extent();
} else {
domain = orgXDomain;
extent = x.domain();
}
return (domain[1] - domain[0]) / (extent[1] - extent[0]); return (domain[1] - domain[0]) / (extent[1] - extent[0]);
} }
...@@ -828,6 +835,7 @@ ...@@ -828,6 +835,7 @@
/*-- Define brush --*/ /*-- Define brush --*/
var brush = d3.svg.brush().x(subX).on("brush", redrawForBrush); var brush = d3.svg.brush().x(subX).on("brush", redrawForBrush);
var zoom = d3.behavior.zoom().on("zoom", redrawForZoom);
/*-- Draw Chart --*/ /*-- Draw Chart --*/
...@@ -835,6 +843,8 @@ ...@@ -835,6 +843,8 @@
var firstDate = null, var firstDate = null,
lastDate = null; lastDate = null;
var orgXDomain;
function init (data) { function init (data) {
var targets = c3.data.targets = convertDataToTargets(data); var targets = c3.data.targets = convertDataToTargets(data);
var rectX, rectW; var rectX, rectW;
...@@ -855,6 +865,12 @@ ...@@ -855,6 +865,12 @@
yAxis.ticks(3).outerTickSize(0).tickFormat(__axis_y_format); yAxis.ticks(3).outerTickSize(0).tickFormat(__axis_y_format);
yAxis2.ticks(3).outerTickSize(0).tickFormat(__axis_y2_format); yAxis2.ticks(3).outerTickSize(0).tickFormat(__axis_y2_format);
// Save original x domain for zoom update
orgXDomain = x.domain();
// MEMO: must set x here for timeseries data
zoom.x(x);
/*-- Main Region --*/ /*-- Main Region --*/
// Add Axis // Add Axis
...@@ -1123,7 +1139,8 @@ ...@@ -1123,7 +1139,8 @@
dragging = false; dragging = false;
// TODO: add callback here // TODO: add callback here
}) })
); )
.call(zoom);
// Define g for bar chart area // Define g for bar chart area
main.select(".chart").append("g") main.select(".chart").append("g")
...@@ -1204,14 +1221,20 @@ ...@@ -1204,14 +1221,20 @@
var barIndices = getBarIndices(), barTargetsNum = barIndices.__max__ + 1; var barIndices = getBarIndices(), barTargetsNum = barIndices.__max__ + 1;
var barX, barY, barW, barH; var barX, barY, barW, barH;
var rectX, rectW; var rectX, rectW;
var withY, withSubchart, withTransition, withUpdateXDomain;
// Hide tooltip and grid
main.select('line.xgrid-focus').style("visibility", "hidden");
tooltip.style("visibility", "hidden");
options = isDefined(options) ? options : {}; options = isDefined(options) ? options : {};
withY = isDefined(options.withY) ? options.withY : true; withY = isDefined(options.withY) ? options.withY : true;
withSubchart = isDefined(options.withSubchart) ? options.withSubchart : true; withSubchart = isDefined(options.withSubchart) ? options.withSubchart : true;
withTransition = isDefined(options.withTransition) ? options.withTransition : true; withTransition = isDefined(options.withTransition) ? options.withTransition : true;
withUpdateXDomain = isDefined(options.withUpdateXDomain) ? options.withUpdateXDomain : true;
// ATTENTION: call here to update tickOffset // ATTENTION: call here to update tickOffset
x.domain(brush.empty() ? subX.domain() : brush.extent()); if (withUpdateXDomain) x.domain(brush.empty() ? subX.domain() : brush.extent());
y.domain(getYDomain(c3.data.targets, 'y')); y.domain(getYDomain(c3.data.targets, 'y'));
y2.domain(getYDomain(c3.data.targets, 'y2')); y2.domain(getYDomain(c3.data.targets, 'y2'));
...@@ -1387,6 +1410,14 @@ ...@@ -1387,6 +1410,14 @@
withSubchart: false withSubchart: false
}); });
} }
function redrawForZoom() {
redraw({
withTransition: false,
withY: false,
withSubchart: false,
withUpdateXDomain: false
});
}
function resize () { function resize () {
// Update sizes and scales // Update sizes and scales
......
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