Browse Source

Modularize region

pull/486/head
Masayuki Tanaka 11 years ago
parent
commit
1e6867acb5
  1. 53
      c3.js
  2. 6
      c3.min.js
  3. 26
      src/core.js
  4. 27
      src/region.js

53
c3.js

@ -214,9 +214,7 @@
.attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE.
// Regions
main.append('g')
.attr("clip-path", $$.clipPath)
.attr("class", CLASS[_regions]);
$$.initRegion();
// Grids
$$.initGrid();
@ -453,7 +451,7 @@
c3_chart_internal_fn.redraw = function (options, transitions) {
var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config;
var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate;
var mainLine, mainArea, mainCircle, mainBar, mainText, eventRect, eventRectUpdate;
var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget;
var rectX, rectW;
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend;
@ -570,15 +568,7 @@
$$.redrawGrid(duration, withY);
// rect for regions
mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region])
.data(config[__regions]);
mainRegion.enter().append('g')
.attr('class', generateCall($$.classRegion, $$))
.append('rect')
.style("fill-opacity", 0);
mainRegion.exit().transition().duration(duration)
.style("opacity", 0)
.remove();
$$.redrawRegion(duration);
// bars
mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar])
@ -756,12 +746,7 @@
.attr('y', yForText)
.style("fill", $$.color)
.style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$)));
transitions.push(mainRegion.selectAll('rect').transition()
.attr("x", generateCall($$.regionX, $$))
.attr("y", generateCall($$.regionY, $$))
.attr("width", generateCall($$.regionWidth, $$))
.attr("height", generateCall($$.regionHeight, $$))
.style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; }));
$$.addTransitionForRegion(transitions);
$$.addTransitionForGrid(transitions);
// Wait for end of transitions if called from flow API
@ -784,7 +769,8 @@
wait = $$.generateWait();
var xgrid = $$.xgrid || d3.selectAll([]),
xgridLines = $$.xgridLines || d3.selectAll([]);
xgridLines = $$.xgridLines || d3.selectAll([]),
mainRegion = $$.mainRegion || d3.selectAll([]);
// remove head data after rendered
$$.data.targets.forEach(function (d) {
@ -4571,6 +4557,33 @@
}
};
c3_chart_internal_fn.initRegion = function () {
var $$ = this, CLASS = $$.CLASS;
$$.main.append('g')
.attr("clip-path", $$.clipPath)
.attr("class", CLASS[_regions]);
};
c3_chart_internal_fn.redrawRegion = function (duration) {
var $$ = this, config = $$.config, CLASS = $$.CLASS;
$$.mainRegion = $$.main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region])
.data(config[__regions]);
$$.mainRegion.enter().append('g')
.attr('class', generateCall($$.classRegion, $$))
.append('rect')
.style("fill-opacity", 0);
$$.mainRegion.exit().transition().duration(duration)
.style("opacity", 0)
.remove();
};
c3_chart_internal_fn.addTransitionForRegion = function (transitions) {
var $$ = this;
transitions.push($$.mainRegion.selectAll('rect').transition()
.attr("x", generateCall($$.regionX, $$))
.attr("y", generateCall($$.regionY, $$))
.attr("width", generateCall($$.regionWidth, $$))
.attr("height", generateCall($$.regionHeight, $$))
.style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; }));
};
c3_chart_internal_fn.regionX = function (d) {
var $$ = this, config = $$.config,
xPos, yScale = d.axis === 'y' ? $$.y : $$.y2;

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

26
src/core.js

@ -209,9 +209,7 @@ c3_chart_internal_fn.initWithData = function (data) {
.attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE.
// Regions
main.append('g')
.attr("clip-path", $$.clipPath)
.attr("class", CLASS[_regions]);
$$.initRegion();
// Grids
$$.initGrid();
@ -448,7 +446,7 @@ c3_chart_internal_fn.updateTargets = function (targets) {
c3_chart_internal_fn.redraw = function (options, transitions) {
var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config;
var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate;
var mainLine, mainArea, mainCircle, mainBar, mainText, eventRect, eventRectUpdate;
var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget;
var rectX, rectW;
var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend;
@ -565,15 +563,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$.redrawGrid(duration, withY);
// rect for regions
mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region])
.data(config[__regions]);
mainRegion.enter().append('g')
.attr('class', generateCall($$.classRegion, $$))
.append('rect')
.style("fill-opacity", 0);
mainRegion.exit().transition().duration(duration)
.style("opacity", 0)
.remove();
$$.redrawRegion(duration);
// bars
mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar])
@ -751,12 +741,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
.attr('y', yForText)
.style("fill", $$.color)
.style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$)));
transitions.push(mainRegion.selectAll('rect').transition()
.attr("x", generateCall($$.regionX, $$))
.attr("y", generateCall($$.regionY, $$))
.attr("width", generateCall($$.regionWidth, $$))
.attr("height", generateCall($$.regionHeight, $$))
.style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; }));
$$.addTransitionForRegion(transitions);
$$.addTransitionForGrid(transitions);
// Wait for end of transitions if called from flow API
@ -779,7 +764,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
wait = $$.generateWait();
var xgrid = $$.xgrid || d3.selectAll([]),
xgridLines = $$.xgridLines || d3.selectAll([]);
xgridLines = $$.xgridLines || d3.selectAll([]),
mainRegion = $$.mainRegion || d3.selectAll([]);
// remove head data after rendered
$$.data.targets.forEach(function (d) {

27
src/region.js

@ -1,3 +1,30 @@
c3_chart_internal_fn.initRegion = function () {
var $$ = this, CLASS = $$.CLASS;
$$.main.append('g')
.attr("clip-path", $$.clipPath)
.attr("class", CLASS[_regions]);
};
c3_chart_internal_fn.redrawRegion = function (duration) {
var $$ = this, config = $$.config, CLASS = $$.CLASS;
$$.mainRegion = $$.main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region])
.data(config[__regions]);
$$.mainRegion.enter().append('g')
.attr('class', generateCall($$.classRegion, $$))
.append('rect')
.style("fill-opacity", 0);
$$.mainRegion.exit().transition().duration(duration)
.style("opacity", 0)
.remove();
};
c3_chart_internal_fn.addTransitionForRegion = function (transitions) {
var $$ = this;
transitions.push($$.mainRegion.selectAll('rect').transition()
.attr("x", generateCall($$.regionX, $$))
.attr("y", generateCall($$.regionY, $$))
.attr("width", generateCall($$.regionWidth, $$))
.attr("height", generateCall($$.regionHeight, $$))
.style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; }));
};
c3_chart_internal_fn.regionX = function (d) {
var $$ = this, config = $$.config,
xPos, yScale = d.axis === 'y' ? $$.y : $$.y2;

Loading…
Cancel
Save