Commit 4fe2f2fb authored by Evgeny's avatar Evgeny

Speed up setValue and getValue

parent 6d8eaefa
c3_chart_fn.load = function (args) { c3_chart_fn.load = function (args) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
$$.config.turned = false;
// update xs if specified // update xs if specified
if (args.xs) { if (args.xs) {
$$.addXs(args.xs); $$.addXs(args.xs);
...@@ -87,33 +90,27 @@ c3_chart_fn.loadColumns = function(cols){ ...@@ -87,33 +90,27 @@ c3_chart_fn.loadColumns = function(cols){
c3_chart_fn.setValue = function(id, i, value){ c3_chart_fn.setValue = function(id, i, value){
var $$ = this.internal; var $$ = this.internal;
var column = $$.api.getDataById(id); var t = $$.api.data(id)[0];
if(isUndefined(column)){
throw new Error("Setting value to non-existing sequence " + id);
}
if(isUndefined(column[i])){ if(!t.values[i]){
$$.api.appendToColumn([id, value]); $$.api.appendToColumn([id, value]);
} else { } else {
column[i] = value; t.values[i].value = value;
$$.api.loadColumns([[id].concat(column)]); $$.tuneAxis();
} }
}; };
c3_chart_fn.getValue = function(id, i){ c3_chart_fn.getValue = function(id, i){
var $$ = this.internal; var $$ = this.internal;
var column = $$.api.getDataById(id); var t = $$.api.data(id)[0];
if(isUndefined(column)){
if(!t){
return undefined; return undefined;
} }
if(!t.values[i]){
var v = column[i];
if(isUndefined(v)){
return undefined; return undefined;
} }
return t.values[i].value;
return v.value;
}; };
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