Commit f0a80a45 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Add classes param on load API - #117

parent f1b08788
...@@ -1587,6 +1587,10 @@ ...@@ -1587,6 +1587,10 @@
} }
return generateClass(CLASS.target, id) + additionalClass; return generateClass(CLASS.target, id) + additionalClass;
} }
function classChartText(d) { return CLASS.chartText + classTarget(d.id); }
function classChartLine(d) { return CLASS.chartLine + classTarget(d.id); }
function classChartBar(d) { return CLASS.chartBar + classTarget(d.id); }
function classChartArc(d) { return CLASS.chartArc + classTarget(d.data.id); }
function getTargetSelectorSuffix(targetId) { function getTargetSelectorSuffix(targetId) {
return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : '';
...@@ -3451,22 +3455,22 @@ ...@@ -3451,22 +3455,22 @@
/*-- Main --*/ /*-- Main --*/
//-- Text --// //-- Text --//
mainTextUpdate = main.select('.' + CLASS.chartTexts) mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText)
.selectAll('.' + CLASS.chartText) .data(targets)
.data(targets); .attr('class', classChartText);
mainTextEnter = mainTextUpdate.enter().append('g') mainTextEnter = mainTextUpdate.enter().append('g')
.attr('class', function (d) { return CLASS.chartText + classTarget(d.id); }) .attr('class', classChartText)
.style("pointer-events", "none"); .style("pointer-events", "none");
mainTextEnter.append('g') mainTextEnter.append('g')
.attr('class', classTexts) .attr('class', classTexts)
.style("fill", function (d) { return color(d); }); .style("fill", function (d) { return color(d); });
//-- Bar --// //-- Bar --//
mainBarUpdate = main.select('.' + CLASS.chartBars) mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar)
.selectAll('.' + CLASS.chartBar) .data(targets)
.data(targets); .attr('class', classChartBar);
mainBarEnter = mainBarUpdate.enter().append('g') mainBarEnter = mainBarUpdate.enter().append('g')
.attr('class', function (d) { return CLASS.chartBar + classTarget(d.id); }) .attr('class', classChartBar)
.style("pointer-events", "none"); .style("pointer-events", "none");
// Bars for each data // Bars for each data
mainBarEnter.append('g') mainBarEnter.append('g')
...@@ -3478,9 +3482,10 @@ ...@@ -3478,9 +3482,10 @@
//-- Line --// //-- Line --//
mainLineUpdate = main.select('.' + CLASS.chartLines) mainLineUpdate = main.select('.' + CLASS.chartLines)
.selectAll('.' + CLASS.chartLine) .selectAll('.' + CLASS.chartLine)
.data(targets); .data(targets)
.attr('class', classChartLine);
mainLineEnter = mainLineUpdate.enter().append('g') mainLineEnter = mainLineUpdate.enter().append('g')
.attr('class', function (d) { return CLASS.chartLine + classTarget(d.id); }) .attr('class', classChartLine)
.style("pointer-events", "none"); .style("pointer-events", "none");
// Lines for each data // Lines for each data
mainLineEnter.append("path") mainLineEnter.append("path")
...@@ -3509,11 +3514,11 @@ ...@@ -3509,11 +3514,11 @@
//mainLineUpdate.exit().remove(); //mainLineUpdate.exit().remove();
//-- Pie --// //-- Pie --//
mainPieUpdate = main.select('.' + CLASS.chartArcs) mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc)
.selectAll('.' + CLASS.chartArc) .data(pie(targets))
.data(pie(targets)); .attr("class", classChartArc);
mainPieEnter = mainPieUpdate.enter().append("g") mainPieEnter = mainPieUpdate.enter().append("g")
.attr("class", function (d) { return CLASS.chartArc + classTarget(d.data.id); }); .attr("class", classChartArc);
mainPieEnter.append("path") mainPieEnter.append("path")
.attr("class", classArc) .attr("class", classArc)
.style("opacity", 0) .style("opacity", 0)
...@@ -3553,22 +3558,22 @@ ...@@ -3553,22 +3558,22 @@
if (__subchart_show) { if (__subchart_show) {
contextBarUpdate = context.select('.' + CLASS.chartBars) contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar)
.selectAll('.' + CLASS.chartBar) .data(targets)
.data(targets); .attr('class', classChartBar);
contextBarEnter = contextBarUpdate.enter().append('g') contextBarEnter = contextBarUpdate.enter().append('g')
.attr('class', function (d) { return CLASS.chartBar + classTarget(d.id); }); .attr('class', classChartBar);
// Bars for each data // Bars for each data
contextBarEnter.append('g') contextBarEnter.append('g')
.attr("class", classBars) .attr("class", classBars)
.style("fill", function (d) { return color(d); }); .style("fill", function (d) { return color(d); });
//-- Line --// //-- Line --//
contextLineUpdate = context.select('.' + CLASS.chartLines) contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine)
.selectAll('.' + CLASS.chartLine) .data(targets)
.data(targets); .attr('class', classChartLine);
contextLineEnter = contextLineUpdate.enter().append('g') contextLineEnter = contextLineUpdate.enter().append('g')
.attr('class', function (d) { return CLASS.chartLine + classTarget(d.id); }); .attr('class', classChartLine);
// Lines for each data // Lines for each data
contextLineEnter.append("path") contextLineEnter.append("path")
.attr("class", classLine) .attr("class", classLine)
...@@ -3966,6 +3971,12 @@ ...@@ -3966,6 +3971,12 @@
if (args.xs) { if (args.xs) {
addXs(args.xs); addXs(args.xs);
} }
// update classes if exists
if ('classes' in args) {
Object.keys(args.classes).forEach(function (id) {
__data_classes[id] = args.classes[id];
});
}
// update categories if exists // update categories if exists
if ('categories' in args && isCategorized) { if ('categories' in args && isCategorized) {
__axis_x_categories = args.categories; __axis_x_categories = args.categories;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment