Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨feat, 🎨design: 차트 μ»΄ν¬λ„ŒνŠΈ 생성(일반 차트, 주식 차트 λ“±) #63

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"@reduxjs/toolkit": "^2.2.5",
"apexcharts": "^3.49.1",
"axios": "^1.7.2",
"chart.js": "^4.4.3",
"react": "^18.2.0",
"react-apexcharts": "^1.4.1",
"react-chartjs-2": "^5.2.0",
"bootstrap": "^5.3.3",
"bootstrap-icons": "^1.11.3",
"react": "^18.2.0",
Expand Down
112 changes: 112 additions & 0 deletions src/components/common/StockInfoDetail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React from "react";
import { StyledInfoDetailDiv } from "./StockInfoDetail.style";
const SeiseInfo = ({ details }) => (
<StyledInfoDetailDiv>
<h3>μ‹œμ„Έμ •λ³΄</h3>
<div>
<p>μ‹œκ°€</p>
<p>{details.openingPrice}</p>
</div>
<div>
<p>1λ…„ 졜고</p> <p>{details.oneYearHigh}</p>
</div>
<div>
<p>1λ…„ μ΅œμ €</p> <p>{details.oneYearLow}</p>
</div>
</StyledInfoDetailDiv>
);

const StockInfo = ({ details }) => (
<StyledInfoDetailDiv>
<h3>μ’…λͺ©μ •λ³΄</h3>
<div>
<p>μ‹œμ΄</p> <p>{details.marketcome}</p>
</div>
<div>
<p>κ±°λž˜λŸ‰</p> <p>{details.tradingVolume}</p>
</div>
</StyledInfoDetailDiv>
);

const InvestorTrade = ({ details }) => (
<StyledInfoDetailDiv>
<h3>νˆ¬μžμžλ³„ 맀맀동ν–₯ 24.06.19</h3>
<div>
<p>μ™Έκ΅­μΈλ³΄μœ μœ¨</p> <p>{details.foreignOwnershipRate}</p>
</div>
<div>
<p>μ™Έκ΅­μΈλ§€λ§€μœ¨</p>
<p> {details.foreignTrade}</p>
</div>
<div>
<p>κΈ°κ΄€λ§€λ§€μœ¨</p>
<p>{details.institutionalTrade}</p>
</div>
</StyledInfoDetailDiv>
);

const QuarterResult = ({ details }) => (
<StyledInfoDetailDiv>
<h3>뢄기싀적 2024.03.</h3>
<p>λ§€μΆœμ•‘: {details.revenue}</p>
<p>μ˜μ—…μ΄μ΅: {details.operatingIncome}</p>
<p>λ‹ΉκΈ°μˆœμ΄μ΅: {details.netIncome}</p>
</StyledInfoDetailDiv>
);

const StockDataComponent = ({ data }) => {
switch (data.section) {
case "μ‹œμ„Έμ •λ³΄":
return <SeiseInfo details={data.details} />;
case "μ’…λͺ©μ •λ³΄":
return <StockInfo details={data.details} />;
case "νˆ¬μžμžλ³„ 맀맀동ν–₯ 24.06.19":
return <InvestorTrade details={data.details} />;
case "뢄기싀적 2024.03.":
return <QuarterResult details={data.details} />;
default:
return <div>μ•Œ 수 μ—†λŠ” 데이터</div>;
}
};

// Sample data based on your structure
const stockData = [
{
section: "μ‹œμ„Έμ •λ³΄",
details: {
openingPrice: "678,000",
oneYearHigh: "718,000",
oneYearLow: "103,100",
},
},
{
section: "μ’…λͺ©μ •λ³΄",
details: { marketcome: "4μ‘° 8,211μ–΅", tradingVolume: "193,195" },
},
{
section: "νˆ¬μžμžλ³„ 맀맀동ν–₯ 24.06.19",
details: {
foreignOwnershipRate: "12.90%",
foreignTrade: "-51,338",
institutionalTrade: "-12,688",
},
},
{
section: "뢄기싀적 2024.03.",
details: {
revenue: "3,857μ–΅",
operatingIncome: "801μ–΅",
netIncome: "665μ–΅",
},
},
];

