From d20c68de8c39e044a6ca2eaef4ab127199be0088 Mon Sep 17 00:00:00 2001 From: Jae Sung Park Date: Thu, 1 Mar 2018 23:06:39 +0900 Subject: [PATCH] feat(core): Intent to ship instance property (#315) Implement a property of array containing instances generated in a page Fix #308 Close #315 --- spec/internals/bb-spec.js | 6 ++++++ src/core.js | 22 +++++++++++++++++++++- src/internals/ChartInternal.js | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spec/internals/bb-spec.js b/spec/internals/bb-spec.js index 19fe09b74..d7ecba0d0 100644 --- a/spec/internals/bb-spec.js +++ b/spec/internals/bb-spec.js @@ -27,6 +27,12 @@ describe("Interface & initialization", () => { expect(d3.select(chart.element).classed("bb")).to.be.true; expect(internal.svg.node().tagName).to.be.equal("svg"); expect(internal.convertInputType()).to.be.equal(internal.inputType); + + expect(chart).to.be.equal(bb.instance[0]); + }); + + it("should return version string", () => { + expect(bb.version.length > 0).to.be.ok; }); it("should resize correctly in flex container", done => { diff --git a/src/core.js b/src/core.js index de9d24738..ddea9f949 100644 --- a/src/core.js +++ b/src/core.js @@ -48,8 +48,28 @@ const bb = { * chart.data("data1"); */ generate(config) { - return new Chart(config); + const inst = new Chart(config); + + this.instance.push(inst); + + return inst; }, + /** + * An array containing instance created + * @property {Array} instance instance array + * @example + * // generate charts + * var chart1 = bb.generate(...); + * var chart2 = bb.generate(...); + * + * bb.instance; // [ chart1, chart2, ... ] + * @memberOf bb + */ + instance: [], + /** + * Internal chart object + * @private + */ chart: { fn: Chart.prototype, internal: { diff --git a/src/internals/ChartInternal.js b/src/internals/ChartInternal.js index 547e1427f..960c8ca10 100644 --- a/src/internals/ChartInternal.js +++ b/src/internals/ChartInternal.js @@ -1,6 +1,7 @@ /** * Copyright (c) 2017 NAVER Corp. * billboard.js project is licensed under the MIT license + * @ignore */ import { timeParse as d3TimeParse,