Skip to content

Commit

Permalink
feat(core): Intent to ship instance property (#315)
Browse files Browse the repository at this point in the history
Implement a property of array containing instances generated in a page

Fix #308
Close #315
  • Loading branch information
netil committed Mar 1, 2018
1 parent c11a215 commit d20c68d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/internals/bb-spec.js
Expand Up @@ -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 => {
Expand Down
22 changes: 21 additions & 1 deletion src/core.js
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions 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,
Expand Down

0 comments on commit d20c68d

Please sign in to comment.