Browse Source

Refactor redraw

pull/183/head
Masayuki Tanaka 11 years ago
parent
commit
9643a7aea9
  1. 67
      c3.js
  2. 4
      c3.min.js

67
c3.js

@ -3095,7 +3095,7 @@
var mainCircle, mainBar, mainRegion, mainText, contextBar, eventRect, eventRectUpdate; var mainCircle, mainBar, mainRegion, mainText, contextBar, eventRect, eventRectUpdate;
var barIndices = getBarIndices(), maxDataCountTarget; var barIndices = getBarIndices(), maxDataCountTarget;
var rectX, rectW; var rectX, rectW;
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransitionForHorizontalAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend;
var hideAxis = hasArcType(c3.data.targets); var hideAxis = hasArcType(c3.data.targets);
var drawBar, drawBarOnSub, xForText, yForText; var drawBar, drawBarOnSub, xForText, yForText;
var transitions, duration, durationForExit, durationForAxis; var transitions, duration, durationForExit, durationForAxis;
@ -3112,16 +3112,15 @@
withTransitionForExit = isDefined(options.withTransitionForExit) ? options.withTransitionForExit : withTransition; withTransitionForExit = isDefined(options.withTransitionForExit) ? options.withTransitionForExit : withTransition;
withTransitionForAxis = isDefined(options.withTransitionForAxis) ? options.withTransitionForAxis : withTransition; withTransitionForAxis = isDefined(options.withTransitionForAxis) ? options.withTransitionForAxis : withTransition;
withTransitionForHorizontalAxis = isDefined(options.withTransitionForHorizontalAxis) ? options.withTransitionForHorizontalAxis : withTransition;
duration = withTransition ? __transition_duration : 0; duration = withTransition ? __transition_duration : 0;
durationForExit = withTransitionForExit ? duration : 0; durationForExit = withTransitionForExit ? duration : 0;
durationForAxis = withTransitionForAxis ? duration : 0; durationForAxis = withTransitionForAxis ? duration : 0;
xaxis = main.select('.' + CLASS.axisX); xaxis = main.select('.' + CLASS.axisX).style("opacity", hideAxis ? 0 : 1);
yaxis = main.select('.' + CLASS.axisY); yaxis = main.select('.' + CLASS.axisY).style("opacity", hideAxis ? 0 : 1);
y2axis = main.select('.' + CLASS.axisY2); y2axis = main.select('.' + CLASS.axisY2).style("opacity", hideAxis ? 0 : 1);
subxaxis = context.select('.' + CLASS.axisX); subxaxis = context.select('.' + CLASS.axisX).style("opacity", hideAxis ? 0 : 1);
transitions = { transitions = {
axisX: xaxis.transition().duration(durationForAxis), axisX: xaxis.transition().duration(durationForAxis),
@ -3135,6 +3134,13 @@
updateLegend(mapToIds(c3.data.targets), options, transitions); updateLegend(mapToIds(c3.data.targets), options, transitions);
} }
if (isCategorized) {
// ATTENTION: need to update domain with current domain when categoryAxis
if (targetsToShow.length === 0 || !withUpdateOrgXDomain || withUpdateXDomain) {
x.domain([0, xaxis.selectAll('.tick').size()]);
}
}
if (targetsToShow.length) { if (targetsToShow.length) {
if (withUpdateOrgXDomain) { if (withUpdateOrgXDomain) {
x.domain(d3.extent(getXDomain(targetsToShow))); x.domain(d3.extent(getXDomain(targetsToShow)));
@ -3148,11 +3154,6 @@
x.domain(brush.empty() ? orgXDomain : brush.extent()); x.domain(brush.empty() ? orgXDomain : brush.extent());
if (__zoom_enabled) { zoom.scale(x).updateScaleExtent(); } if (__zoom_enabled) { zoom.scale(x).updateScaleExtent(); }
} }
} else {
// ticks increase without this when no data shown
if (isCategorized) {
x.domain([0, xaxis.selectAll('.tick').size()]);
}
} }
y.domain(getYDomain(targetsToShow, 'y')); y.domain(getYDomain(targetsToShow, 'y'));
@ -3165,33 +3166,11 @@
subXAxis.tickValues(tickValues); subXAxis.tickValues(tickValues);
} }
// x axis // axes
xaxis.style("opacity", hideAxis ? 0 : 1); transitions.axisX.call(xAxis);
if (__axis_rotated || withTransitionForHorizontalAxis) { transitions.axisY.call(yAxis);
xaxis = transitions.axisX; transitions.axisY2.call(y2Axis);
} transitions.axisSubX.call(subXAxis);
xaxis.call(xAxis);
// y axis
yaxis.style("opacity", hideAxis ? 0 : 1);
if (!__axis_rotated || withTransitionForHorizontalAxis) {
yaxis = transitions.axisY;
}
yaxis.call(yAxis);
// y2 axis
y2axis.style("opacity", hideAxis ? 0 : 1);
if (!__axis_rotated || withTransitionForHorizontalAxis) {
y2axis = transitions.axisY2;
}
y2axis.call(y2Axis);
// sub x axis
subxaxis.style("opacity", hideAxis ? 0 : 1);
if (__axis_rotated || withTransitionForHorizontalAxis) {
subxaxis = transitions.axisSubX;
}
subxaxis.call(subXAxis);
// show/hide if manual culling needed // show/hide if manual culling needed
if (withUpdateXDomain) { if (withUpdateXDomain) {
@ -3907,14 +3886,12 @@
.style('visibility', 'visible') .style('visibility', 'visible')
.transition() .transition()
.style('opacity', opacityForLegend); .style('opacity', opacityForLegend);
updateLegend(mapToIds(c3.data.targets));
} }
function hideLegend(targetIds) { function hideLegend(targetIds) {
addHiddenLegendIds(targetIds); addHiddenLegendIds(targetIds);
legend.selectAll(selectorLegends(targetIds)) legend.selectAll(selectorLegends(targetIds))
.style('opacity', 0) .style('opacity', 0)
.style('visibility', 'hidden'); .style('visibility', 'hidden');
updateLegend(mapToIds(c3.data.targets));
} }
function updateLegend(targetIds, options, transitions) { function updateLegend(targetIds, options, transitions) {
@ -4163,7 +4140,7 @@
.style('opacity', 1); .style('opacity', 1);
} }
redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withTransitionForHorizontalAxis: false}); redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
}; };
c3.hide = function (targetIds, options) { c3.hide = function (targetIds, options) {
@ -4184,7 +4161,7 @@
.style('opacity', legendOpacityForHidden); .style('opacity', legendOpacityForHidden);
} }
redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withTransitionForHorizontalAxis: false}); redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
}; };
c3.toggle = function (targetId) { c3.toggle = function (targetId) {
@ -4454,15 +4431,15 @@
legend.style('visibility', 'visible'); legend.style('visibility', 'visible');
} }
showLegend(mapToTargetIds(targetIds)); showLegend(mapToTargetIds(targetIds));
redraw({withTransitionForHorizontalAxis: false}); redraw({withLegend: true});
}; };
c3.legend.hide = function (targetIds) { c3.legend.hide = function (targetIds) {
hideLegend(mapToTargetIds(targetIds));
redraw({withLegend: true});
if (__legend_show && isEmpty(targetIds)) { if (__legend_show && isEmpty(targetIds)) {
__legend_show = false; __legend_show = false;
legend.style('visibility', 'hidden'); legend.style('visibility', 'hidden');
} }
hideLegend(mapToTargetIds(targetIds));
redraw({withTransitionForHorizontalAxis: false});
}; };
c3.resize = function (size) { c3.resize = function (size) {

4
c3.min.js vendored

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