@props([ 'title', 'subtitle' => null, 'info' => null, 'chart' => 'donut', // donut|gauge|bars 'centerLabel' => null, 'centerValue' => null, 'items' => [], // [['label' => '', 'value' => 0, 'color' => '#…'], ...] 'href' => null, 'linkLabel' => null, ]) @php $palette = ['#FB923C', '#10B981', '#0EA5E9', '#F43F5E', '#A855F7', '#F59E0B', '#64748B']; $normalized = []; foreach (array_values($items) as $i => $item) { $normalized[] = [ 'label' => (string) ($item['label'] ?? ''), 'value' => (float) ($item['value'] ?? 0), 'color' => (string) ($item['color'] ?? $palette[$i % count($palette)]), ]; } $total = array_sum(array_column($normalized, 'value')); if ($total <= 0) { $total = 1; if ($normalized === []) { $normalized = [['label' => 'لا بيانات', 'value' => 1, 'color' => '#E2E8F0']]; } } $donutSegments = []; $circumference = 2 * M_PI * 42; $offset = 0.0; foreach ($normalized as $seg) { $len = ($seg['value'] / $total) * $circumference; $donutSegments[] = [ ...$seg, 'dash' => $len, 'gap' => max($circumference - $len, 0), 'offset' => -$offset, ]; $offset += $len; } // Semi-circle gauge: 180° arc, radius 48, path length ≈ π*r $gaugeR = 48; $gaugeLen = M_PI * $gaugeR; $gaugeSegments = []; $gOffset = 0.0; foreach ($normalized as $seg) { $len = ($seg['value'] / $total) * $gaugeLen; $gaugeSegments[] = [ ...$seg, 'dash' => $len, 'gap' => max($gaugeLen - $len, 0), 'offset' => -$gOffset, ]; $gOffset += $len; } $barMax = max(1.0, max(array_column($normalized, 'value') ?: [1])); $displayCenter = $centerValue ?? (string) (int) round(array_sum(array_column($normalized, 'value'))); @endphp
merge(['class' => 'nursery-card nursery-chart-panel']) }}>
@if(isset($icon)) {{ $icon }} @endif

{{ $title }}

@if($info) @endif
@if($subtitle)

{{ $subtitle }}

@endif
@if($href && $linkLabel) {{ $linkLabel }} @endif
{{-- في RTL: العنصر الأول يمين → البيانات يمين، الشارت شمال --}}
    @foreach($normalized as $item)
  • {{ $item['label'] }} {{ is_float($item['value']) && floor($item['value']) != $item['value'] ? number_format($item['value'], 2) : (int) $item['value'] }}
  • @endforeach