Metrics dashboard

How a workspace's issues moved over a period, and against the period before it: what is happening today, four headline figures, the daily line, where the closed issues came from, what is open by priority, how far issues get from report to release, the busiest projects, the latest activity and the cycle's goals. Every chart is drawn on the server from a PHP array, as SVG with its own text alternative and, here, a table of its values for a screen reader, so the page needs no chart library and no script.

The Reports page, light and dark

The Reports page on a phone, light and dark

A block, not a component: copy the view below into your app. It is the Reports page of the sidebar shell, which assumes the base layout.

What it shows

  • The period in the page header: a date picker range with presets, a switch to compare with the period before, and Update, all one GET form, so a report is a link to share.

  • A day still under way: an alert says the last day's figures are partial and how often they update, rather than letting a half day read as a drop.

  • Today so far as a metric ticker: what is open now, opened and closed today and waiting for review, each with its trend through the day. These are now, not the period, so they stay the same whatever period is chosen.

  • Four figures as stat tiles: issues closed and opened, the median time to close, and active members. Comparing, each says what it is up or down on and by how much; not comparing, each says which days it covers. The median time to close has no coloured change but a caption ("down from 3.1 days"): fewer days is better, and the tile would colour a fall red.

  • Opened and closed each day as a line chart, with its legend and the series named at their ends.

  • Closed by project as a horizontal bar chart with the values on the bars, open by priority as a donut chart with the total in the middle and a legend with counts and shares, and from report to release as a funnel chart with the drop between each step.

  • The busiest projects in a table: open, closed, the median time to close, and a bar sparkline of the closed issues each week. Each project's name links to its own report.

  • Latest activity as a timeline: who did what, with their initials, a link to the issue and when.

  • The cycle's goals: two progress bars, three activity rings for the week, and a gauge whose bands say whether the share of questions answered within a day meets its target.

  • Loading: while $report is null, a skeleton swap holds every chart's place with a skeleton of its shape, and the busiest projects' table draws skeleton rows under its real head (loading), all under the same headings, so the page does not jump when the numbers come:

    Loading, light and dark

  • An empty period: every chart says, in its own words, that there is nothing to draw (empty state in the table and the timeline), the figures read 0 and a dash, and comparing is off. Today so far and the goals are not about the period, so they stay:

    A period with nothing in it, light and dark

Built from

The markup

resources/views/reports/index.blade.php

{{--
    How the workspace's issues moved over a period, against the period
    before it. Each chart is drawn on the server from a PHP array, with its
    own text alternative and a table of its values for a screen reader.
    The controller passes $period (from, to, and previous: the period
    compared with, in words), $compare and $report (null while it is being
    worked out; see the docs page for its shape).
--}}
@php
    $from = \Illuminate\Support\Carbon::parse($period['from']);
    $to = \Illuminate\Support\Carbon::parse($period['to']);
    $span = $from->isSameMonth($to) ? $from->format('j').'–'.$to->format('j F Y') : $from->format('j M').' – '.$to->format('j M Y');
    $ready = $report !== null;
    $number = ['decimals' => 0];
@endphp

