Commit 065df8be authored by Evgeny's avatar Evgeny

Add normalized functionality

parent 0884c496
......@@ -394,9 +394,10 @@ c3_chart_internal_fn.updateSizes = function () {
}
};
c3_chart_internal_fn.updateTargets = function (targets) {
c3_chart_internal_fn.updateTargets = function (t){
var $$ = this;
var targets = $$.normalize(t);
/*-- Main --*/
//-- Text --//
......@@ -496,8 +497,6 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$.y2Axis.tickValues($$.generateTickValues($$.y2.domain(), config.axis_y2_tick_count));
}
$$.normalize();
// axes
$$.redrawAxis(transitions, hideAxis);
......
c3.chart.internal.fn.normalize = function(){
var $$ = this, tr = [], c = [],
data = $$.api.data();
c3.chart.internal.fn.normalize = function(targets){
var $$ = this, tr = [], c = [];
if(!$$.config.normalized){
return;
if(!$$.config.normalized || isUndefined(targets)){
return targets;
}
for(var k = 0; k < data[0].values.length; k++) {
var data = copyArray(targets);
for(var k = 0; k < targets[0].values.length; k++) {
var tt = 0;
for(c in data) {
tt = tt + data[c].values[k].value;
for(c in targets) {
tt = tt + targets[c].values[k].value;
}
tr[k] = tt;
}
for(c in data) {
for(c in targets) {
for(k = 0; k < tr.length; k++) {
data[c].values[k].value = data[c].values[k].value / tr[k];
data[c].values[k].value = targets[c].values[k].value / tr[k];
}
}
return data;
}
......@@ -63,7 +63,15 @@ var isValue = c3_chart_internal_fn.isValue = function (v) {
var newObj = {};
for(var key in oldObj){
if(oldObj.hasOwnProperty(key)){
newObj[key] = oldObj[key];
if(typeof oldObj[key] === 'object'){
newObj[key] = copyObject(oldObj[key]);
} else if(Array.isArray(oldObj[key])){
newObj[key] = copyArray(oldObj[key]);
} else if(typeof oldObj[key] === 'function'){
newObj[key] = oldObj[key].bind(newObj);
} else {
newObj[key] = oldObj[key];
}
}
}
return newObj;
......
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