Skip to content

Commit

Permalink
๐Ÿ”ง fix: ์ฐจํŠธ ์ด๋™ํ‰๊ท ์„  ๊ด€๋ จ ์˜ค๋ฅ˜ ์ˆ˜์ • #192
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysir committed Nov 27, 2024
1 parent 5928f9b commit 7e33d69
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
2 changes: 1 addition & 1 deletion FE/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type StockChartUnit = {
acml_vol: string;
prdy_vrss_sign: string;
mov_avg_5: string;
mov_avg_20: string;
mov_avg_20?: string;
};

export type MypageSectionType = 'account' | 'order' | 'info';
Expand Down
28 changes: 20 additions & 8 deletions FE/src/utils/chart/drawCandleChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ export function drawCandleChart(
const n = data.length;

const values = data
.map((d) => [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
])
.map((d) => {
if (d.mov_avg_20) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
];
} else {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
];
}
})
.flat();
const yMax = Math.round(Math.max(...values) * (1 + weight));
const yMin = Math.round(Math.min(...values) * (1 - weight));
Expand Down
49 changes: 41 additions & 8 deletions FE/src/utils/chart/drawLineChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ export function drawLineChart(
const gap = Math.floor(width / n);

const values = data
.map((d) => [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
])
.map((d) => {
if (d.mov_avg_20) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
];
} else {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
];
}
})
.flat();
const yMax = Math.round(Math.max(...values) * (1 + weight));
const yMin = Math.round(Math.min(...values) * (1 - weight));
Expand All @@ -48,4 +60,25 @@ export function drawLineChart(
ctx.strokeStyle = '#000';
ctx.lineWidth = lineWidth;
ctx.stroke();

ctx.beginPath();
data.forEach((e, i) => {
if (e.mov_avg_20) {
const cx = x + padding.left + (width * i) / (n - 1) + gap / 2;
const cy =
y +
padding.top +
height -
(height * (+e.mov_avg_20 - yMin)) / (yMax - yMin);

if (i === 0) {
ctx.moveTo(cx, cy);
} else {
ctx.lineTo(cx, cy);
}
}
});
ctx.strokeStyle = '#199123';
ctx.lineWidth = lineWidth;
ctx.stroke();
}

0 comments on commit 7e33d69

Please sign in to comment.