{{-- Trend over the range with a metric switch (one measure per chart: no second axis). $series key => [name, this period (day => n), previous period, fmt] $range App\Services\Analytics\Range $markers optional, for the first chart $title card title --}} @php $bucket = $range->bucket(); $uid = 'tr'.substr(md5(json_encode(array_keys($series)).($title ?? '')), 0, 6); @endphp

{{ $title ?? 'Over time' }}

@if (count($series) > 1)
@foreach ($series as $k => $s) @endforeach
@endif
@foreach ($series as $k => [$name, $cur, $prev, $fmt]) @php $c = \App\Support\Charts::bucket($cur, $bucket); $p = \App\Support\Charts::bucket($prev, $bucket); $p = count($p) === count($c) ? array_combine(array_keys($c), array_values($p)) : $p; @endphp
first) hidden @endif> @include('charts.line', [ 'series' => [['name' => $range->label, 'values' => $c], ['name' => 'The '.$range->days().' days before', 'values' => $p, 'prev' => true]], 'fmt' => $fmt, 'bucket' => $bucket, 'label' => $name, 'markers' => $loop->first ? ($markers ?? []) : [], ])
Show as a table
@foreach (array_reverse(array_keys($c)) as $i => $d) @php $pv = array_values($p)[count($c) - 1 - $i] ?? 0; @endphp @endforeach
{{ $bucket === 'week' ? 'Week of' : 'Day' }}{{ $name }}Period before
{{ \Carbon\CarbonImmutable::parse($d)->format('D M j, Y') }}{{ \App\Support\Charts::format($c[$d], $fmt) }}{{ \App\Support\Charts::format($pv, $fmt) }}
@endforeach