{{-- US states shaded by count (one blue, light → dark; grey = none). $values ['VA' => 120, …] (US state codes) $noun 'views' $min optional: the caller left out states under this; they show as "Fewer than N" (never a count) --}} @php $map = \App\Support\Charts::usMap(); $min ??= 0; $noun ??= ''; $max = $values ? max($values) : 0; $steps = \App\Support\Charts::mapSteps((int) $max); // Spread however many steps there are across the five colours. $shade = function (int $v) use ($steps) { if ($v <= 0) return 0; foreach ($steps as $i => $up) { if ($v <= $up) { return count($steps) >= 5 ? $i + 1 : (int) round(($i + 1) * 5 / count($steps)); } } return 5; }; $zero = $min > 1 ? 'Fewer than '.$min : 'None'; $label = fn (int $v) => $v <= 0 ? $zero : number_format($v); $legend = []; $lo = max(1, $min); foreach ($steps as $i => $up) { if ($up < $lo) { continue; } $legend[] = [$shade($up), $lo === $up ? number_format($up) : number_format($lo).'–'.number_format($up)]; $lo = $up + 1; } $top = collect($values)->sortDesc()->keys()->first(); $aria = 'Map of '.$noun.' by US state'.($top ? ', most in '.($map['states'][$top][0] ?? $top) : '').'. The list beside it has the figures.'; @endphp