charting update

This commit is contained in:
2024-03-04 13:22:19 -05:00
parent c9dde12f83
commit 8beafc01db
2 changed files with 41 additions and 24 deletions
+33 -19
View File
@@ -4,16 +4,30 @@ import { createChart, ColorType } from "lightweight-charts";
import React, { MutableRefObject, useEffect, useRef } from "react"; import React, { MutableRefObject, useEffect, useRef } from "react";
import { indexData, portfolioData } from "@/app/MockData/MockData"; import { indexData, portfolioData } from "@/app/MockData/MockData";
const Chart = (props: any) => { interface ChartProps {
const { series: Series[];
data, colors: {
colors: { backgroundColor: string;
backgroundColor = "transparent", textColor: string;
portfolioLineColor = "#FACC15", };
indexLineColor = "#FFFFFF", config?: object;
textColor = "white", }
} = {},
} = props; interface Series {
data: typeof portfolioData;
seriesColor: string;
}
const Chart = ({ series, colors, config }: ChartProps) => {
// const {
// data,
// colors: {
// backgroundColor = "transparent",
// portfolioLineColor = "#FACC15",
// indexLineColor = "#FFFFFF",
// textColor = "white",
// } = {},
// } = props;
const chartContainerRef = useRef() as MutableRefObject<HTMLDivElement>; const chartContainerRef = useRef() as MutableRefObject<HTMLDivElement>;
@@ -26,8 +40,8 @@ const Chart = (props: any) => {
const chart = createChart(chartContainerRef.current, { const chart = createChart(chartContainerRef.current, {
layout: { layout: {
background: { type: ColorType.Solid, color: backgroundColor }, background: { type: ColorType.Solid, color: colors.backgroundColor },
textColor, textColor: colors.textColor,
}, },
width: chartContainerRef.current.clientWidth * 0.95, width: chartContainerRef.current.clientWidth * 0.95,
height: chartContainerRef.current.clientHeight * 0.95, height: chartContainerRef.current.clientHeight * 0.95,
@@ -40,14 +54,14 @@ const Chart = (props: any) => {
chart.timeScale().fitContent(); chart.timeScale().fitContent();
const portfolioSeries = chart.addLineSeries({ const portfolioSeries = chart.addLineSeries({
color: portfolioLineColor, color: series[0].seriesColor,
}); });
portfolioSeries.setData(portfolioData); portfolioSeries.setData(series[0].data);
const indexSeries = chart.addLineSeries({ // const indexSeries = chart.addLineSeries({
color: indexLineColor, // color: indexLineColor,
}); // });
indexSeries.setData(indexData); // indexSeries.setData(indexData);
window.addEventListener("resize", handleResize); window.addEventListener("resize", handleResize);
@@ -56,7 +70,7 @@ const Chart = (props: any) => {
chart.remove(); chart.remove();
}; };
}, [data, backgroundColor, portfolioLineColor, indexLineColor, textColor]); });
return ( return (
<div <div
+8 -5
View File
@@ -6,7 +6,6 @@ import {
loserMovers, loserMovers,
} from "@/app/MockData/MockData"; } from "@/app/MockData/MockData";
import HomepageModule from "./HomepageModuleCard"; import HomepageModule from "./HomepageModuleCard";
import PortfolioChart from "../charts/Chart";
import MarketHeatmap from "../charts/MarketHeatmap"; import MarketHeatmap from "../charts/MarketHeatmap";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { ArrowRight, Divide } from "lucide-react"; import { ArrowRight, Divide } from "lucide-react";
@@ -23,7 +22,13 @@ export const PortfolioModule = () => {
<div className="text-green-500">^10.0% $3,412.09</div> <div className="text-green-500">^10.0% $3,412.09</div>
</div> </div>
<div className="h-3/4"> <div className="h-3/4">
<Chart data={portfolioData} /> <Chart
data={portfolioData}
colors={{
backgroundColor: "transparent",
textColor: "white",
}}
/>
</div> </div>
<div className="flex justify-between"> <div className="flex justify-between">
<Button className="text-white" variant="link"> <Button className="text-white" variant="link">
@@ -103,9 +108,7 @@ export const MarketsModule = () => {
<HomepageModule title="Markets"> <HomepageModule title="Markets">
<div className="w-full"> <div className="w-full">
<div className="w-1/2"></div> <div className="w-1/2"></div>
<div className="w-1/2 border-blue-200 border"> <div className="w-1/2 border-blue-200 border"></div>
<Chart />
</div>
</div> </div>
</HomepageModule> </HomepageModule>
); );