Browse Source

Refactor drag seletion

pull/1/head
Masayuki Tanaka 12 years ago committed by masayuki
parent
commit
524a27e9d1
  1. 37
      c3.js

37
c3.js

@ -819,35 +819,32 @@
.attr('y', min_y) .attr('y', min_y)
.attr('width', max_x-min_x) .attr('width', max_x-min_x)
.attr('height', max_y-min_y) .attr('height', max_y-min_y)
main.selectAll('.target-circles').selectAll('.target-circle') main.selectAll('.target-circles, .target-bars')
.selectAll('.target-circle, .target-bar')
.filter(function(d){ return __data_selection_isselectable(d) }) .filter(function(d){ return __data_selection_isselectable(d) })
.each(function(d,i){ .each(function(d,i){
var _this = d3.select(this), var _this = d3.select(this),
_selected = _this.classed('_s_'), _selected = _this.classed('_s_'),
_included = _this.classed('_i_'), _included = _this.classed('_i_'),
_x = x(d.x), _y = y(d.value), _x, _y, _w, toggle, isWithin = false
_within = min_x < _x && _x < max_x && min_y < _y && _y < max_y if (this.nodeName === 'circle') {
if (_within ^ _included) { _x = _this.attr("cx")*1
_this.classed('_i_', !_included) _y = _this.attr("cy")*1
// TODO: included/unincluded callback here toggle = togglePoint
_this.classed('_s_', !_selected) isWithin = min_x < _x && _x < max_x && min_y < _y && _y < max_y
togglePoint(!_selected, _this, d, i)
} }
}) else if (this.nodeName === 'rect') {
main.selectAll('.target-bars').selectAll('.target-bar') _x = _this.attr("x")*1
.filter(function(d){ return __data_selection_isselectable(d) }) _y = _this.attr("y")*1
.each(function(d,i){ _w = _this.attr('width')*1
var _this = d3.select(this), toggle = toggleBar
_selected = _this.classed('_s_'), isWithin = min_x < _x+_w && _x < max_x && _y < max_y
_included = _this.classed('_i_'), }
_x = _this.attr("x")*1, _y = _this.attr("y")*1 if (isWithin ^ _included) {
_w = _this.attr('width')*1,
_within = min_x < _x+_w && _x < max_x && _y < max_y
if (_within ^ _included) {
_this.classed('_i_', !_included) _this.classed('_i_', !_included)
// TODO: included/unincluded callback here // TODO: included/unincluded callback here
_this.classed('_s_', !_selected) _this.classed('_s_', !_selected)
toggleBar(!_selected, _this, d, i) toggle(!_selected, _this, d, i)
} }
}) })
}) })

Loading…
Cancel
Save