Browse Source

Use chart object as this in event handlers - #327

pull/373/merge
Masayuki Tanaka 10 years ago
parent
commit
a2aea133d0
  1. 46
      c3.js
  2. 4
      c3.min.js

46
c3.js

@ -2455,7 +2455,7 @@
//-- Selection --// //-- Selection --//
function selectPoint(target, d, i) { function selectPoint(target, d, i) {
__data_onselected(d, target.node()); __data_onselected.call(c3, d, target.node());
// add selected-circle on low layer g // add selected-circle on low layer g
main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i)
.data([d]) .data([d])
@ -2469,7 +2469,7 @@
.attr("r", pointSelectR); .attr("r", pointSelectR);
} }
function unselectPoint(target, d, i) { function unselectPoint(target, d, i) {
__data_onunselected(d, target.node()); __data_onunselected.call(c3, d, target.node());
// remove selected-circle from low layer g // remove selected-circle from low layer g
main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i)
.transition().duration(100).attr('r', 0) .transition().duration(100).attr('r', 0)
@ -2480,11 +2480,11 @@
} }
function selectBar(target, d) { function selectBar(target, d) {
__data_onselected(d, target.node()); __data_onselected.call(c3, d, target.node());
target.transition().duration(100).style("fill", function () { return d3.rgb(color(d)).brighter(0.75); }); target.transition().duration(100).style("fill", function () { return d3.rgb(color(d)).brighter(0.75); });
} }
function unselectBar(target, d) { function unselectBar(target, d) {
__data_onunselected(d, target.node()); __data_onunselected.call(c3, d, target.node());
target.transition().duration(100).style("fill", function () { return color(d); }); target.transition().duration(100).style("fill", function () { return color(d); });
} }
function toggleBar(selected, target, d, i) { function toggleBar(selected, target, d, i) {
@ -2925,8 +2925,8 @@
// Define svgs // Define svgs
svg = selectChart.append("svg") svg = selectChart.append("svg")
.style("overflow", "hidden") .style("overflow", "hidden")
.on('mouseenter', __onmouseover) .on('mouseenter', function () { return __onmouseover.call(c3); })
.on('mouseleave', __onmouseout); .on('mouseleave', function () { return __onmouseout.call(c3); });
// Define defs // Define defs
defs = svg.append("defs"); defs = svg.append("defs");
@ -3171,11 +3171,15 @@
window.onresize = generateResize(); window.onresize = generateResize();
} }
if (window.onresize.add) { if (window.onresize.add) {
window.onresize.add(__onresize); window.onresize.add(function () {
__onresize.call(c3);
});
window.onresize.add(function () { window.onresize.add(function () {
c3.flush(); c3.flush();
}); });
window.onresize.add(__onresized); window.onresize.add(function () {
__onresized.call(c3);
});
} }
// export element of the chart // export element of the chart
@ -3215,7 +3219,7 @@
// Call event handler // Call event handler
main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) {
__data_onmouseover(d); __data_onmouseover.call(c3, d);
}); });
}) })
.on('mouseout', function (d) { .on('mouseout', function (d) {
@ -3228,7 +3232,7 @@
unexpandBars(); unexpandBars();
// Call event handler // Call event handler
main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) {
__data_onmouseout(d); __data_onmouseout.call(c3, d);
}); });
}) })
.on('mousemove', function (d) { .on('mousemove', function (d) {
@ -3354,12 +3358,12 @@
if (dist(closest, mouse) < 100) { if (dist(closest, mouse) < 100) {
svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); svg.select('.' + CLASS.eventRect).style('cursor', 'pointer');
if (!mouseover) { if (!mouseover) {
__data_onmouseover(closest); __data_onmouseover.call(c3, closest);
mouseover = true; mouseover = true;
} }
} else { } else {
svg.select('.' + CLASS.eventRect).style('cursor', null); svg.select('.' + CLASS.eventRect).style('cursor', null);
__data_onmouseout(closest); __data_onmouseout.call(c3, closest);
mouseover = false; mouseover = false;
} }
}) })
@ -3416,7 +3420,7 @@
shape.classed(CLASS.SELECTED, !isSelected); shape.classed(CLASS.SELECTED, !isSelected);
toggle(!isSelected, shape, d, i); toggle(!isSelected, shape, d, i);
} }
__data_onclick(d, that); __data_onclick.call(c3, d, that);
} }
} }
@ -3485,7 +3489,7 @@
.attr('class', CLASS.dragarea) .attr('class', CLASS.dragarea)
.style('opacity', 0.1); .style('opacity', 0.1);
dragging = true; dragging = true;
__data_ondragstart(); __data_ondragstart.call(c3);
} }
function dragend() { function dragend() {
@ -3498,7 +3502,7 @@
main.selectAll('.' + CLASS.shape) main.selectAll('.' + CLASS.shape)
.classed(CLASS.INCLUDED, false); .classed(CLASS.INCLUDED, false);
dragging = false; dragging = false;
__data_ondragend(); __data_ondragend.call(c3);
} }
function smoothLines(el, type) { function smoothLines(el, type) {
@ -3836,7 +3840,7 @@
// transitions // transitions
expandArc(updated.data.id); expandArc(updated.data.id);
toggleFocusLegend(updated.data.id, true); toggleFocusLegend(updated.data.id, true);
callback(arcData, i); callback.call(c3, arcData, i);
}) })
.on('mousemove', function (d) { .on('mousemove', function (d) {
var updated = updateAngle(d), arcData = convertToArcData(updated), selectedData = [arcData]; var updated = updateAngle(d), arcData = convertToArcData(updated), selectedData = [arcData];
@ -3854,12 +3858,12 @@
unexpandArc(updated.data.id); unexpandArc(updated.data.id);
revertLegend(); revertLegend();
hideTooltip(); hideTooltip();
callback(arcData, i); callback.call(c3, arcData, i);
}) })
.on('click', function (d, i) { .on('click', function (d, i) {
var updated = updateAngle(d), arcData = convertToArcData(updated), callback = getArcOnClick(); var updated = updateAngle(d), arcData = convertToArcData(updated), callback = getArcOnClick();
toggleShape(this, d, i); toggleShape(this, d, i);
callback(arcData, i); callback.call(c3, arcData, i);
}); });
mainArc mainArc
.attr("transform", function (d) { return !isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) .attr("transform", function (d) { return !isGaugeType(d.data) && withTransform ? "scale(0)" : ""; })
@ -4673,7 +4677,7 @@
.style('visibility', function (id) { return isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('visibility', function (id) { return isLegendToShow(id) ? 'visible' : 'hidden'; })
.style('cursor', 'pointer') .style('cursor', 'pointer')
.on('click', function (id) { .on('click', function (id) {
typeof __legend_item_onclick === 'function' ? __legend_item_onclick(id) : c3.toggle(id); typeof __legend_item_onclick === 'function' ? __legend_item_onclick.call(c3, id) : c3.toggle(id);
}) })
.on('mouseover', function (id) { .on('mouseover', function (id) {
d3.select(this).classed(CLASS.legendItemFocused, true); d3.select(this).classed(CLASS.legendItemFocused, true);
@ -4681,7 +4685,7 @@
c3.focus(id); c3.focus(id);
} }
if (typeof __legend_item_onmouseover === 'function') { if (typeof __legend_item_onmouseover === 'function') {
__legend_item_onmouseover(id); __legend_item_onmouseover.call(c3, id);
} }
}) })
.on('mouseout', function (id) { .on('mouseout', function (id) {
@ -4690,7 +4694,7 @@
c3.revert(); c3.revert();
} }
if (typeof __legend_item_onmouseout === 'function') { if (typeof __legend_item_onmouseout === 'function') {
__legend_item_onmouseout(id); __legend_item_onmouseout.call(c3, id);
} }
}); });
l.append('text') l.append('text')

4
c3.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save