Skip to content

Commit

Permalink
fix(event): Fix handling for single x Axis data
Browse files Browse the repository at this point in the history
- Add prevention condition when handling single x Axis event data
- Update the event reference for touch environment

Fix #1737
  • Loading branch information
netil authored Oct 23, 2020
1 parent 95817a9 commit 84eaa6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/ChartInternal/interactions/eventrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,12 @@ export default {
bindTouchOnEventRect(isMultipleX: boolean): void {
const $$ = this;
const {config, state, $el: {eventRect, svg}} = $$;
const event = d3Event;

const selectRect = context => {
if (isMultipleX) {
$$.selectRectForMultipleXs(context);
} else {
// const eventRect = getEventRect();
// const index = getIndex(eventRect);
const index = $$.getDataIndexFromEvent(event);
const index = $$.getDataIndexFromEvent(d3Event);

$$.callOverOutForTouch(index);

Expand Down Expand Up @@ -442,7 +439,7 @@ export default {
const $$ = ctx;
const {config, state, $el: {main}} = $$;

if ($$.hasArcType() || state.cancelClick) {
if (!d || $$.hasArcType() || state.cancelClick) {
state.cancelClick && (state.cancelClick = false);

return;
Expand Down
18 changes: 14 additions & 4 deletions test/esm/bar-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe("ESM bar", function() {
const args: any = {
data: {
columns: [
["data1", 300, 350, 300, 0, 100],
["data2", 130, 100, 140, 200, 150]
["data1", 30, 350, 300, 0, 100],
["data2", 200, 100, 140, 200, 150]
],
type: bar(),
onclick: spy
Expand All @@ -35,8 +35,8 @@ describe("ESM bar", function() {
const pos = getBBox(bar);

fireEvent(eventRect.node(), "click", {
clientX: pos.x + 20,
clientY: pos.y + 50
clientX: pos.x + 10,
clientY: pos.y
}, chart);

expect(spy.calledOnce).to.be.true;
Expand All @@ -53,4 +53,14 @@ describe("ESM bar", function() {

expect(true).to.be.ok;
});

it("check data.onclick for bar type", () => {
try {
chart.internal.clickHandlerForSingleX(undefined, chart.internal);
} catch(e) {
expect(false).to.be.true;
}

expect(true).to.be.true;
});
});

0 comments on commit 84eaa6b

Please sign in to comment.