|
| 1 | +"use client"; |
| 2 | +import React, { type JSX } from "react"; |
| 3 | +import { |
| 4 | + LineChart, |
| 5 | + Line, |
| 6 | + XAxis, |
| 7 | + YAxis, |
| 8 | + CartesianGrid, |
| 9 | + Tooltip, |
| 10 | + ResponsiveContainer, |
| 11 | + Legend, |
| 12 | + ReferenceLine, |
| 13 | + Label, |
| 14 | +} from "recharts"; |
| 15 | + |
| 16 | +const data = [ |
| 17 | + { time: "t0", totalState: 50, activeState: 0, prunedState: 25, prunedTotal: null }, |
| 18 | + { time: "t1", totalState: 250, activeState: 75, prunedState: 150, prunedTotal: null }, |
| 19 | + { time: "t2", totalState: 450, activeState: 150, prunedState: 275, prunedTotal: null }, |
| 20 | + { time: "t3", totalState: 650, activeState: 225, prunedState: 400, prunedTotal: 225 }, |
| 21 | + { time: "t4", totalState: 850, activeState: 300, prunedState: 525, prunedTotal: 425 }, |
| 22 | + { time: "t5", totalState: 1050, activeState: 375, prunedState: 650, prunedTotal: 625 }, |
| 23 | + { time: "t6", totalState: 1250, activeState: 450, prunedState: 775, prunedTotal: 825 }, |
| 24 | +]; |
| 25 | + |
| 26 | +const StateGrowthChart = (): JSX.Element => { |
| 27 | + const renderLegend = (props: any) => { |
| 28 | + const { payload } = props; |
| 29 | + // Add custom legend entry for the arrow |
| 30 | + const customPayload = [ |
| 31 | + ...payload, |
| 32 | + { value: "Resync/Offline Pruning", color: "#666", type: "arrow" } |
| 33 | + ]; |
| 34 | + |
| 35 | + return ( |
| 36 | + <div style={{ display: "flex", justifyContent: "center", gap: "16px", paddingBottom: "16px", flexWrap: "wrap" }}> |
| 37 | + {customPayload.map((entry: any, index: number) => ( |
| 38 | + <div key={`legend-${index}`} style={{ display: "flex", alignItems: "center", gap: "6px" }}> |
| 39 | + <svg width="16" height="2" style={{ overflow: "visible" }}> |
| 40 | + <line |
| 41 | + x1="0" |
| 42 | + y1="1" |
| 43 | + x2="16" |
| 44 | + y2="1" |
| 45 | + stroke={entry.color} |
| 46 | + strokeWidth="2" |
| 47 | + strokeDasharray={entry.value === "Total State After Pruning / Resync" || entry.type === "arrow" ? "3 3" : "0"} |
| 48 | + /> |
| 49 | + </svg> |
| 50 | + <span style={{ fontSize: "11px", color: "#666" }}>{entry.value}</span> |
| 51 | + </div> |
| 52 | + ))} |
| 53 | + </div> |
| 54 | + ); |
| 55 | + }; |
| 56 | + |
| 57 | + return ( |
| 58 | + <div className="w-full my-6 p-4 border rounded-lg bg-white dark:bg-gray-900"> |
| 59 | + <ResponsiveContainer width="100%" height={400}> |
| 60 | + <LineChart |
| 61 | + data={data} |
| 62 | + margin={{ top: 20, right: 30, left: 20, bottom: 60 }} |
| 63 | + > |
| 64 | + <CartesianGrid strokeDasharray="3 3" className="stroke-gray-200 dark:stroke-gray-700" /> |
| 65 | + <XAxis |
| 66 | + dataKey="time" |
| 67 | + label={{ value: "Time →", position: "insideBottom", offset: -10 }} |
| 68 | + tick={false} |
| 69 | + /> |
| 70 | + <YAxis |
| 71 | + label={{ value: "State Size (GB)", angle: -90, position: "insideLeft", offset: 10 }} |
| 72 | + tick={false} |
| 73 | + /> |
| 74 | + <Legend |
| 75 | + verticalAlign="top" |
| 76 | + height={36} |
| 77 | + content={renderLegend} |
| 78 | + /> |
| 79 | + <Line |
| 80 | + type="monotone" |
| 81 | + dataKey="totalState" |
| 82 | + stroke="#ff0000" |
| 83 | + strokeWidth={3} |
| 84 | + name="Total State" |
| 85 | + dot={false} |
| 86 | + legendType="line" |
| 87 | + /> |
| 88 | + <Line |
| 89 | + type="monotone" |
| 90 | + dataKey="activeState" |
| 91 | + stroke="#0066cc" |
| 92 | + strokeWidth={3} |
| 93 | + name="Active State" |
| 94 | + dot={false} |
| 95 | + legendType="line" |
| 96 | + /> |
| 97 | + <Line |
| 98 | + type="monotone" |
| 99 | + dataKey="prunedState" |
| 100 | + stroke="#FFA500" |
| 101 | + strokeWidth={3} |
| 102 | + name="Pruned State" |
| 103 | + dot={false} |
| 104 | + legendType="line" |
| 105 | + /> |
| 106 | + <Line |
| 107 | + type="monotone" |
| 108 | + dataKey="prunedTotal" |
| 109 | + stroke="#ff0000" |
| 110 | + strokeWidth={3} |
| 111 | + strokeDasharray="5 5" |
| 112 | + name="Total State After Pruning / Resync" |
| 113 | + dot={false} |
| 114 | + connectNulls={false} |
| 115 | + legendType="line" |
| 116 | + /> |
| 117 | + {/* Vertical arrow at t3 */} |
| 118 | + <ReferenceLine |
| 119 | + segment={[ |
| 120 | + { x: "t3", y: 650 }, |
| 121 | + { x: "t3", y: 275 }, |
| 122 | + ]} |
| 123 | + stroke="#666" |
| 124 | + strokeWidth={2} |
| 125 | + strokeDasharray="5 5" |
| 126 | + /> |
| 127 | + </LineChart> |
| 128 | + </ResponsiveContainer> |
| 129 | + <div className="mt-4 text-sm text-gray-600 dark:text-gray-400 text-center"> |
| 130 | + <strong>Note:</strong> The dotted line shows how resync or offline pruning reduces total state or pruned state back to active state level. |
| 131 | + </div> |
| 132 | + </div> |
| 133 | + ); |
| 134 | +}; |
| 135 | + |
| 136 | +export default StateGrowthChart; |
0 commit comments