Skip to content
Snippets Groups Projects
Commit cef6fb91 authored by Lukas's avatar Lukas Committed by mcfarhat
Browse files

Use theme locally to set stroke color in chart component

parent 624b462e
No related branches found
No related tags found
1 merge request!599Lbudginas/#493 hive price chart
...@@ -13,6 +13,7 @@ import { useHiveChainContext } from "@/contexts/HiveChainContext"; ...@@ -13,6 +13,7 @@ import { useHiveChainContext } from "@/contexts/HiveChainContext";
import { Card, CardContent, CardHeader } from "../ui/card"; import { Card, CardContent, CardHeader } from "../ui/card";
import { Loader2 } from "lucide-react"; import { Loader2 } from "lucide-react";
import { colorMap } from "../balanceHistory/BalanceHistoryChart"; import { colorMap } from "../balanceHistory/BalanceHistoryChart";
import { useTheme } from "@/contexts/ThemeContext";
const CustomTooltip = ({ const CustomTooltip = ({
active, active,
...@@ -54,7 +55,6 @@ const calculateAvgHivePrice = ( ...@@ -54,7 +55,6 @@ const calculateAvgHivePrice = (
interface MarketChartProps { interface MarketChartProps {
data: Hive.MarketHistory | undefined; data: Hive.MarketHistory | undefined;
isLoading: boolean; isLoading: boolean;
strokeColor: string;
} }
interface ChartData { interface ChartData {
date: string; date: string;
...@@ -65,9 +65,9 @@ interface ChartData { ...@@ -65,9 +65,9 @@ interface ChartData {
const MarketHistoryChart: React.FC<MarketChartProps> = ({ const MarketHistoryChart: React.FC<MarketChartProps> = ({
data, data,
isLoading, isLoading,
strokeColor,
}) => { }) => {
const { hiveChain } = useHiveChainContext(); const { hiveChain } = useHiveChainContext();
const { theme } = useTheme();
if (!data || !hiveChain) return; if (!data || !hiveChain) return;
...@@ -99,44 +99,38 @@ const MarketHistoryChart: React.FC<MarketChartProps> = ({ ...@@ -99,44 +99,38 @@ const MarketHistoryChart: React.FC<MarketChartProps> = ({
const maxValue = Math.max( const maxValue = Math.max(
...chartData.map((d: ChartData) => parseFloat(d.avgPrice)) ...chartData.map((d: ChartData) => parseFloat(d.avgPrice))
); );
const strokeColor = theme === "dark" ? "#FFF" : "#000";
return ( return (
<Card className="mb-3"> <ResponsiveContainer
<CardHeader className="flex justify-between items-center px-1 py-3"> width="100%"
<h2 className="text-lg font-semibold">Hive Price Chart</h2> height={250}
</CardHeader> >
<CardContent> <LineChart data={chartData}>
<ResponsiveContainer <XAxis
width="100%" dataKey="date"
height={300} stroke={strokeColor}
> />
<LineChart data={chartData}> <YAxis
<XAxis dataKey="avgPrice"
dataKey="date" domain={[minValue, maxValue]}
stroke={strokeColor} stroke={strokeColor}
/> />
<YAxis <Tooltip content={<CustomTooltip />} />
dataKey="avgPrice" <Legend
domain={[minValue, maxValue]} verticalAlign="top"
stroke={strokeColor} height={36}
/> />
<Tooltip content={<CustomTooltip />} /> <Line
<Legend name={`Hive Price: $${lastHivePrice}`}
verticalAlign="top" type="monotone"
height={36} dataKey="avgPrice"
/> stroke={colorMap.HIVE}
<Line dot={false}
name={`Hive Price: $${lastHivePrice}`} strokeWidth={2}
type="monotone" />
dataKey="avgPrice" </LineChart>
stroke={colorMap.HIVE} </ResponsiveContainer>
dot={false}
strokeWidth={2}
/>
</LineChart>
</ResponsiveContainer>
</CardContent>
</Card>
); );
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment