| 1 | "use client" |
| 2 | |
| 3 | import { useChartPart } from "./chart-context" |
| 4 | |
| 5 | export function Grid({ |
| 6 | horizontal = true, |
| 7 | vertical = false, |
| 8 | strokeDasharray = "3 3" |
| 9 | }: { |
| 10 | horizontal?: boolean |
| 11 | vertical?: boolean |
| 12 | strokeDasharray?: string |
| 13 | }) { |
| 14 | const ctx = |
| 15 | if (!ctx.ready |
| 16 | const { width |
| 17 | |
| 18 | return ( |
| 19 | <g className="stroke-border |
| 20 | {horizontal && |
| 21 | ctx.y |
| 22 | .ticks(4) |
| 23 | .map((t) |
| 24 | <line |
| 25 | key={`h-${t |
| 26 | x1={0} |
| 27 | x2={width} |
| 28 | y1={ctx.y |
| 29 | y2={ctx.y |
| 30 | /> |
| 31 | ))} |
| 32 | {vertical && |
| 33 | ctx.data.map |
| 34 | <line |
| 35 | // biome-ignore lint/suspicious/noArrayIndexKey: index is the stable x position |
| 36 | key={`v-${i |
| 37 | x1={ctx.xCenter |
| 38 | x2={ctx.xCenter |
| 39 | y1={0} |
| 40 | y2={ctx.plot |
| 41 | /> |
| 42 | ))} |
| 43 | </g> |
| 44 | ) |
| 45 | } |
| 46 | |
| 47 | // Render beneath the dither canvas so grid lines sit behind the fill. |
| 48 | Grid.chartLayer = " |