@php $labels = $labels ?? []; $series = $series ?? []; $emptyText = $emptyText ?? 'Belum ada data untuk periode ini.'; $chartWidth = 800; $chartHeight = 280; $paddingLeft = 44; $paddingRight = 18; $paddingTop = 18; $paddingBottom = 38; $plotWidth = $chartWidth - $paddingLeft - $paddingRight; $plotHeight = $chartHeight - $paddingTop - $paddingBottom; $allValues = collect($series)->flatMap(fn ($item) => $item['data'] ?? [])->map(fn ($value) => (float) $value); $maxValue = max(1, (float) ($allValues->max() ?? 1)); $pointCount = max(1, count($labels)); $dateIndexes = array_values(array_unique([0, (int) floor(($pointCount - 1) / 2), $pointCount - 1])); $formatDate = function ($value): string { try { return \Illuminate\Support\Carbon::parse($value)->translatedFormat('d M'); } catch (\Throwable) { return (string) $value; } }; @endphp @if($allValues->isEmpty())

{{ $emptyText }}

@else
@for($grid = 0; $grid <= 4; $grid++) @php $gridY = $paddingTop + (($plotHeight / 4) * $grid); $gridValue = (int) round($maxValue * (1 - ($grid / 4))); @endphp {{ number_format($gridValue, 0, ',', '.') }} @endfor @foreach($series as $seriesIndex => $item) @php $values = array_values($item['data'] ?? []); $color = $item['color'] ?? 'var(--meridian-accent)'; $points = collect($values)->map(function ($value, $index) use ($paddingLeft, $paddingTop, $plotWidth, $plotHeight, $pointCount, $maxValue) { $x = $paddingLeft + ($pointCount > 1 ? ($plotWidth * $index / ($pointCount - 1)) : $plotWidth / 2); $y = $paddingTop + $plotHeight - (($plotHeight * (float) $value) / $maxValue); return round($x, 2).','.round($y, 2); })->implode(' '); $areaPoints = $paddingLeft.','.($paddingTop + $plotHeight).' '.$points.' '.($chartWidth - $paddingRight).','.($paddingTop + $plotHeight); @endphp @if($seriesIndex === 0) @endif @foreach($values as $index => $value) @php $x = $paddingLeft + ($pointCount > 1 ? ($plotWidth * $index / ($pointCount - 1)) : $plotWidth / 2); $y = $paddingTop + $plotHeight - (($plotHeight * (float) $value) / $maxValue); @endphp {{ $labels[$index] ?? '' }}: {{ number_format((float) $value, 0, ',', '.') }} {{ $item['name'] ?? '' }} @endforeach @endforeach @foreach($dateIndexes as $index) @php $x = $paddingLeft + ($pointCount > 1 ? ($plotWidth * $index / ($pointCount - 1)) : $plotWidth / 2); @endphp {{ $formatDate($labels[$index] ?? '') }} @endforeach
@endif