{{-- Server-rendered donut with legend (inline SVG, no JS). @include('partials.charts.donut', ['data' => [['label'=>'Paid','value'=>12,'color'=>'#1baf7a'], …], 'size' => 150, 'format' => 'int'|'money', 'title' => 'Payment methods', 'center' => 'Total']) 'color' is optional (falls back to the categorical palette in order); 'note' is an optional small second line in the legend. --}} @php $palette = ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300', '#4a3aa7', '#e34948']; $rows = collect($data ?? [])->values()->map(fn ($r, $i) => ['label' => $r['label'] ?? '', 'value' => max(0, (float) ($r['value'] ?? 0)), 'note' => $r['note'] ?? null, 'color' => $r['color'] ?? $palette[$i % count($palette)]]); $total = (float) $rows->sum('value'); $size = (int) ($size ?? 150); $format = $format ?? 'int'; $title = $title ?? 'Share by category'; $full = fn ($v) => $format === 'money' ? money($v) : number_format((float) $v); $compactMoney = function ($v) { $v = (float) $v; $cur = config('infotics.currency', 'PKR'); if ($v >= 1e6) { return $cur.' '.rtrim(rtrim(number_format($v / 1e6, 2), '0'), '.').'M'; } if ($v >= 1e4) { return $cur.' '.rtrim(rtrim(number_format($v / 1e3, 1), '0'), '.').'K'; } return money($v); }; $offset = 0; @endphp @if($total <= 0)