{{-- Spider/radar of field mastery — port of ags_parent RadarChart.jsx. Vars: $items = [['name'=>, 'value'=>float|null], ...], $unit='M', $color --}} @php $unit = $unit ?? 'M'; $color = $color ?? '#88C808'; $SIZE = 340; $CX = 170; $CY = 170; $R_MAX = 120; $items = array_values($items ?? []); $values = array_map(fn ($it) => $it['value'] === null ? 0 : (float) $it['value'], $items); $peak = max(array_merge([100], $values)); $ceiling = (int) (ceil($peak / 100) * 100); $ringCount = max(1, (int) ($ceiling / 100)); $N = max(3, count($items)); $angle = fn ($i) => -M_PI / 2 + (2 * M_PI * $i) / $N; $xy = function ($i, $value) use ($angle, $CX, $CY, $R_MAX, $ceiling) { $r = ($value / max(1, $ceiling)) * $R_MAX; return [$CX + $r * cos($angle($i)), $CY + $r * sin($angle($i))]; }; $profile = []; foreach (range(0, $N - 1) as $i) { $profile[] = implode(',', $xy($i, $items[$i] ?? false ? $values[$i] : 0)); } @endphp