From 949a067c321e868b564e5186ed8711a0a172454b Mon Sep 17 00:00:00 2001 From: Tomas Tomecek Date: Thu, 18 Aug 2016 10:41:53 +0200 Subject: [PATCH] load: update json if provided --- spec/api.load-spec.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/api.load.js | 4 ++++ 2 files changed, 44 insertions(+) diff --git a/spec/api.load-spec.js b/spec/api.load-spec.js index fbea981..f63da15 100644 --- a/spec/api.load-spec.js +++ b/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); + }); + + }); + + }); + }); diff --git a/src/api.load.js b/src/api.load.js index b2f0272..364b413 100644 --- a/src/api.load.js +++ b/src/api.load.js @@ -35,6 +35,10 @@ c3_chart_fn.load = function (args) { $$.load($$.getCaches(args.cacheIds), args.done); return; } + // update json if exists + if ('json' in args) { + config.data_json = args.json; + } // unload if needed if ('unload' in args) { // TODO: do not unload if target will load (included in url/rows/columns)