Skip to content

Commit

Permalink
Fix selection by drag
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki0812 committed May 10, 2014
1 parent 102c9ab commit 358bd15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions c3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2954,30 +2954,33 @@
main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape)
.filter(function (d) { return __data_selection_isselectable(d); })
.each(function (d, i) {
var _this = d3.select(this),
isSelected = _this.classed(CLASS.SELECTED),
isIncluded = _this.classed(CLASS.INCLUDED),
var shape = d3.select(this),
isSelected = shape.classed(CLASS.SELECTED),
isIncluded = shape.classed(CLASS.INCLUDED),
_x, _y, _w, _h, toggle, isWithin = false, box;
if (this.nodeName === 'circle') {
_x = _this.attr("cx") * 1;
_y = _this.attr("cy") * 1;
if (shape.classed(CLASS.circle)) {
_x = shape.attr("cx") * 1;
_y = shape.attr("cy") * 1;
toggle = togglePoint;
isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY;
}
else if (this.nodeName === 'path') {
else if (shape.classed(CLASS.bar)) {
box = getPathBox(this);
_x = box.x;
_y = box.y;
_w = box.width;
_h = box.height;
toggle = toggleBar;
isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY);
} else {
// line/area selection not supported yet
return;
}
if (isWithin ^ isIncluded) {
_this.classed(CLASS.INCLUDED, !isIncluded);
shape.classed(CLASS.INCLUDED, !isIncluded);
// TODO: included/unincluded callback here
_this.classed(CLASS.SELECTED, !isSelected);
toggle(!isSelected, _this, d, i);
shape.classed(CLASS.SELECTED, !isSelected);
toggle(!isSelected, shape, d, i);
}
});
}
Expand Down
Loading

0 comments on commit 358bd15

Please sign in to comment.