-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bar): Fix not firing data.onclick
- Add conditional to check when only 'bar' named binding is imported. - Add test codes for ESM Fix #1619 Ref #1620
- Loading branch information
Showing
4 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2017 ~ present NAVER Corp. | ||
* billboard.js project is licensed under the MIT license | ||
*/ | ||
/* eslint-disable */ | ||
/* global describe, beforeEach, it, expect */ | ||
import {expect} from "chai"; | ||
import sinon from "sinon"; | ||
import bb, {bar} from "../../src/index.esm"; | ||
import util from "../assets/util"; | ||
import CLASS from "../../src/config/classes"; | ||
|
||
describe("ESM bar", function() { | ||
let chart; | ||
const spy = sinon.spy(); | ||
const args: any = { | ||
data: { | ||
columns: [ | ||
["data1", 300, 350, 300, 0, 100], | ||
["data2", 130, 100, 140, 200, 150] | ||
], | ||
type: bar(), | ||
onclick: spy | ||
} | ||
}; | ||
|
||
beforeEach(() => { | ||
chart = bb.generate(args); | ||
}); | ||
|
||
it("check data.onclick for bar type", () => { | ||
const rect = chart.$.main.select(`.${CLASS.eventRect}.${CLASS.eventRect}-0`).node(); | ||
const bar = chart.$.bar.bars.nodes()[0]; | ||
const pos = util.getBBox(bar); | ||
|
||
util.fireEvent(rect, "click", { | ||
clientX: pos.x + 20, | ||
clientY: pos.y + 50 | ||
}, chart); | ||
|
||
expect(spy.calledOnce).to.be.true; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2017 ~ present NAVER Corp. | ||
* billboard.js project is licensed under the MIT license | ||
*/ | ||
/* eslint-disable */ | ||
/* global describe, beforeEach, it, expect */ | ||
import {expect} from "chai"; | ||
import * as bb from "../../src/index.esm"; | ||
import CLASS from "../../src/config/classes"; | ||
|
||
describe("ESM build", function() { | ||
let chart; | ||
|
||
const data = [ | ||
["data1", 300, 350, 300, 0, 100], | ||
["data2", 130, 100, 140, 200, 150] | ||
]; | ||
|
||
const rangeData = [ | ||
["data1", | ||
[150, 140, 110], | ||
[155, 130, 115], | ||
[160, 135, 120], | ||
[135, 120, 110], | ||
[180, 150, 130] | ||
] | ||
]; | ||
|
||
let args: any = { | ||
data: { | ||
columns: data | ||
} | ||
}; | ||
|
||
it("should generate each chart types", () => { | ||
Object.keys(bb) | ||
.filter(v => !/(bb|default|selection|subchart|zoom)/.test(v)) | ||
.forEach(v => { | ||
let path; | ||
|
||
// initialize type | ||
args.data.type = bb[v](); | ||
|
||
if (/(area|line|step)/.test(v)) { | ||
args.data.columns = /Range/.test(v) ? rangeData: data; | ||
|
||
chart = bb.bb.generate(args); | ||
path = chart.$.line.lines.attr("d"); | ||
|
||
} else { | ||
chart = bb.bb.generate(args); | ||
|
||
if (v === "bar") { | ||
path = chart.$.bar.bars.attr("d"); | ||
|
||
} else if (v === "radar") { | ||
path = chart.$.main | ||
.select(`.${CLASS.chartRadar} polygon`) | ||
.attr("points"); | ||
|
||
} else if (v === "scatter") { | ||
const dataLength: any = data.reduce((a: any, r: any) => a.length + r.length); | ||
|
||
expect(chart.$.circles.nodes().length).to.be.equal(dataLength - 2); | ||
|
||
} else { | ||
// donut, gauge, pie | ||
path = chart.$.arc.selectAll("path").attr("d"); | ||
} | ||
} | ||
|
||
path && expect(/NaN/.test(path)).to.be.false; | ||
}); | ||
}); | ||
}); |