Skip to content

Commit

Permalink
feat(interaction): avoid multiple <rect> generation
Browse files Browse the repository at this point in the history
- Enhance on event handling by mitigating event <rect> element
- Do not re-generate and re-bind events when redraw happens

Fix #1642
  • Loading branch information
netil committed Sep 4, 2020
1 parent 47ede7e commit 97df63a
Show file tree
Hide file tree
Showing 24 changed files with 448 additions and 322 deletions.
4 changes: 3 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,9 @@ d3.select(".chart_area")
}
},
point: {
show: false
focus: {
only: true
}
}
},
style: [
Expand Down
1 change: 0 additions & 1 deletion src/Chart/api/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const tooltip = {
index = args.index;
}

// emulate events to show
(inputType === "mouse" ?
["mouseover", "mousemove"] : ["touchstart"]
).forEach(eventName => {
Expand Down
24 changes: 24 additions & 0 deletions src/ChartInternal/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import CLASS from "../../config/classes";
import {KEY} from "../../module/Cache";
import {
findIndex,
getUnique,
hasValue,
isArray,
Expand Down Expand Up @@ -608,6 +609,29 @@ export default {
(isObjectType(dataLabels) && notEmpty(dataLabels));
},

/**
* Get data index from the event coodinates
* @param {Event} event Event object
* @returns {number}
*/
getDataIndexFromEvent(event): number {
const $$ = this;
const {config, state: {inputType, eventReceiver: {coords, rect}}} = $$;
const isRotated = config.axis_rotated;

// get data based on the mouse coords
const e = inputType === "touch" ? event.changedTouches[0] : event;
const index = findIndex(
coords,
isRotated ? e.clientY - rect.y : e.clientX - rect.x,
0,
coords.length - 1,
isRotated
);

return index;
},

getDataLabelLength(min, max, key) {
const $$ = this;
const lengths = [0, 0];
Expand Down

0 comments on commit 97df63a

Please sign in to comment.