Browse Source

Fix onclick on step chart - #489

pull/535/head
Masayuki Tanaka 10 years ago
parent
commit
beed643670
  1. 17
      c3.js
  2. 6
      c3.min.js
  3. 3
      htdocs/samples/chart_step.html
  4. 7
      src/interaction.js
  5. 10
      src/selection.js

17
c3.js

@ -2119,6 +2119,10 @@
if ($$.dragging) { return; } // do nothing when dragging if ($$.dragging) { return; } // do nothing when dragging
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
if ($$.isStepType(d) && d3.mouse(this)[0] < $$.x($$.getXValue(d.id, index))) {
index -= 1;
}
// Show tooltip // Show tooltip
selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) {
return $$.addName($$.getValueOnIndex(t.values, index)); return $$.addName($$.getValueOnIndex(t.values, index));
@ -2175,6 +2179,9 @@
$$.cancelClick = false; $$.cancelClick = false;
return; return;
} }
if ($$.isStepType(d) && d3.mouse(this)[0] < $$.x($$.getXValue(d.id, index))) {
index -= 1;
}
$$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) {
$$.toggleShape(this, d, index); $$.toggleShape(this, d, index);
}); });
@ -4672,8 +4679,14 @@
var $$ = this, d3 = $$.d3, config = $$.config, var $$ = this, d3 = $$.d3, config = $$.config,
shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle;
if (that.nodeName === 'circle') { if (that.nodeName === 'circle') {
isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); if ($$.isStepType(d)) {
toggle = $$.togglePoint; // circle is hidden in step chart, so treat as within the click area
isWithin = true;
toggle = function () {}; // TODO: how to select step chart?
} else {
isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5);
toggle = $$.togglePoint;
}
} }
else if (that.nodeName === 'path') { else if (that.nodeName === 'path') {
if (shape.classed(CLASS.bar)) { if (shape.classed(CLASS.bar)) {

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

3
htdocs/samples/chart_step.html

@ -17,7 +17,8 @@
types: { types: {
data1: 'step', data1: 'step',
data2: 'area-step' data2: 'area-step'
} },
onclick: function (d) { console.log('clicked', d); }
}, },
subchart: { subchart: {
show: true show: true

7
src/interaction.js

@ -144,6 +144,10 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
if ($$.dragging) { return; } // do nothing when dragging if ($$.dragging) { return; } // do nothing when dragging
if ($$.hasArcType()) { return; } if ($$.hasArcType()) { return; }
if ($$.isStepType(d) && d3.mouse(this)[0] < $$.x($$.getXValue(d.id, index))) {
index -= 1;
}
// Show tooltip // Show tooltip
selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) {
return $$.addName($$.getValueOnIndex(t.values, index)); return $$.addName($$.getValueOnIndex(t.values, index));
@ -200,6 +204,9 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
$$.cancelClick = false; $$.cancelClick = false;
return; return;
} }
if ($$.isStepType(d) && d3.mouse(this)[0] < $$.x($$.getXValue(d.id, index))) {
index -= 1;
}
$$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) {
$$.toggleShape(this, d, index); $$.toggleShape(this, d, index);
}); });

10
src/selection.js

@ -54,8 +54,14 @@ c3_chart_internal_fn.toggleShape = function (that, d, i) {
var $$ = this, d3 = $$.d3, config = $$.config, var $$ = this, d3 = $$.d3, config = $$.config,
shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle;
if (that.nodeName === 'circle') { if (that.nodeName === 'circle') {
isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); if ($$.isStepType(d)) {
toggle = $$.togglePoint; // circle is hidden in step chart, so treat as within the click area
isWithin = true;
toggle = function () {}; // TODO: how to select step chart?
} else {
isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5);
toggle = $$.togglePoint;
}
} }
else if (that.nodeName === 'path') { else if (that.nodeName === 'path') {
if (shape.classed(CLASS.bar)) { if (shape.classed(CLASS.bar)) {

Loading…
Cancel
Save