<x-layouts.app title="Reports">
    <div class="@container flex flex-col gap-5">
        <x-ds::page-header title="Reports" :description="'How Tidewater Ferries’ issues moved, '.$span.'.'">
            <x-slot:actions>
                <form method="GET" action="{{ route('reports.index') }}" class="flex flex-wrap items-end gap-3">
                    <div class="w-full sm:w-64">
                        <x-ds::date-picker name="period" label="Period" :range="true" :presets="true" :months="2" :confirm="true" :value="[$period['from'], $period['to']]" />
                    </div>
                    {{-- Down to the fields' middle line, as the picker carries a label above it. --}}
                    <x-ds::switch name="compare" value="1" label="Compare" :checked="$compare" :submitUnchecked="false" class="pb-2" />
                    <x-ds::button type="submit" variant="secondary">Update</x-ds::button>
                </form>
            </x-slot:actions>
        </x-ds::page-header>

        @if ($ready && $report['partial'])
            <x-ds::alert>{{ $report['partial'] }}</x-ds::alert>
        @endif

        <x-ds::skeleton-swap :loaded="$ready">
            <x-slot:placeholder>
                <x-ds::skeleton variant="block" size="sm" />
            </x-slot:placeholder>
            @if ($ready)
                <x-ds::metric-ticker label="Today so far" size="sm" :items="$report['today']" />
            @endif
        </x-ds::skeleton-swap>

        {{-- Two tiles a row in a narrow column, four from a wide one: container queries, so the sidebar's width counts. --}}
        <div class="grid grid-cols-1 gap-4 @md:grid-cols-2 @4xl:grid-cols-4">
            @if ($ready)
                @foreach ($report['kpis'] as $kpi)
                    @if ($compare)
                        <x-ds::stat-tile :label="$kpi['label']" :value="$kpi['value']" :delta="$kpi['delta']" :rising="$kpi['rising'] ?? 'good'" :caption="$kpi['previous'] ?? 'on '.$period['previous']" :countUp="false" />
                    @else
                        <x-ds::stat-tile :label="$kpi['label']" :value="$kpi['value']" :caption="$span" :countUp="false" />
                    @endif
                @endforeach
            @else
                @foreach (range(1, 4) as $tile)
                    <x-ds::skeleton variant="block" size="lg" />
                @endforeach
            @endif
        </div>

        <x-ds::panel title="Opened and closed each day" body="plain">
            <x-ds::skeleton-swap :loaded="$ready">
                <x-slot:placeholder><x-ds::skeleton variant="block" size="lg" /></x-slot:placeholder>
                @if ($ready)
                    <x-ds::line-chart
                        label="Issues opened and closed each day"
                        :data="$report['daily']"
                        :series="['Opened', 'Closed']"
                        height="lg"
                        curve="smooth"
                        :format="$number"
                        :table="true"
                        empty="Nothing was opened or closed in this period"
                    />
                @endif
            </x-ds::skeleton-swap>
        </x-ds::panel>

        <div class="grid gap-4 @3xl:grid-cols-3">
            <x-ds::panel title="Closed by project" body="plain">
                <x-ds::skeleton-swap :loaded="$ready">
                    <x-slot:placeholder><x-ds::skeleton :lines="5" /></x-slot:placeholder>
                    @if ($ready)
                        <x-ds::bar-chart label="Issues closed by project" :data="$report['byProject']" orientation="horizontal" height="sm" tone="accent" :showValues="true" :table="true" empty="No issue was closed" />
                    @endif
                </x-ds::skeleton-swap>
            </x-ds::panel>

            <x-ds::panel title="Open by priority" body="plain">
                <x-ds::skeleton-swap :loaded="$ready">
                    <x-slot:placeholder><x-ds::skeleton variant="circle" size="lg" /></x-slot:placeholder>
                    @if ($ready)
                        <x-ds::donut-chart label="Open issues by priority" :data="$report['byPriority']" size="sm" legend="bottom" totalLabel="Open" :table="true" empty="No open issues" />
                    @endif
                </x-ds::skeleton-swap>
            </x-ds::panel>

            <x-ds::panel title="From report to release" body="plain">
                <x-ds::skeleton-swap :loaded="$ready">
                    <x-slot:placeholder><x-ds::skeleton :lines="5" /></x-slot:placeholder>
                    @if ($ready)
                        <x-ds::funnel-chart label="Issues from report to release" :data="$report['flow']" height="sm" :table="true" empty="No issue was reported" />
                    @endif
                </x-ds::skeleton-swap>
            </x-ds::panel>
        </div>

        <div class="grid gap-4 @4xl:grid-cols-3">
            <section aria-labelledby="projects-heading" class="flex min-w-0 flex-col gap-3 @4xl:col-span-2">
                <h2 id="projects-heading" class="text-section text-fg">Busiest projects</h2>
                {{-- Skeleton rows under the real head while the report is on its way, so nothing moves when it lands. --}}
                <x-ds::table label="Busiest projects" :loading="! $ready" :columns="['Project', ['label' => 'Open', 'align' => 'right'], ['label' => 'Closed', 'align' => 'right'], ['label' => 'Median to close', 'align' => 'right'], 'Closed each week']">
                    @forelse ($ready ? $report['projects'] : [] as $project)
                        <x-ds::table-row>
                            <x-ds::table-cell :rowHeader="true">
                                <a href="{{ route('reports.projects.show', $project['key']) }}" class="rounded-chip hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus-ring">{{ $project['name'] }}</a>
                            </x-ds::table-cell>
                            <x-ds::table-cell align="right" class="tabular-nums">{{ $project['open'] }}</x-ds::table-cell>
                            <x-ds::table-cell align="right" class="tabular-nums">{{ $project['closed'] }}</x-ds::table-cell>
                            <x-ds::table-cell align="right" :nowrap="true">{{ $project['median'] }}</x-ds::table-cell>
                            <x-ds::table-cell>
                                <x-ds::sparkline :values="$project['trend']" variant="bar" width="sm" :label="'Closed each week in '.$project['name']" />
                            </x-ds::table-cell>
                        </x-ds::table-row>
                    @empty
                        <tr>
                            <td colspan="5"><x-ds::empty-state title="No project had any activity" :bare="true" /></td>
                        </tr>
                    @endforelse
                </x-ds::table>
            </section>

            <x-ds::panel title="Latest activity" body="plain">
                <x-ds::skeleton-swap :loaded="$ready">
                    <x-slot:placeholder><x-ds::skeleton :lines="6" /></x-slot:placeholder>
                    @if ($ready)
                        @if ($report['activity'])
                            <x-ds::timeline label="Latest activity" :dense="true">
                                @foreach ($report['activity'] as $event)
                                    <x-ds::timeline-item
                                        :avatar="$event['who']"
                                        :title="$event['who'].' '.$event['what']"
                                        :href="$event['issue'] ? route('issues.show', $event['issue']) : null"
                                        :time="$event['time']"
                                        :datetime="$event['at']"
                                        :tone="$event['tone']"
                                    />
                                @endforeach
                            </x-ds::timeline>
                        @else
                            <x-ds::empty-state title="Nothing happened" description="No issue was opened, moved or closed in this period." :bare="true" />
                        @endif
                    @endif
                </x-ds::skeleton-swap>
            </x-ds::panel>
        </div>

        <x-ds::panel :title="$ready ? $report['goals']['cycle'].' goals' : 'Goals'" body="plain">
            <x-ds::skeleton-swap :loaded="$ready">
                <x-slot:placeholder><x-ds::skeleton :lines="4" /></x-slot:placeholder>
                @if ($ready)
                    @php $goals = $report['goals']; @endphp
                    <div class="grid items-center gap-6 @3xl:grid-cols-3">
                        <div class="flex flex-col gap-4">
                            @foreach ($goals['progress'] as $goal)
                                <x-ds::progress :label="$goal['label']" :value="$goal['value']" :max="$goal['max']" tone="accent" :showValue="true">{{ $goal['value'] }} of {{ $goal['max'] }}</x-ds::progress>
                            @endforeach
                        </div>
                        <x-ds::activity-rings label="This week" :rings="$goals['rings']" size="sm" :table="true" />
                        <x-ds::gauge
                            label="Questions answered within a day"
                            :value="$goals['answered']"
                            :format="['suffix' => '%']"
                            :thresholds="[['at' => 0, 'tone' => 'danger', 'label' => 'well short'], ['at' => 80, 'tone' => 'warning', 'label' => 'short'], ['at' => 90, 'tone' => 'success', 'label' => 'on target']]"
                        />
                    </div>
                @endif
            </x-ds::skeleton-swap>
        </x-ds::panel>
    </div>
</x-layouts.app>

Wire it up

The route and the report

use App\Http\Controllers\ReportController;

Route::middleware('auth')->group(function () {
    Route::get('reports', [ReportController::class, 'index'])->name('reports.index');
    Route::get('reports/projects/{project}', [ReportController::class, 'project'])->name('reports.projects.show');
});

The controller reads the period, works out the one before it (as many days, ending the day before), and passes the view three things:

public function index(Request $request, ReportBuilder $reports)
{
    $request->validate([
        'period_start' => ['nullable', 'date'],
        'period_end' => ['nullable', 'date', 'after_or_equal:period_start'],
    ]);
    $to = $request->date('period_end') ?? today();
    $from = $request->date('period_start') ?? $to->copy()->startOfMonth();
    $days = $from->diffInDays($to) + 1;
    $previous = [$from->copy()->subDays($days), $from->copy()->subDay()];

    return view('reports.index', [
        'period' => [
            'from' => $from->toDateString(),
            'to' => $to->toDateString(),
            'previous' => $previous[0]->format('j').'–'.$previous[1]->format('j F'),
        ],
        // The switch posts nothing when off, so a first visit (no period
        // in the query) compares and a submitted form follows the switch.
        'compare' => $request->has('period_start') ? $request->boolean('compare') : true,
        'report' => $reports->for($request->user()->currentWorkspace, $from, $to, $previous),
    ]);
}

ReportBuilder is a class of your own. What it returns, every chart's data an array of label => number in the order to draw it:

KeyWhat it is
kpisfour of label, value (a number, or words such as "2.4 days"), delta (the change in per cent, or null for none), rising (bad where less is better, such as time to close; optional) and previous (a caption to use instead of "on 2–31 October", or null)
todaythe ticker's items: label, value, trend (numbers through the day) and tone
dailyday => ['Opened' => n, 'Closed' => n], one per day of the period
byProject, byPriority, flowname => count, for the bars, the donut and the funnel
projectskey, name, open, closed, median (words) and trend (closed each week)
activitywho, what, issue (a key to link, or null), time (words) and at (ISO 8601)
goalscycle, progress and rings (each label, value, max), and answered (a per cent)
partialthe line saying the last day is still under way, or null

Cache each report for a few minutes by workspace and period: the queries behind it are the expensive part of the page, and the alert says how fresh the numbers are.

Loading, with Livewire

Rendered by a controller, the page has no loading state: it arrives with its numbers. The skeletons are for a Livewire component that renders the frame at once and fills it after, with wire:init, so a slow report does not hold up the page:

use Livewire\Attributes\Url;
use Livewire\Component;

class ReportsPage extends Component
{
    #[Url] public ?string $period_start = null;
    #[Url] public ?string $period_end = null;
    #[Url] public bool $compare = true;
    public ?array $report = null;

    public function load(ReportBuilder $reports): void
    {
        $this->report = $reports->for(/* as above */);
    }

    public function updated(): void
    {
        $this->report = null;   // the skeletons, until load() answers
        $this->load(app(ReportBuilder::class));
    }
}
<div wire:init="load" class="@container flex flex-col gap-5">
    …
    <x-ds::metric-ticker label="Today so far" size="sm" :items="$report['today']" wire:poll.60s="refreshToday" />

The ticker passes its attributes to its root, so wire:poll there keeps today's figures current without reloading the rest. This recipe was written against the components' documented hooks, not run in a Livewire app.

Phone, keyboard, no script

  • Phone: one column. The period's controls wrap under the title, the tiles go one to a row, and each chart takes the full width; the line chart labels fewer days on its axis. The busiest projects table scrolls sideways inside its own box. The grid uses container queries (@md:, @3xl:, @4xl:), so with the sidebar open the columns follow the room the page has, not the window's width.
  • Keyboard: the period, the compare switch and Update; then only the links, each project's name and each activity's issue. The charts are images with a text alternative, not stops on the way, and their values tables are read, not tabbed to.
  • No script: everything shows and everything works. The charts, sparklines, rings and gauge are SVG drawn on the server; the period is a GET form, and without the script the date picker is two native date fields posting period_start and period_end. Only the picker's calendar and presets need the script.
  • One workaround in the view: the row of three charts is relative overflow-clip, because a chart's visually hidden values table keeps its width (a table ignores sr-only's 1px) and, at the right edge, scrolled the whole page sideways.

From the package repo: edit this page on GitHub.

Was this page helpful?