|
|
@ -7,14 +7,10 @@ c3_chart_internal_fn.initBrush = function (scale) { |
|
|
|
// TODO: dynamically change brushY/brushX according to axis_rotated.
|
|
|
|
// TODO: dynamically change brushY/brushX according to axis_rotated.
|
|
|
|
$$.brush = ($$.config.axis_rotated ? d3.brushY() : d3.brushX()).on("brush", function () { |
|
|
|
$$.brush = ($$.config.axis_rotated ? d3.brushY() : d3.brushX()).on("brush", function () { |
|
|
|
if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") { return; } |
|
|
|
if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") { return; } |
|
|
|
|
|
|
|
|
|
|
|
// TODO: fix
|
|
|
|
|
|
|
|
var s = d3.event.selection || $$.brush.scale.range(); |
|
|
|
|
|
|
|
$$.main.select('.' + CLASS.eventRect).call($$.zoom.transform, d3.zoomIdentity |
|
|
|
|
|
|
|
.scale($$.width / (s[1] - s[0])) |
|
|
|
|
|
|
|
.translate(-s[0], 0)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$$.redrawForBrush(); |
|
|
|
$$.redrawForBrush(); |
|
|
|
|
|
|
|
}).on("end", function () { |
|
|
|
|
|
|
|
if (d3.event.sourceEvent && d3.event.sourceEvent.type === "zoom") { return; } |
|
|
|
|
|
|
|
if ($$.brush.empty() && d3.event.sourceEvent.type !== 'end') { $$.brush.clear(); } |
|
|
|
}); |
|
|
|
}); |
|
|
|
$$.brush.updateExtent = function () { |
|
|
|
$$.brush.updateExtent = function () { |
|
|
|
var range = this.scale.range(), extent; |
|
|
|
var range = this.scale.range(), extent; |
|
|
@ -35,6 +31,9 @@ c3_chart_internal_fn.initBrush = function (scale) { |
|
|
|
this.updateScale(scale || $$.subX).updateExtent(); |
|
|
|
this.updateScale(scale || $$.subX).updateExtent(); |
|
|
|
$$.context.select('.' + CLASS.brush).call(this); |
|
|
|
$$.context.select('.' + CLASS.brush).call(this); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
$$.brush.clear = function () { |
|
|
|
|
|
|
|
$$.context.select('.' + CLASS.brush).call($$.brush.move, null); |
|
|
|
|
|
|
|
}; |
|
|
|
$$.brush.selection = function () { |
|
|
|
$$.brush.selection = function () { |
|
|
|
return d3.brushSelection($$.context.select('.' + CLASS.brush).node()); |
|
|
|
return d3.brushSelection($$.context.select('.' + CLASS.brush).node()); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -227,7 +226,7 @@ c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, durat |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.redrawForBrush = function () { |
|
|
|
c3_chart_internal_fn.redrawForBrush = function () { |
|
|
|
var $$ = this, x = $$.x; |
|
|
|
var $$ = this, x = $$.x, d3 = $$.d3, s; |
|
|
|
$$.redraw({ |
|
|
|
$$.redraw({ |
|
|
|
withTransition: false, |
|
|
|
withTransition: false, |
|
|
|
withY: $$.config.zoom_rescale, |
|
|
|
withY: $$.config.zoom_rescale, |
|
|
@ -236,6 +235,11 @@ c3_chart_internal_fn.redrawForBrush = function () { |
|
|
|
withEventRect: false, |
|
|
|
withEventRect: false, |
|
|
|
withDimension: false |
|
|
|
withDimension: false |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// update zoom transation binded to event rect
|
|
|
|
|
|
|
|
s = d3.event.selection || $$.brush.scale.range(); |
|
|
|
|
|
|
|
$$.main.select('.' + CLASS.eventRect).call($$.zoom.transform, d3.zoomIdentity |
|
|
|
|
|
|
|
.scale($$.width / (s[1] - s[0])) |
|
|
|
|
|
|
|
.translate(-s[0], 0)); |
|
|
|
$$.config.subchart_onbrush.call($$.api, x.orgDomain()); |
|
|
|
$$.config.subchart_onbrush.call($$.api, x.orgDomain()); |
|
|
|
}; |
|
|
|
}; |
|
|
|
c3_chart_internal_fn.transformContext = function (withTransition, transitions) { |
|
|
|
c3_chart_internal_fn.transformContext = function (withTransition, transitions) { |
|
|
|