@props(['points' => [], 'color' => '#111827', 'unit' => '', 'height' => 140]) @php $values = array_filter(array_column($points, 'value'), fn ($v) => $v !== null); $width = 600; $padding = 30; $min = count($values) ? min($values) : 0; $max = count($values) ? max($values) : 1; if ($min === $max) { $min -= 1; $max += 1; } // جلوگیری از تقسیم بر صفر وقتی همه مقادیر یکسانند $count = count($points); $step = $count > 1 ? ($width - 2 * $padding) / ($count - 1) : 0; $coords = []; foreach ($points as $i => $p) { if ($p['value'] === null) { $coords[] = null; continue; } $x = $padding + $i * $step; $y = $height - $padding - (($p['value'] - $min) / ($max - $min)) * ($height - 2 * $padding); $coords[] = ['x' => $x, 'y' => $y, 'value' => $p['value'], 'label' => $p['label']]; } $polylinePoints = collect($coords)->filter()->map(fn ($c) => "{$c['x']},{$c['y']}")->implode(' '); @endphp
@if(count($values) === 0)

داده‌ای برای نمایش نمودار وجود ندارد.

@else {{-- خط روند --}} {{-- نقاط + برچسب مقدار --}} @foreach($coords as $c) @continue(!$c) {{ $c['value'] }}{{ $unit }} {{ $c['label'] }} @endforeach @endif