From 64cd68e841f49390c8072c4d6635722549192313 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 10 May 2013 13:10:38 +0900 Subject: [PATCH] Fix load for bar --- c3.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/c3.js b/c3.js index 814e930..a9ef22c 100644 --- a/c3.js +++ b/c3.js @@ -340,7 +340,7 @@ } function convertDataToTargets (data) { var ids = d3.keys(data[0]).filter(function(key){ return key !== __data_x }) - var targets, i = 0 + var targets, currentTargetsNum = getTargetsNum(), i = 0 data.forEach(function(d) { d.x = (isTimeSeries) ? parseDate(d[__data_x]) : i++ @@ -354,7 +354,7 @@ id : convertedId, id_org : id, values : data.map(function(d) { - return {x: d.x, value: +d[id], id: convertedId, i: i} + return {x: d.x, value: +d[id], id: convertedId, i: currentTargetsNum + i} }) } }) @@ -377,7 +377,8 @@ return false } function getTargetsNum (filter) { - return typeof filter !== 'undefined' ? c3.data.targets.filter(isBarType).length : c3.data.targets.length; + if (typeof c3.data.targets === 'undefined') return 0 + return typeof filter !== 'undefined' ? c3.data.targets.filter(filter).length : c3.data.targets.length; } function getBarTargetIndices () { var indices = [] @@ -1056,6 +1057,17 @@ .attr("cx", function(d) { return x(d.x) }) .attr("cy", function(d) { return y(d.value) }) + main.selectAll(".target-bars") + .data(targets) + .filter(isBarType) + .selectAll('rect') + .data(function(d) { return d.values }) + .transition() + .attr("x", barX) + .attr("y", function(d){ return y(d.value) }) + .attr("width", barWidth) + .attr("height", function(d){ return height-y(d.value) }) + /*-- Context --*/ if (__subchart_show) { @@ -1097,6 +1109,17 @@ .filter(isLineType) .transition() .attr("d", function (d) { return line2(d.values) }) + + context.selectAll(".target-bars") + .data(targets) + .filter(isBarType) + .selectAll('rect') + .data(function(d) { return d.values }) + .transition() + .attr("x", barX) + .attr("y", function(d){ return y2(d.value) }) + .attr("width", bar2Width) + .attr("height", function(d){ return height2-y2(d.value) }) } /*-- Legend --*/