const StockInfoDetail = () => (
<div style={{ display: "flex", flexDirection: "row", gap: "5px" }}>
{stockData.map((data, index) => (
<StockDataComponent key={index} data={data} />
))}
</div>
);

export default StockInfoDetail;
25 changes: 25 additions & 0 deletions src/components/common/StockInfoDetail.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styled from "styled-components";

export const StyledInfoDetailDiv = styled.div`
width: 25%;
ascpect-ratio: 1/1;
background-color: lightgray;
border-radius: 10px;
color: black;
padding: 10px;
h3 {
font-size: 18px;
}
div {
display: flex;
flex-direction: row;
}
div p:first-child {
color: gray;
width: 30%;
}
span {
font-weight: normal;
color: gray;
}
`;
13 changes: 7 additions & 6 deletions src/components/common/graphs/normalGraph/NormalGraph.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useRef } from "react";
import { ReactP5Wrapper } from "react-p5-wrapper";
import styled from "styled-components";

// import p5 from "p5";
// window.p5 = p5;
const ChartContainer = styled.div`
background: #fff;
padding: 10px;
Expand Down Expand Up @@ -46,7 +47,7 @@ const sketch = (p5) => {
barIndex = 0;
isAnimating = true;
axisProgress = 0;
console.log(props);
// console.log(props);
}
if (props.date) {
date = props.date;
Expand Down Expand Up @@ -134,7 +135,7 @@ const sketch = (p5) => {
45,
355 - yAxisLength,
55,
360 - yAxisLength
355 - yAxisLength
);
} else if (data.length > 1 && isAnimating) {
// xμΆ•κ³Ό ν‰ν–‰ν•œ 보쑰선 그리기
Expand Down Expand Up @@ -174,14 +175,14 @@ const sketch = (p5) => {
const startY = p5.map(data[drawnLines], 0, 100, 300, 50);
const endX = p5.map(drawnLines + 1, 0, data.length - 1, 100, 500);
const endY = p5.map(data[drawnLines + 1], 0, 100, 300, 50);
console.log(drawnLines, lineProgress);
// console.log(drawnLines, lineProgress);
if (lineProgress == 1) {
lineProgress = 0;
} else if (lineProgress + lineStep >= 1) {
lineProgress = 1;
drawnLines++;
lineStep = lineStep + 0.01;
console.log("asdf:", drawnLines);
// console.log("asdf:", drawnLines);
} else {
lineProgress += lineStep;
}
Expand Down Expand Up @@ -281,7 +282,7 @@ const sketch = (p5) => {
if (barProgress[data.length - 1] < data.length) {
for (let ii = 0; ii <= barIndex; ii++) {
barProgress[ii] += barStep;
if (barProgress[ii] >= 1) {
if (barProgress[ii] >= 0.5) {
barProgress[ii] = 1;
if (barProgress[barIndex] > 0.4) {
barIndex++;
Expand Down
35 changes: 20 additions & 15 deletions src/components/common/keywordGraph/googleGraph/GoogleGraph.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import React from "react";
import React, { useEffect } from "react";
import NormalGraph from "../../graphs/normalGraph/NormalGraph";
export default function GoogleGraph() {
return (
<div>
<span>
<strong>"λΆˆλ‹­"</strong>이 이만큼 μ–ΈκΈ‰λμ–΄μš”
</span>

<div style={{ marginTop: "20px" }}>
<NormalGraph
data={[50, 30, 20, 10, 50]}
date={["24.06.01", "24.06.02", "24.06.03", "24.06.04", "24.06.05"]}
color={[66, 133, 244]}
lineSpeed={0.05}
barSpeed={0.05}
></NormalGraph>
</div>
<div style={{ marginTop: "20px" }}>
<NormalGraph
data={[50, 30, 20, 10, 50, 50, 30, 20, 10, 50]}
date={[
"24.06.01",
"24.06.02",
"24.06.03",
"24.06.04",
"24.06.05",
"24.06.01",
"24.06.02",
"24.06.03",
"24.06.04",
"24.06.05",
]}
color={[66, 133, 244]}
lineSpeed={0.1}
barSpeed={0.1}
></NormalGraph>
</div>
);
}
Loading