@php $maxMonth = $months->max('total'); @endphp
@php
$maxM = max(1, $months->max('total'));
$svgW = 600; $svgH = 200; $pad = 35;
$cnt = count($months);
$lnPts = '';
$fillPts = '';
foreach ($months as $i => $m) {
$x = $pad + ($i / max(1, $cnt - 1)) * ($svgW - 2 * $pad);
$y = $svgH - $pad - (($m['total'] / $maxM) * ($svgH - 2 * $pad));
$lnPts .= "$x,$y ";
$fillPts .= "$x,$y ";
}
$lx = $pad + (($cnt - 1) / max(1, $cnt - 1)) * ($svgW - 2 * $pad);
$fx = $pad;
$by = $svgH - $pad;
$fillPts .= "$lx,$by $fx,$by";
@endphp
@php
$qColors = ['#3b82f6', '#22c55e', '#a855f7', '#f59e0b'];
$quarters = [];
$qLabels = ['T1', 'T2', 'T3', 'T4'];
$qMonthRanges = [['Jan','Feb','Mar'], ['Apr','May','Jun'], ['Jul','Aug','Sep'], ['Oct','Nov','Dec']];
$qTotal = 0;
foreach ($qLabels as $i => $label) {
$total = collect($months)->filter(fn($m) => in_array($m['label'], $qMonthRanges[$i]))->sum('total');
$quarters[] = ['label' => $label, 'total' => $total, 'color' => $qColors[$i]];
$qTotal += $total;
}
$qTotal = max(1, $qTotal);
$conicParts = '';
$cumAngle = 0;
foreach ($quarters as $i => $q) {
$angle = ($q['total'] / $qTotal) * 360;
if ($q['total'] > 0) {
$conicParts .= ($i > 0 ? ', ' : '') . $q['color'] . ' ' . round($cumAngle) . 'deg ' . round($cumAngle + $angle) . 'deg';
$cumAngle += $angle;
}
}
@endphp
Total
{{ number_format($qTotal, 0) }}
@foreach($quarters as $q)
{{ $q['label'] }}
{{ number_format($q['total'], 2) }}
@endforeach