Browse Source

Refactor redraw arguments

pull/1/head
Masayuki Tanaka 12 years ago
parent
commit
f01dc2a218
  1. 35
      c3.js

35
c3.js

@ -742,7 +742,7 @@
/*-- Define brush --*/ /*-- Define brush --*/
var brush = d3.svg.brush().x(subX).on("brush", redraw); var brush = d3.svg.brush().x(subX).on("brush", redrawForBrush);
/*-- Draw Chart --*/ /*-- Draw Chart --*/
@ -1096,18 +1096,20 @@
updateTargets(targets); updateTargets(targets);
// Draw with targets // Draw with targets
redraw(false, true, true); redraw({withTransition:false});
} }
function redraw (withTransition, withY, withSubchart) { function redraw (options) {
var xgrid, xgridData, xgridLine; var xgrid, xgridData, xgridLine;
var mainPath, mainCircle, mainBar, contextPath; var mainPath, mainCircle, mainBar, contextPath;
var barIndices = getBarIndices(), barTargetsNum = barIndices.__max__ + 1; var barIndices = getBarIndices(), barTargetsNum = barIndices.__max__ + 1;
var barX, barY, barW, barH; var barX, barY, barW, barH;
var rectX, rectW; var rectX, rectW;
withY = isDefined(withY) ? withY : false; options = isDefined(options) ? options : {};
withSubchart = isDefined(withSubchart) ? withSubchart : false; withY = isDefined(options.withY) ? options.withY : true;
withSubchart = isDefined(options.withSubchart) ? options.withSubchart : true;
withTransition = isDefined(options.withTransition) ? options.withTransition : true;
// ATTENTION: call here to update tickOffset // ATTENTION: call here to update tickOffset
x.domain(brush.empty() ? subX.domain() : brush.extent()); x.domain(brush.empty() ? subX.domain() : brush.extent());
@ -1279,6 +1281,13 @@
.style("fill-opacity", 0) .style("fill-opacity", 0)
.remove(); .remove();
} }
function redrawForBrush() {
redraw({
withTransition: false,
withY: false,
withSubchart: false
});
}
function updateTargets (targets) { function updateTargets (targets) {
var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate; var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate;
@ -1387,7 +1396,7 @@
updateTargets(c3.data.targets); updateTargets(c3.data.targets);
// Redraw with new targets // Redraw with new targets
redraw(true, true, true); redraw();
done(); done();
} }
@ -1541,7 +1550,7 @@
updateLegend(c3.data.targets); updateLegend(c3.data.targets);
} }
if (c3.data.targets.length > 0) redraw(true, true, true); if (c3.data.targets.length > 0) redraw();
}; };
c3.selected = function (target) { c3.selected = function (target) {
@ -1582,36 +1591,36 @@
c3.toLine = function (targets) { c3.toLine = function (targets) {
setTargetType(targets, 'line'); setTargetType(targets, 'line');
redraw(true, true, true); redraw();
}; };
c3.toSpline = function (targets) { c3.toSpline = function (targets) {
setTargetType(targets, 'spline'); setTargetType(targets, 'spline');
redraw(true, true, true); redraw();
}; };
c3.toBar = function (targets) { c3.toBar = function (targets) {
setTargetType(targets, 'bar'); setTargetType(targets, 'bar');
redraw(true, true, true); redraw();
}; };
c3.groups = function (groups) { c3.groups = function (groups) {
if (isUndefined(groups)) return __data_groups; if (isUndefined(groups)) return __data_groups;
__data_groups = groups; __data_groups = groups;
redraw(true, true, true); redraw();
return __data_groups; return __data_groups;
}; };
c3.regions = function (regions) { c3.regions = function (regions) {
if (isUndefined(regions)) return __regions; if (isUndefined(regions)) return __regions;
__regions = regions; __regions = regions;
redraw(true, true, true); redraw();
return __regions; return __regions;
}; };
c3.regions.add = function (regions) { c3.regions.add = function (regions) {
if (isUndefined(regions)) return __regions; if (isUndefined(regions)) return __regions;
__regions = __regions.concat(regions); __regions = __regions.concat(regions);
redraw(true, true, true); redraw();
return __regions; return __regions;
}; };
c3.regions.remove = function (classes, options) { c3.regions.remove = function (classes, options) {

Loading…
Cancel
Save