Browse Source

Fix subchart clear in d3.v4

pull/2246/head
Masayuki Tanaka 7 years ago
parent
commit
10f229033f
  1. 2
      htdocs/samples/subchart_onbrush.html
  2. 2
      htdocs/samples/zoom_onzoom.html
  3. 20
      src/subchart.js

2
htdocs/samples/subchart_onbrush.html

@ -6,7 +6,7 @@
<div id="chart1"></div> <div id="chart1"></div>
<div id="chart2"></div> <div id="chart2"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script> <script src="/js/c3.js"></script>
<script> <script>

2
htdocs/samples/zoom_onzoom.html

@ -6,7 +6,7 @@
<div id="chart1"></div> <div id="chart1"></div>
<div id="chart2"></div> <div id="chart2"></div>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script> <script src="/js/c3.js"></script>
<script> <script>

20
src/subchart.js

@ -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) {

Loading…
Cancel
Save