Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brush selection rename #1423

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.0 alpha 12
* Rename selection --> brushSelection. By Deepak Kumar.([#1423](https://github.com/dc-js/dc.js/issues/1423))

## 3.0.0 alpha 11
* xAxisPaddingUnit should be the d3 interval not the name of it ([#1320](https://github.com/dc-js/dc.js/issues/1320), [#1326](https://github.com/dc-js/dc.js/issues/1326), [#1420](https://github.com/dc-js/dc.js/issues/1420))

Expand Down
18 changes: 9 additions & 9 deletions src/bar-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ dc.barChart = function (parent, chartGroup) {
}
}

_chart.fadeDeselectedArea = function (selection) {
_chart.fadeDeselectedArea = function (brushSelection) {
var bars = _chart.chartBodyG().selectAll('rect.bar');

if (_chart.isOrdinal()) {
Expand All @@ -229,9 +229,9 @@ dc.barChart = function (parent, chartGroup) {
bars.classed(dc.constants.DESELECTED_CLASS, false);
}
} else {
if (!_chart.brushIsEmpty(selection)) {
var start = selection[0];
var end = selection[1];
if (!_chart.brushIsEmpty(brushSelection)) {
var start = brushSelection[0];
var end = brushSelection[1];

bars.classed(dc.constants.DESELECTED_CLASS, function (d) {
return d.x < start || d.x >= end;
Expand Down Expand Up @@ -315,12 +315,12 @@ dc.barChart = function (parent, chartGroup) {
return _chart;
};

_chart.extendBrush = function (selection) {
if (selection && _chart.round() && (!_centerBar || _alwaysUseRounding)) {
selection[0] = _chart.round()(selection[0]);
selection[1] = _chart.round()(selection[1]);
_chart.extendBrush = function (brushSelection) {
if (brushSelection && _chart.round() && (!_centerBar || _alwaysUseRounding)) {
brushSelection[0] = _chart.round()(brushSelection[0]);
brushSelection[1] = _chart.round()(brushSelection[1]);
}
return selection;
return brushSelection;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/box-plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ dc.boxPlot = function (parent, chartGroup) {
boxesG.exit().remove().call(_box);
}

_chart.fadeDeselectedArea = function (selection) {
_chart.fadeDeselectedArea = function (brushSelection) {
if (_chart.hasFilter()) {
if (_chart.isOrdinal()) {
_chart.g().selectAll('g.box').each(function (d) {
Expand All @@ -192,8 +192,8 @@ dc.boxPlot = function (parent, chartGroup) {
}
});
} else {
var start = selection[0];
var end = selection[1];
var start = brushSelection[0];
var end = brushSelection[1];
var keyAccessor = _chart.keyAccessor();
_chart.g().selectAll('g.box').each(function (d) {
var key = keyAccessor(d);
Expand Down
4 changes: 2 additions & 2 deletions src/bubble-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ dc.bubbleChart = function (parent, chartGroup) {
// override default x axis brush from parent chart
};

_chart.redrawBrush = function (selection, doTransition) {
_chart.redrawBrush = function (brushSelection, doTransition) {
// override default x axis brush from parent chart
_chart.fadeDeselectedArea(selection);
_chart.fadeDeselectedArea(brushSelection);
};

return _chart.anchor(parent, chartGroup);
Expand Down
20 changes: 10 additions & 10 deletions src/composite-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ dc.compositeChart = function (parent, chartGroup) {
return;
}

var selection = d3.event.selection;
if (selection) {
selection = selection.map(_chart.x().invert);
var brushSelection = d3.event.selection;
if (brushSelection) {
brushSelection = brushSelection.map(_chart.x().invert);
}
selection = _chart.extendBrush(selection);
brushSelection = _chart.extendBrush(brushSelection);

_chart.redrawBrush(selection, false);
_chart.redrawBrush(brushSelection, false);

var brushIsEmpty = _chart.brushIsEmpty(selection);
var brushIsEmpty = _chart.brushIsEmpty(brushSelection);

_chart.replaceFilter(brushIsEmpty ? null : selection);
_chart.replaceFilter(brushIsEmpty ? null : brushSelection);

for (var i = 0; i < _children.length; ++i) {
_children[i].replaceFilter(brushIsEmpty ? null : selection);
_children[i].replaceFilter(brushIsEmpty ? null : brushSelection);
}
};

Expand Down Expand Up @@ -284,11 +284,11 @@ dc.compositeChart = function (parent, chartGroup) {
return _chart;
};

_chart.fadeDeselectedArea = function (selection) {
_chart.fadeDeselectedArea = function (brushSelection) {
for (var i = 0; i < _children.length; ++i) {
var child = _children[i];
child.brush(_chart.brush());
child.fadeDeselectedArea(selection);
child.fadeDeselectedArea(brushSelection);
}
};

Expand Down
40 changes: 20 additions & 20 deletions src/coordinate-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,16 +1053,16 @@ dc.coordinateGridMixin = function (_chart) {
.attr('d', _chart.resizeHandlePath);
};

_chart.extendBrush = function (selection) {
if (selection && _chart.round()) {
selection[0] = _chart.round()(selection[0]);
selection[1] = _chart.round()(selection[1]);
_chart.extendBrush = function (brushSelection) {
if (brushSelection && _chart.round()) {
brushSelection[0] = _chart.round()(brushSelection[0]);
brushSelection[1] = _chart.round()(brushSelection[1]);
}
return selection;
return brushSelection;
};

_chart.brushIsEmpty = function (selection) {
return !selection || selection[1] <= selection[0];
_chart.brushIsEmpty = function (brushSelection) {
return !brushSelection || brushSelection[1] <= brushSelection[0];
};

_chart._brushing = function () {
Expand All @@ -1078,22 +1078,22 @@ dc.coordinateGridMixin = function (_chart) {
return;
}

var selection = d3.event.selection;
if (selection) {
selection = selection.map(_chart.x().invert);
var brushSelection = d3.event.selection;
if (brushSelection) {
brushSelection = brushSelection.map(_chart.x().invert);
}

selection = _chart.extendBrush(selection);
brushSelection = _chart.extendBrush(brushSelection);

_chart.redrawBrush(selection, false);
_chart.redrawBrush(brushSelection, false);

if (_chart.brushIsEmpty(selection)) {
if (_chart.brushIsEmpty(brushSelection)) {
dc.events.trigger(function () {
_chart.filter(null);
_chart.redrawGroup();
}, dc.constants.EVENT_DELAY);
} else {
var rangedFilter = dc.filters.RangedFilter(selection[0], selection[1]);
var rangedFilter = dc.filters.RangedFilter(brushSelection[0], brushSelection[1]);

dc.events.trigger(function () {
_chart.replaceFilter(rangedFilter);
Expand All @@ -1110,20 +1110,20 @@ dc.coordinateGridMixin = function (_chart) {
.call(_brush);
};

_chart.redrawBrush = function (selection, doTransition) {
_chart.redrawBrush = function (brushSelection, doTransition) {
if (_brushOn && _gBrush) {
if (_resizing) {
_chart.setBrushExtents(doTransition);
}

if (!selection) {
if (!brushSelection) {
_gBrush
.call(_brush.move, null);

_gBrush.selectAll('path.' + CUSTOM_BRUSH_HANDLE_CLASS)
.attr('display', 'none');
} else {
var scaledSelection = [_x(selection[0]), _x(selection[1])];
var scaledSelection = [_x(brushSelection[0]), _x(brushSelection[1])];

var gBrush =
dc.optionalTransition(doTransition, _chart.transitionDuration(), _chart.transitionDelay())(_gBrush);
Expand All @@ -1134,15 +1134,15 @@ dc.coordinateGridMixin = function (_chart) {
gBrush.selectAll('path.' + CUSTOM_BRUSH_HANDLE_CLASS)
.attr('display', null)
.attr('transform', function (d, i) {
return 'translate(' + _x(selection[i]) + ', 0)';
return 'translate(' + _x(brushSelection[i]) + ', 0)';
})
.attr('d', _chart.resizeHandlePath);
}
}
_chart.fadeDeselectedArea(selection);
_chart.fadeDeselectedArea(brushSelection);
};

_chart.fadeDeselectedArea = function (selection) {
_chart.fadeDeselectedArea = function (brushSelection) {
// do nothing, sub-chart should override this function
};

Expand Down
42 changes: 21 additions & 21 deletions src/scatter-plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,16 @@ dc.scatterPlot = function (parent, chartGroup) {
// no handle paths for poly-brushes
};

_chart.extendBrush = function (selection) {
_chart.extendBrush = function (brushSelection) {
if (_chart.round()) {
selection[0] = selection[0].map(_chart.round());
selection[1] = selection[1].map(_chart.round());
brushSelection[0] = brushSelection[0].map(_chart.round());
brushSelection[1] = brushSelection[1].map(_chart.round());
}
return selection;
return brushSelection;
};

_chart.brushIsEmpty = function (selection) {
return !selection || selection[0][0] >= selection[1][0] || selection[0][1] >= selection[1][1];
_chart.brushIsEmpty = function (brushSelection) {
return !brushSelection || brushSelection[0][0] >= brushSelection[1][0] || brushSelection[0][1] >= brushSelection[1][1];
};

_chart._brushing = function () {
Expand All @@ -417,36 +417,36 @@ dc.scatterPlot = function (parent, chartGroup) {
return;
}

var selection = d3.event.selection;
var brushSelection = d3.event.selection;

// Testing with pixels is more reliable
var brushIsEmpty = _chart.brushIsEmpty(selection);
var brushIsEmpty = _chart.brushIsEmpty(brushSelection);

if (selection) {
selection = selection.map(function (point) {
if (brushSelection) {
brushSelection = brushSelection.map(function (point) {
return point.map(function (coord, i) {
var scale = i === 0 ? _chart.x() : _chart.y();
return scale.invert(coord);
});
});

selection = _chart.extendBrush(selection);
brushSelection = _chart.extendBrush(brushSelection);

// The rounding process might have made selection empty, so we need to recheck
brushIsEmpty = brushIsEmpty && _chart.brushIsEmpty(selection);
// The rounding process might have made brushSelection empty, so we need to recheck
brushIsEmpty = brushIsEmpty && _chart.brushIsEmpty(brushSelection);
}

_chart.redrawBrush(selection, false);
_chart.redrawBrush(brushSelection, false);

var ranged2DFilter = brushIsEmpty ? null : dc.filters.RangedTwoDimensionalFilter(selection);
var ranged2DFilter = brushIsEmpty ? null : dc.filters.RangedTwoDimensionalFilter(brushSelection);

dc.events.trigger(function () {
_chart.replaceFilter(ranged2DFilter);
_chart.redrawGroup();
}, dc.constants.EVENT_DELAY);
};

_chart.redrawBrush = function (selection, doTransition) {
_chart.redrawBrush = function (brushSelection, doTransition) {
// override default x axis brush from parent chart
var _brush = _chart.brush();
var _gBrush = _chart.gBrush();
Expand All @@ -456,12 +456,12 @@ dc.scatterPlot = function (parent, chartGroup) {
_chart.setBrushExtents(doTransition);
}

if (!selection) {
if (!brushSelection) {
_gBrush
.call(_brush.move, selection);
.call(_brush.move, brushSelection);

} else {
selection = selection.map(function (point) {
brushSelection = brushSelection.map(function (point) {
return point.map(function (coord, i) {
var scale = i === 0 ? _chart.x() : _chart.y();
return scale(coord);
Expand All @@ -472,12 +472,12 @@ dc.scatterPlot = function (parent, chartGroup) {
dc.optionalTransition(doTransition, _chart.transitionDuration(), _chart.transitionDelay())(_gBrush);

gBrush
.call(_brush.move, selection);
.call(_brush.move, brushSelection);

}
}

_chart.fadeDeselectedArea(selection);
_chart.fadeDeselectedArea(brushSelection);
};

_chart.setBrushY = function (gBrush) {
Expand Down