chart update

This commit is contained in:
2024-02-28 23:57:15 -05:00
parent 084a5050b7
commit 6a396953bf
17 changed files with 2886 additions and 205 deletions
+30
View File
@@ -0,0 +1,30 @@
"use client";
import { ResponsiveTreeMap } from "@nivo/treemap";
import React from "react";
const MarketHeatmap = ({ data }: any) => (
<ResponsiveTreeMap
data={data}
identity="name"
value="loc"
valueFormat=".02s"
tile="binary"
// margin={{ top: 10, right: 10, bottom: 10, left: 10 }}
labelSkipSize={30}
labelTextColor="black"
parentLabelPosition="left"
parentLabelTextColor={{
from: "color",
modifiers: [["darker", 2]],
}}
colors={{ scheme: "red_yellow_green" }}
borderColor={{
from: "color",
modifiers: [["brighter", 0.1]],
}}
motionConfig="wobbly"
/>
);
export default MarketHeatmap;
+59 -64
View File
@@ -1,71 +1,66 @@
"use client";
import React from "react";
import { ResponsiveLine } from "@nivo/line";
import { createChart, ColorType } from "lightweight-charts";
import React, { MutableRefObject, useEffect, useRef } from "react";
import { indexData, portfolioData } from "@/app/MockData/MockData";
function PortfolioChart({ data }: any) {
return (
<ResponsiveLine
data={data}
theme={{
"text": {
"fontSize": 11,
"fill": "#ffffff",
"outlineWidth": 0,
"outlineColor": "transparent",
const PortfolioChart = (props: any) => {
const {
data,
colors: {
backgroundColor = "transparent",
portfolioLineColor = "#FACC15",
indexLineColor = "#FFFFFF",
textColor = "white",
} = {},
} = props;
const chartContainerRef = useRef() as MutableRefObject<HTMLDivElement>;
useEffect(() => {
const handleResize = () => {
chart.applyOptions({
width: chartContainerRef.current.clientWidth * 0.95,
});
};
const chart = createChart(chartContainerRef.current, {
layout: {
background: { type: ColorType.Solid, color: backgroundColor },
textColor,
},
width: chartContainerRef.current.clientWidth * 0.95,
height: 300,
grid: {
vertLines: {
visible: false,
},
}}
margin={{ top: 50, right: 110, bottom: 50, left: 60 }}
xScale={{ type: "point" }}
yScale={{
type: "linear",
min: "auto",
max: "auto",
stacked: true,
reverse: false,
}}
yFormat=" >-.2f"
curve="monotoneX"
axisTop={null}
axisRight={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: "",
legendOffset: 0,
truncateTickAt: 0,
}}
axisBottom={{
tickSize: 0,
tickPadding: 0,
tickRotation: -1,
legend: "",
legendOffset: 36,
legendPosition: "middle",
truncateTickAt: 0,
}}
axisLeft={null}
enableGridX={false}
colors={{ scheme: "yellow_orange_brown" }}
enablePoints={false}
pointSize={10}
pointColor={{ theme: "background" }}
pointBorderWidth={2}
pointBorderColor={{ from: "serieColor" }}
pointLabelYOffset={-12}
crosshairType="cross"
useMesh={true}
legends={[]}
motionConfig={{
mass: 1,
tension: 250,
friction: 1,
clamp: true,
precision: 0.01,
velocity: 0,
}}
/>
},
});
chart.timeScale().fitContent();
const portfolioSeries = chart.addLineSeries({
color: portfolioLineColor,
});
portfolioSeries.setData(portfolioData);
const indexSeries = chart.addLineSeries({
color: indexLineColor,
});
indexSeries.setData(indexData);
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
chart.remove();
};
}, [data, backgroundColor, portfolioLineColor, indexLineColor, textColor]);
return (
<div className="flex justify-center" ref={chartContainerRef} id="chart" />
);
}
};
export default PortfolioChart;