Add support for negative values for stacked-100

parent 1a9b8452
...@@ -381,9 +381,11 @@ c3_chart_internal_fn.tuneAxis = function(sync, callback){ ...@@ -381,9 +381,11 @@ c3_chart_internal_fn.tuneAxis = function(sync, callback){
// if we don't need to tune // if we don't need to tune
if($$.config.normalized){ if($$.config.normalized){
$$.data.targets = $$.normalize($$.data._targets); $$.data.targets = $$.normalize($$.data._targets);
if($$.data.targets.noNegative){
$$.cachedRedraw(); $$.cachedRedraw();
return; return;
} }
}
var apply = function(){ var apply = function(){
......
...@@ -7,6 +7,8 @@ c3.chart.internal.fn.normalize = function(targets){ ...@@ -7,6 +7,8 @@ c3.chart.internal.fn.normalize = function(targets){
var data = []; var data = [];
data.noNegative = true;
targets.forEach(function(target){ targets.forEach(function(target){
data.push($$.cloneTarget(target)); data.push($$.cloneTarget(target));
}); });
...@@ -14,7 +16,12 @@ c3.chart.internal.fn.normalize = function(targets){ ...@@ -14,7 +16,12 @@ c3.chart.internal.fn.normalize = function(targets){
for(var k = 0; k < targets[0].values.length; k++) { for(var k = 0; k < targets[0].values.length; k++) {
var tt = 0; var tt = 0;
for(c in targets) { for(c in targets) {
tt = tt + targets[c].values[k].value; if(targets[c].values[k]){
if(targets[c].values[k].value < 0){
data.noNegative = false;
}
tt = tt + Math.abs(targets[c].values[k].value);
}
} }
tr[k] = tt; tr[k] = tt;
} }
......
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