Skip to content

Commit

Permalink
resize brush handles on chart redraw
Browse files Browse the repository at this point in the history
for #971
also, transition the brush and optionalTransition helper
also enables brush for resize-right-axis for testing purposes
  • Loading branch information
gordonwoodhull committed Aug 5, 2015
1 parent a83e621 commit 354b890
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 23 deletions.
24 changes: 20 additions & 4 deletions dc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dc.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dc.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dc.min.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ dc.coordinateGridMixin = function (_chart) {
.attr('class', 'brush')
.attr('transform', 'translate(' + _chart.margins().left + ',' + _chart.margins().top + ')')
.call(_brush.x(_chart.x()));
_chart.setBrushY(gBrush);
_chart.setBrushY(gBrush, false);
_chart.setHandlePaths(gBrush);

if (_chart.hasFilter()) {
Expand All @@ -884,8 +884,10 @@ dc.coordinateGridMixin = function (_chart) {
gBrush.selectAll('.resize').append('path').attr('d', _chart.resizeHandlePath);
};

_chart.setBrushY = function (gBrush) {
gBrush.selectAll('rect').attr('height', brushHeight());
_chart.setBrushY = function (gBrush, doTransition) {
var transition = dc.optionalTransition(doTransition, _chart.transitionDuration());
transition(gBrush.selectAll('.brush rect')).attr('height', brushHeight());
transition(gBrush.selectAll('.resize path')).attr('d', _chart.resizeHandlePath);
};

_chart.extendBrush = function () {
Expand Down Expand Up @@ -932,7 +934,7 @@ dc.coordinateGridMixin = function (_chart) {

var gBrush = g.select('g.brush');
gBrush.call(_chart.brush().x(_chart.x()));
_chart.setBrushY(gBrush);
_chart.setBrushY(gBrush, true);
}

_chart.fadeDeselectedArea();
Expand Down
14 changes: 14 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ dc.transition = function (selections, duration, callback) {
return s;
};

/* somewhat silly, but to avoid duplicating logic */
dc.optionalTransition = function (enable, duration, callback) {
if (enable) {
return function (selection) {
return dc.transition(selection, duration, callback);
};
}
else {
return function (selection) {
return selection;
};
}
};

dc.units = {};

/**
Expand Down
24 changes: 20 additions & 4 deletions web/js/dc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/js/dc.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions web/js/dc.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/js/dc.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/resizing/resizing-right-axis.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
.elasticY(true)
.renderHorizontalGridLines(true)
.legend(dc.legend().x(90).y(10).itemHeight(13).gap(5))
.brushOn(false)
.brushOn(true)
.compose([
dc.lineChart(moveChart)
.group(indexAvgByMonthGroup, "Monthly Index Average")
Expand Down

0 comments on commit 354b890

Please sign in to comment.