mirror of
https://github.com/dylanbenzi/yellowbird.git
synced 2026-11-27 01:07:01 +00:00
more customizable charts
This commit is contained in:
@@ -13,6 +13,8 @@ import {
|
||||
LineData,
|
||||
CandlestickData,
|
||||
HistogramData,
|
||||
ChartOptions,
|
||||
DeepPartial,
|
||||
} from "lightweight-charts";
|
||||
import React, { MutableRefObject, useEffect, useRef } from "react";
|
||||
|
||||
@@ -28,6 +30,7 @@ interface ChartProps {
|
||||
| CandlestickSeriesPartialOptionsWithData
|
||||
| HistogramSeriesPartialOptionsWithData
|
||||
>;
|
||||
options?: DeepPartial<ChartOptions>;
|
||||
}
|
||||
|
||||
interface LineChartWithData {
|
||||
@@ -70,7 +73,7 @@ export type CandlestickSeriesPartialOptionsWithData =
|
||||
export type HistogramSeriesPartialOptionsWithData =
|
||||
HistogramSeriesPartialOptions & HistogramChartWithData;
|
||||
|
||||
const Chart = ({ colors, series }: ChartProps) => {
|
||||
const Chart = ({ colors, series, options }: ChartProps) => {
|
||||
const chartContainerRef = useRef() as MutableRefObject<HTMLDivElement>;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -80,13 +83,13 @@ const Chart = ({ colors, series }: ChartProps) => {
|
||||
});
|
||||
};
|
||||
|
||||
const chart = createChart(chartContainerRef.current, {
|
||||
const chartOptions: DeepPartial<ChartOptions> = {
|
||||
layout: {
|
||||
background: {
|
||||
type: ColorType.Solid,
|
||||
color: colors?.backgroundColor,
|
||||
color: colors?.backgroundColor || "transparent",
|
||||
},
|
||||
textColor: colors?.textColor,
|
||||
textColor: colors?.textColor || "white",
|
||||
},
|
||||
width: chartContainerRef.current.clientWidth * 0.95,
|
||||
height: chartContainerRef.current.clientHeight * 0.95,
|
||||
@@ -95,24 +98,30 @@ const Chart = ({ colors, series }: ChartProps) => {
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
...options,
|
||||
};
|
||||
|
||||
const chart = createChart(chartContainerRef.current, chartOptions);
|
||||
chart.timeScale().fitContent();
|
||||
|
||||
series.forEach((seriesItem) => {
|
||||
switch (seriesItem.type) {
|
||||
case "line":
|
||||
const lineChart = chart.addLineSeries({
|
||||
color: seriesItem.color,
|
||||
});
|
||||
|
||||
lineChart.setData(seriesItem.data);
|
||||
case "area":
|
||||
|
||||
case "baseline":
|
||||
|
||||
case "candle":
|
||||
|
||||
case "histogram":
|
||||
if (seriesItem.type === "line") {
|
||||
const lineChart = chart.addLineSeries({ ...seriesItem });
|
||||
lineChart.setData(seriesItem.data);
|
||||
} else if (seriesItem.type === "area") {
|
||||
const areaChart = chart.addAreaSeries({ ...seriesItem });
|
||||
areaChart.setData(seriesItem.data);
|
||||
} else if (seriesItem.type === "baseline") {
|
||||
const baselineChart = chart.addBaselineSeries({ ...seriesItem });
|
||||
baselineChart.setData(seriesItem.data);
|
||||
} else if (seriesItem.type === "candle") {
|
||||
const candleChart = chart.addCandlestickSeries({ ...seriesItem });
|
||||
candleChart.setData(seriesItem.data);
|
||||
} else if (seriesItem.type === "histogram") {
|
||||
const histogramChart = chart.addHistogramSeries({ ...seriesItem });
|
||||
histogramChart.setData(seriesItem.data);
|
||||
} else {
|
||||
const hi = "hello :)";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {
|
||||
heatmapData,
|
||||
newsData,
|
||||
portfolioData,
|
||||
indexData,
|
||||
winnerMovers,
|
||||
loserMovers,
|
||||
} from "@/app/MockData/MockData";
|
||||
import HomepageModule from "./HomepageModuleCard";
|
||||
import PortfolioChart, {
|
||||
AreaSeriesPartialOptionsWithData,
|
||||
LineSeriesPartialOptionsWithData,
|
||||
} from "../charts/Chart";
|
||||
import MarketHeatmap from "../charts/MarketHeatmap";
|
||||
@@ -16,18 +15,30 @@ import { ArrowRight } from "lucide-react";
|
||||
import { NewsTable } from "../charts/news/NewsTable";
|
||||
import { newsColumns } from "../charts/news/newsColumns";
|
||||
import Chart from "../charts/Chart";
|
||||
import {
|
||||
LineData,
|
||||
LineStyle,
|
||||
LineType,
|
||||
WhitespaceData,
|
||||
} from "lightweight-charts";
|
||||
import { globalColors, smaFunc } from "@/lib/utils";
|
||||
import { seriesOne } from "@/app/MockData/seriesOne";
|
||||
import { seriesThree } from "@/app/MockData/seriesThree";
|
||||
import { seriesFive } from "@/app/MockData/seriesFive";
|
||||
|
||||
export const PortfolioModule = () => {
|
||||
const portfolioLine: LineSeriesPartialOptionsWithData = {
|
||||
type: "line",
|
||||
data: portfolioData,
|
||||
data: seriesThree,
|
||||
color: "white",
|
||||
lineType: LineType.Curved,
|
||||
};
|
||||
|
||||
const indexLine: LineSeriesPartialOptionsWithData = {
|
||||
type: "line",
|
||||
data: indexData,
|
||||
color: "yellow",
|
||||
data: seriesFive,
|
||||
color: globalColors.yellow,
|
||||
lineType: LineType.Curved,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -120,28 +131,45 @@ export const MoversModule = () => {
|
||||
};
|
||||
|
||||
export const MarketsModule = () => {
|
||||
// const chartSeries: chartSeries[] = [
|
||||
// {
|
||||
// options: {color: "yellow"},
|
||||
// type: "line",
|
||||
// data: portfolioData,
|
||||
// },
|
||||
// {
|
||||
// type: "line",
|
||||
// data:
|
||||
// }
|
||||
// ];
|
||||
const sp500IndexLine: LineSeriesPartialOptionsWithData = {
|
||||
type: "line",
|
||||
data: seriesOne,
|
||||
color: "white",
|
||||
lineType: LineType.Curved,
|
||||
priceLineVisible: false,
|
||||
};
|
||||
|
||||
const sma5Line: LineSeriesPartialOptionsWithData = {
|
||||
type: "line",
|
||||
data: smaFunc(seriesOne, 20),
|
||||
color: globalColors.yellow,
|
||||
lineType: LineType.Curved,
|
||||
priceLineVisible: false,
|
||||
};
|
||||
|
||||
return (
|
||||
<HomepageModule title="Markets">
|
||||
<div className="w-full h-full">
|
||||
<div className="w-1/2"></div>
|
||||
<div className="w-1/2 border-blue-200 border">
|
||||
{/* <Chart
|
||||
series={chartSeries}
|
||||
backgroundColor={"transparent"}
|
||||
textColor={"white"}
|
||||
/> */}
|
||||
<div className="flex h-full">
|
||||
<div className="w-1/2">content</div>
|
||||
<div className="h-full w-1/2 relative">
|
||||
<div className="absolute">S&P 500</div>
|
||||
<Chart
|
||||
series={[sp500IndexLine, sma5Line]}
|
||||
colors={{
|
||||
backgroundColor: "transparent",
|
||||
textColor: "white",
|
||||
}}
|
||||
options={{
|
||||
grid: {
|
||||
horzLines: {
|
||||
visible: false,
|
||||
},
|
||||
vertLines: {
|
||||
visible: false,
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</HomepageModule>
|
||||
|
||||
Reference in New Issue
Block a user