@props([ 'series' => [], // [['label' => 'Mon', 'value' => 1200], …] 'height' => 220, 'formatter' => null, // callable for the value labels 'slot' => 1, // categorical slot (1–4) 'label' => 'Value', ]) @php /* * Column chart for change over time. * * Server-rendered SVG on purpose: the dashboard must paint on the first * response, and a POS runs on hardware where a charting bundle is a real * cost. Bars carry a 2px surface gap, 4px rounded data-ends anchored to * the baseline, and a native tooltip per mark. */ $rows = collect($series)->values(); $max = max(1, (float) $rows->max('value')); $count = max(1, $rows->count()); $width = 640; $padTop = 16; $padBottom = 28; $padLeft = 8; $plotHeight = $height - $padTop - $padBottom; $slotWidth = ($width - $padLeft * 2) / $count; $barWidth = max(3, min(46, $slotWidth - 6)); // the 2px+ surface gap $format = $formatter ?? fn ($value) => number_format((float) $value); // Only label the peak and the latest column — a number on every bar is noise. $peakIndex = $rows->search(fn ($row) => (float) $row['value'] === $max); $lastIndex = $count - 1; @endphp
| Period | {{ $label }} |
|---|---|
| {{ $row['label'] }} | {{ $format($row['value']) }} |