Skip to content

Commit

Permalink
πŸ”§ fix: 이동 평균 κ΄€λ ¨ 였λ₯˜ μˆ˜μ • #192
Browse files Browse the repository at this point in the history
μ΄λ™νŽΈκ· μ„  5 λ˜ν•œ 없을 수 있기 λ•Œλ¬Έμ— 쑰건 μˆ˜μ •.
  • Loading branch information
dannysir committed Nov 27, 2024
1 parent 7e33d69 commit 0fc4cfe
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
2 changes: 1 addition & 1 deletion FE/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type StockChartUnit = {
stck_lwpr: string;
acml_vol: string;
prdy_vrss_sign: string;
mov_avg_5: string;
mov_avg_5?: string;
mov_avg_20?: string;
};

Expand Down
14 changes: 12 additions & 2 deletions FE/src/utils/chart/drawCandleChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function drawCandleChart(

const values = data
.map((d) => {
if (d.mov_avg_20) {
if (d.mov_avg_20 && d.mov_avg_5) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
Expand All @@ -23,14 +23,24 @@ export function drawCandleChart(
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
];
} else {
} else if (d.mov_avg_5) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
];
} else if (d.mov_avg_20) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_20),
];
} else {
return [+d.stck_hgpr, +d.stck_lwpr, +d.stck_clpr, +d.stck_oprc];
}
})
.flat();
Expand Down
36 changes: 24 additions & 12 deletions FE/src/utils/chart/drawLineChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function drawLineChart(

const values = data
.map((d) => {
if (d.mov_avg_20) {
if (d.mov_avg_20 && d.mov_avg_5) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
Expand All @@ -29,32 +29,44 @@ export function drawLineChart(
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
];
} else {
} else if (d.mov_avg_5) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
];
} else if (d.mov_avg_20) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_20),
];
} else {
return [+d.stck_hgpr, +d.stck_lwpr, +d.stck_clpr, +d.stck_oprc];
}
})
.flat();
const yMax = Math.round(Math.max(...values) * (1 + weight));
const yMin = Math.round(Math.min(...values) * (1 - weight));

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

if (i === 0) {
ctx.moveTo(cx, cy);
} else {
ctx.lineTo(cx, cy);
if (i === 0) {
ctx.moveTo(cx, cy);
} else {
ctx.lineTo(cx, cy);
}
}
});
ctx.strokeStyle = '#000';
Expand Down
38 changes: 30 additions & 8 deletions FE/src/utils/chart/drawUpperYAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,36 @@ export const drawUpperYAxis = (
upperChartHeight: number,
) => {
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 && d.mov_avg_5) {
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 if (d.mov_avg_5) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
];
} else if (d.mov_avg_20) {
return [
+d.stck_hgpr,
+d.stck_lwpr,
+d.stck_clpr,
+d.stck_oprc,
Math.floor(+d.mov_avg_20),
];
} else {
return [+d.stck_hgpr, +d.stck_lwpr, +d.stck_clpr, +d.stck_oprc];
}
})
.flat();
const yMax = Math.round(Math.max(...values) * (1 + weight));
const yMin = Math.round(Math.min(...values) * (1 - weight));
Expand Down

0 comments on commit 0fc4cfe

Please sign in to comment.