Skip to content

Commit

Permalink
[#1299] Chart > Indicator 인디케이터의 dataIndex가 0일 때 위치가 정확하지 않음
Browse files Browse the repository at this point in the history
#########################################
[원인]
 - gdata의 0, 1 인덱스 요소가 없을 때 xp 프로퍼티를 찾지 못하게 되고 타입에러가 발생하게 됨.

[수정 내용]
 - gdata에 1개 이상 데이터 있을 경우 findGraphData 함수 내부 로직 실행.
 - gdata의 원소가 1개 뿐이여서 xp 간 간격을 계산 할 수 없을 경우 undefined - xp < 6 은 false로 기존 값인 6을 가지고 내부 로직이 실행 되도록 수정.
  • Loading branch information
Mun94 committed Oct 25, 2022
1 parent 9741372 commit 322cef8
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/components/chart/element/element.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,28 +243,30 @@ class Line {
const item = { data: null, hit: false, color: this.color };
const gdata = this.data;

let s = 0;
let e = gdata.length - 1;
if (gdata.length) {
let s = 0;
let e = gdata.length - 1;

const xpInterval = gdata[1].xp - gdata[0].xp < 6 ? 1.5 : 6;
const xpInterval = gdata[1]?.xp - gdata[0].xp < 6 ? 1.5 : 6;

while (s <= e) {
const m = Math.floor((s + e) / 2);
const x = gdata[m].xp;
const y = gdata[m].yp;
while (s <= e) {
const m = Math.floor((s + e) / 2);
const x = gdata[m].xp;
const y = gdata[m].yp;

if ((x - xpInterval < xp) && (xp < x + xpInterval)) {
item.data = gdata[m];
item.index = m;
if ((x - xpInterval < xp) && (xp < x + xpInterval)) {
item.data = gdata[m];
item.index = m;

if ((y - 6 <= yp) && (yp <= y + 6)) {
item.hit = true;
if ((y - 6 <= yp) && (yp <= y + 6)) {
item.hit = true;
}
return item;
} else if (x + xpInterval > xp) {
e = m - 1;
} else {
s = m + 1;
}
return item;
} else if (x + xpInterval > xp) {
e = m - 1;
} else {
s = m + 1;
}
}

Expand Down

0 comments on commit 322cef8

Please sign in to comment.