{{-- :::chart type="line" title: "Average 30-day return by plan tier" caption: "Data from 12,000 completed cycles, Q1 2026" (optional) x_labels: [Day 1, Day 7, Day 14, Day 21, Day 30] series: - name: "$5 plan" color: "#f97316" (optional; falls back to palette) data: [0, 3, 8, 15, 22] - name: "$25 plan" data: [0, 4, 10, 18, 25] ::: Supports type="line" or type="bar". Server-rendered SVG, no JS deps. Palette rotates through brand orange + neutrals for extra series. --}} @php $type = $type ?? 'line'; $title = $title ?? ''; $caption = $caption ?? null; $x_labels = $x_labels ?? []; $series = $series ?? []; $palette = ['#f97316', '#0f172a', '#64748b', '#94a3b8']; // Guard against malformed data $valid = !empty($x_labels) && !empty($series); $maxVal = 0; if ($valid) { foreach ($series as $s) { foreach (($s['data'] ?? []) as $v) { $maxVal = max($maxVal, (float) $v); } } $maxVal = $maxVal > 0 ? $maxVal * 1.15 : 1; } // SVG dimensions $W = 720; $H = 320; $padL = 44; $padR = 24; $padT = 24; $padB = 44; $plotW = $W - $padL - $padR; $plotH = $H - $padT - $padB; $stepX = count($x_labels) > 1 ? $plotW / (count($x_labels) - 1) : $plotW; @endphp @if($valid)
@if($title)
{{ $title }}
@endif @if(!empty($series))
@foreach($series as $si => $s)
{{ $s['name'] ?? 'Series ' . ($si + 1) }}
@endforeach
@endif
{{-- Grid lines (5 horizontal) --}} @for($g = 0; $g <= 4; $g++) @php $y = $padT + ($plotH * $g / 4); @endphp {{ number_format($maxVal - ($maxVal * $g / 4), 0) }} @endfor {{-- X axis labels --}} @foreach($x_labels as $xi => $xl) @php $x = $padL + ($xi * $stepX); @endphp {{ $xl }} @endforeach {{-- Series --}} @foreach($series as $si => $s) @php $color = $s['color'] ?? $palette[$si % count($palette)]; $data = $s['data'] ?? []; @endphp @if($type === 'line') @php $points = []; foreach ($data as $di => $val) { $px = $padL + ($di * $stepX); $py = $padT + $plotH - (((float) $val / $maxVal) * $plotH); $points[] = round($px, 2) . ',' . round($py, 2); } $polyPoints = implode(' ', $points); @endphp @foreach($data as $di => $val) @php $px = $padL + ($di * $stepX); $py = $padT + $plotH - (((float) $val / $maxVal) * $plotH); @endphp @endforeach @elseif($type === 'bar') @php $groupCount = count($series); $groupW = $stepX * 0.7; $barW = $groupW / max($groupCount, 1); @endphp @foreach($data as $di => $val) @php $groupX = $padL + ($di * $stepX) - ($groupW / 2); $bx = $groupX + ($si * $barW); $bh = ((float) $val / $maxVal) * $plotH; $by = $padT + $plotH - $bh; @endphp @endforeach @endif @endforeach
@if($caption)
{{ $caption }}
@endif
@endif