Skip to content

Commit

Permalink
[#1103] Pie Chart > 브라우저 확대/축소 시 Tooltip 버그 발생
Browse files Browse the repository at this point in the history
###################################
1. isPointInPath 함수 직접 구현으로 변경
  • Loading branch information
jhee564 committed Mar 23, 2022
1 parent 3c90720 commit f36094e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/components/chart/element/element.pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Pie {
this.doughnutHoleSize = 0;
this.startAngle = 0;
this.endAngle = 0;
this.slice = null;
this.state = null;
this.ctx = null;
this.isSelect = false;
Expand Down Expand Up @@ -71,8 +70,6 @@ class Pie {
}

ctx.closePath();

this.slice = slice;
this.ctx = ctx;
}

Expand All @@ -84,8 +81,19 @@ class Pie {
*/
findGraphData([offsetX, offsetY]) {
const item = { data: null, hit: false, color: null, index: -1 };

if (this.show && this.ctx?.isPointInPath(this.slice, offsetX, offsetY)) {
const {
radius,
startAngle,
endAngle,
centerX,
centerY,
} = this;

const distance = Math.sqrt((offsetX - centerX) ** 2 + (offsetY - centerY) ** 2);
const radian = (2.5 * Math.PI) - Math.atan2((offsetX - centerX), (offsetY - centerY));
const isPointInPath = radius > distance && radian >= startAngle && radian <= endAngle;

if (this.show && isPointInPath) {
item.type = this.type;
item.data = this.data;
item.hit = true;
Expand Down

0 comments on commit f36094e

Please sign in to comment.