Browse Source

load: update json if provided

pull/1812/head
Tomas Tomecek 8 years ago
parent
commit
949a067c32
  1. 40
      spec/api.load-spec.js
  2. 4
      src/api.load.js

40
spec/api.load-spec.js

@ -118,4 +118,44 @@ describe('c3 api load', function () {
}); });
describe('reload data', function () {
it('should define chart via json', function () {
args = {
data: {
json: [
{x: 1, y: 2},
{x: 3, y: 1},
{x: 5, y: 3}
],
keys: {
value: ["x", "y"],
x: 'x',
},
},
};
expect(true).toBeTruthy();
});
describe('json property of config', function () {
it('should store the re-loaded json data', function (done) {
chart.load({
json: [
{x: 10, y: 20},
{x: 30, y: 10},
]
});
setTimeout(function () {
var json = chart.internal.config.data_json;
expect(json.length).toBe(2);
expect(json[0].x).toBe(10);
done();
}, 500);
});
});
});
}); });

4
src/api.load.js

@ -35,6 +35,10 @@ c3_chart_fn.load = function (args) {
$$.load($$.getCaches(args.cacheIds), args.done); $$.load($$.getCaches(args.cacheIds), args.done);
return; return;
} }
// update json if exists
if ('json' in args) {
config.data_json = args.json;
}
// unload if needed // unload if needed
if ('unload' in args) { if ('unload' in args) {
// TODO: do not unload if target will load (included in url/rows/columns) // TODO: do not unload if target will load (included in url/rows/columns)

Loading…
Cancel
Save