Browse Source

Fix multiple click on step chart - #608

pull/590/merge
Masayuki Tanaka 10 years ago
parent
commit
10e02e5923
  1. 14
      c3.js
  2. 6
      c3.min.js
  3. 3
      src/shape.js
  4. 11
      src/shape.line.js

14
c3.js

@ -2504,8 +2504,7 @@
isWithin = false; isWithin = false;
} }
else if (that.nodeName === 'circle') { else if (that.nodeName === 'circle') {
// circle is hidden in step chart, so treat as within the click area isWithin = $$.isStepType(d) ? $$.isWithinStep(that, $$.getYScale(d.id)(d.value)) : $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5);
isWithin = $$.isStepType(d) ? true : $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5);
} }
else if (that.nodeName === 'path') { else if (that.nodeName === 'path') {
isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true; isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true;
@ -2860,11 +2859,14 @@
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
return config.point_select_r ? config.point_select_r : $$.pointR(d) * 4; return config.point_select_r ? config.point_select_r : $$.pointR(d) * 4;
}; };
c3_chart_internal_fn.isWithinCircle = function (_this, _r) { c3_chart_internal_fn.isWithinCircle = function (that, r) {
var d3 = this.d3, var d3 = this.d3,
mouse = d3.mouse(_this), d3_this = d3.select(_this), mouse = d3.mouse(that), d3_this = d3.select(that),
cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; cx = +d3_this.attr("cx"), cy = +d3_this.attr("cy");
return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < r;
};
c3_chart_internal_fn.isWithinStep = function (that, y) {
return Math.abs(y - this.d3.mouse(that)[1]) < 30;
}; };
c3_chart_internal_fn.initBar = function () { c3_chart_internal_fn.initBar = function () {

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

3
src/shape.js

@ -53,8 +53,7 @@ c3_chart_internal_fn.isWithinShape = function (that, d) {
isWithin = false; isWithin = false;
} }
else if (that.nodeName === 'circle') { else if (that.nodeName === 'circle') {
// circle is hidden in step chart, so treat as within the click area isWithin = $$.isStepType(d) ? $$.isWithinStep(that, $$.getYScale(d.id)(d.value)) : $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5);
isWithin = $$.isStepType(d) ? true : $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5);
} }
else if (that.nodeName === 'path') { else if (that.nodeName === 'path') {
isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true; isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true;

11
src/shape.line.js

@ -339,9 +339,12 @@ c3_chart_internal_fn.pointSelectR = function (d) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
return config.point_select_r ? config.point_select_r : $$.pointR(d) * 4; return config.point_select_r ? config.point_select_r : $$.pointR(d) * 4;
}; };
c3_chart_internal_fn.isWithinCircle = function (_this, _r) { c3_chart_internal_fn.isWithinCircle = function (that, r) {
var d3 = this.d3, var d3 = this.d3,
mouse = d3.mouse(_this), d3_this = d3.select(_this), mouse = d3.mouse(that), d3_this = d3.select(that),
cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; cx = +d3_this.attr("cx"), cy = +d3_this.attr("cy");
return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < r;
};
c3_chart_internal_fn.isWithinStep = function (that, y) {
return Math.abs(y - this.d3.mouse(that)[1]) < 30;
}; };

Loading…
Cancel
Save