Skip to content

Commit

Permalink
[#1299] Chart > Indicator 인디케이터의 dataIndex가 0일 때 위치가 정확하지 않음
Browse files Browse the repository at this point in the history
#####################################################
[원인]
 - SelectedLabel 데이터 많을 때 정확하게 0번째 위치에 인디케이터가 생기지 않는데 데이터가 많아서 그래프의 포인트간 간격이 6 이하일 때 원하는 차트의 날짜에 클릭했을 때 정확하게 인디케이터가 생성 되지 않음.

[수정 내용]
 - 차트 포인트 간격이 6 미만일 때 데이터간 간격의 최소 값인 1.5로 계산하여 데이터 값의 x - 1.5 < 클릭한 차트의 xp 위치 && xp < x + 1.5로 오차 범위를 최소화 함.
  • Loading branch information
Mun94 committed Oct 20, 2022
1 parent 70147e2 commit 6af211a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/views/brushChart/example/SelectLabelGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default {
selectLabel: {
use: true,
useClick: true,
limit: 3,
limit: 2,
useDeselectOverflow: true,
useApproximateValue: true,
tipBackground: '#FF0000',
Expand Down Expand Up @@ -122,7 +122,7 @@ export default {
});
const defaultGroupSelectLabel = ref({
dataIndex: [1, 3, 7],
dataIndex: [0, 100],
});
const clickedLabel = ref("''");
Expand Down Expand Up @@ -152,7 +152,7 @@ export default {
};
onMounted(() => {
for (let ix = 0; ix < 10; ix++) {
for (let ix = 0; ix < 500; ix++) {
addRandomChartData();
}
});
Expand Down
10 changes: 6 additions & 4 deletions src/components/chart/element/element.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,25 @@ class Line {
let s = 0;
let e = gdata.length - 1;

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;

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/components/chart/scale/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class Scale {

if (this.type === 'x') {
labelPoint = this.position === 'top' ? offsetPoint - 10 : offsetPoint + 10;
if (options?.brush?.showLabel || !options.brush) {
if (options?.brush?.showLabel || !options?.brush) {
ctx.fillText(labelText, labelCenter, labelPoint);
}

Expand Down Expand Up @@ -344,7 +344,7 @@ class Scale {
}
} else {
labelPoint = this.position === 'left' ? offsetPoint - 10 : offsetPoint + 10;
if (options?.brush?.showLabel || !options.brush) {
if (options?.brush?.showLabel || !options?.brush) {
ctx.fillText(labelText, labelPoint, labelCenter);
}

Expand Down

0 comments on commit 6af211a

Please sign in to comment.