Skip to content
Brok UI

Loading…

No results

Metrics

Open source

Dashboard analytics cards — a traffic trend card with a range control, a KPI performance row with sparklines, a sales-by-channel distribution, a weekly-traffic heatmap and a spending breakdown with a segmented bar and table.

Preview

4 of 5

resources/views/blocks/metrics-heatmap.blade.php Blade
@props([
    'heading' => 'Weekly Traffic',
    'subheading' => 'Traffic intensity by hour and day',
    'days' => null,
    'buckets' => null,
    'data' => null,
])

@php
    $days ??= [__('Mon'), __('Tue'), __('Wed'), __('Thu'), __('Fri'), __('Sat'), __('Sun')];
    $buckets ??= ['00–03', '03–06', '06–09', '09–12', '12–15', '15–18', '18–21', '21–24'];

    // 7 rows (Mon..Sun) x 8 cols (time buckets) of intensity levels 0..4.
    // Weekdays: quiet overnight, ramps up through the morning, peaks mid-day/afternoon,
    // tapers into the evening. Weekends: lower overall, later & flatter.
    $data ??= [
        [0, 0, 2, 3, 4, 4, 3, 1], // Mon
        [0, 0, 2, 3, 4, 4, 3, 1], // Tue
        [0, 1, 2, 4, 4, 3, 3, 2], // Wed
        [0, 0, 2, 3, 4, 4, 3, 2], // Thu
        [0, 0, 2, 3, 4, 3, 2, 1], // Fri
        [1, 0, 1, 2, 3, 3, 2, 2], // Sat
        [1, 0, 1, 2, 2, 2, 1, 1], // Sun
    ];

    $levelClass = [
        0 => 'bg-muted',
        1 => 'bg-success/30',
        2 => 'bg-success/50',
        3 => 'bg-success/75',
        4 => 'bg-success',
    ];

    $levelLabels = [
        0 => __('No activity'),
        1 => __('Low'),
        2 => __('Moderate'),
        3 => __('High'),
        4 => __('Very high'),
    ];
@endphp

<x-ui.card {{ $attributes->merge(['class' => 'w-full']) }}>
    <div class="flex flex-col gap-2 p-6 pb-4">
        <h3 class="text-base font-semibold text-foreground">{{ __($heading) }}</h3>
        <p class="text-sm text-muted-foreground">{{ __($subheading) }}</p>
    </div>

    <div class="px-6 pb-6">
        <div class="overflow-x-auto">
            <div
                role="img"
                aria-label="{{ __('Weekly traffic heatmap') }}"
                class="grid min-w-[28rem] gap-2"
                style="grid-template-columns: auto repeat(8, minmax(0, 1fr));"
            >
                {{-- Header row: empty corner + bucket labels --}}
                <div aria-hidden="true"></div>
                @foreach ($buckets as $bucket)
                    <div class="text-center text-xs text-muted-foreground" aria-hidden="true">
                        {{ $bucket }}
                    </div>
                @endforeach

                {{-- Day rows --}}
                @foreach ($data as $i => $row)
                    <div class="flex items-center pe-2 text-end text-xs text-muted-foreground" aria-hidden="true">
                        {{ $days[$i] ?? '' }}
                    </div>
                    @foreach ($row as $j => $lvl)
                        @php $level = (int) $lvl; @endphp
                        <div
                            class="aspect-square rounded-sm {{ $levelClass[$level] ?? $levelClass[0] }}"
                            title="{{ ($days[$i] ?? '') . ' ' . ($buckets[$j] ?? '') . ' — ' . ($levelLabels[$level] ?? '') }}"
                        ></div>
                    @endforeach
                @endforeach
            </div>
        </div>

        {{-- Legend --}}
        <div class="mt-4 flex items-center gap-2 text-xs text-muted-foreground">
            <span class="ms-auto">{{ __('Low') }}</span>
            <span class="flex items-center gap-2" aria-hidden="true">
                <span class="size-3 rounded-sm bg-muted"></span>
                <span class="size-3 rounded-sm bg-success/30"></span>
                <span class="size-3 rounded-sm bg-success/50"></span>
                <span class="size-3 rounded-sm bg-success/75"></span>
                <span class="size-3 rounded-sm bg-success"></span>
            </span>
            <span>{{ __('High') }}</span>
        </div>
    </div>
</x-ui.card>

Installation

terminal
php artisan ui:add blocks/metrics-heatmap

Installs these dependencies automatically:

Registry contract

Install confidence

php artisan ui:add blocks/metrics-heatmap writes only the generated targets below. The CLI validates each file hash before writing and prompts before replacing local changes unless --force is used.

Version
1.0.3
License
open
Stability
stable
Contract
v1
Foundation
≥ 1.0.0
Type Generated target
blade resources/views/blocks/metrics-heatmap.blade.php

Registry dependencies

card

Package dependencies

composer: jml/brok:^0.2

Use with AI

A brief for your coding agent: what the block is, the install command, how to render it, its props and the rules. Copy it, or open a prompt about this block in an assistant.

metrics-heatmap.md
# Brok UI block: Metric Heatmap (`metrics-heatmap`)

A weekly-traffic heatmap card showing intensity by weekday and time-of-day bucket, with a token-themed colour scale and a low-to-high legend.

Brok UI is a Laravel Blade registry. `ui:add` copies this block into the app as plain Blade the app owns; it composes installed `<brok:*>` primitives and semantic design tokens.

## Install

```bash
php artisan ui:add blocks/metrics-heatmap
```

## Render it

```blade
<x-blocks.metrics-heatmap />
```

## Props

- `heading` (string, default `Weekly Traffic`) — Card title.
- `subheading` (string, default `Traffic intensity by hour and day`) — Supporting copy under the heading.
- `days` (mixed|null, default `null`) — Weekday row labels; null falls back to Mon-Sun.
- `buckets` (mixed|null, default `null`) — Time-of-day column labels; null falls back to eight three-hour buckets.
- `data` (mixed|null, default `null`) — 7x8 grid of intensity levels 0-4, day rows by time-bucket columns; null falls back to a sample week.

## Use when

- Visualising traffic or activity intensity across weekday and time-of-day buckets as a coloured grid.
- Pairing the grid with a low-to-high legend and a per-cell tooltip.

## Avoid when

- Needing a geographic density heatmap instead of a weekday/time-bucket grid; use maps-heatmap.

## Rules

- Render the installed block with `<x-blocks.metrics-heatmap />` and pass data through its props; edit the copied file only for structural changes.
- Keep the semantic design tokens (`bg-background`, `text-muted-foreground`); never swap in raw colour utilities.
- Keep the `data-slot` attributes and the logical (start/end) spacing so the markup still mirrors under `dir="rtl"`.

## Links

- Docs: https://brokui.dev/blocks/metrics-heatmap
- Registry JSON (files, props, contract): https://brokui.dev/r/open/blocks/metrics-heatmap.json

Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.

Guidance

Use when

  • Visualising traffic or activity intensity across weekday and time-of-day buckets as a coloured grid.
  • Pairing the grid with a low-to-high legend and a per-cell tooltip.

Avoid when

  • Needing a geographic density heatmap instead of a weekday/time-bucket grid; use maps-heatmap.

Anti-patterns

  • Do not replace semantic props with conflicting utility classes.
  • Do not remove labels, focus styles, or state attributes.
Anatomy
header weekday x time-bucket intensity grid low-to-high legend

Usage

Render the block as a component, passing data where useful:

resources/views/welcome.blade.php Blade
<x-blocks.metrics-heatmap />

Built from primitives

Composes <brok:*> Semantic tokens Re-themeable RTL-ready

This block composes installed <brok:*> primitives and semantic design tokens only — it does not reimplement any primitive. Re-theme it (light, dark, admin, customer) by editing CSS variables; flip the preview to RTL to confirm it mirrors.

Source

The exact, editable file ui:add writes into your app. The preview above renders this same source — there are no preview-only blocks.

resources/views/blocks/metrics-heatmap.blade.php Blade
@props([
    'heading' => 'Weekly Traffic',
    'subheading' => 'Traffic intensity by hour and day',
    'days' => null,
    'buckets' => null,
    'data' => null,
])

@php
    $days ??= [__('Mon'), __('Tue'), __('Wed'), __('Thu'), __('Fri'), __('Sat'), __('Sun')];
    $buckets ??= ['00–03', '03–06', '06–09', '09–12', '12–15', '15–18', '18–21', '21–24'];

    // 7 rows (Mon..Sun) x 8 cols (time buckets) of intensity levels 0..4.
    // Weekdays: quiet overnight, ramps up through the morning, peaks mid-day/afternoon,
    // tapers into the evening. Weekends: lower overall, later & flatter.
    $data ??= [
        [0, 0, 2, 3, 4, 4, 3, 1], // Mon
        [0, 0, 2, 3, 4, 4, 3, 1], // Tue
        [0, 1, 2, 4, 4, 3, 3, 2], // Wed
        [0, 0, 2, 3, 4, 4, 3, 2], // Thu
        [0, 0, 2, 3, 4, 3, 2, 1], // Fri
        [1, 0, 1, 2, 3, 3, 2, 2], // Sat
        [1, 0, 1, 2, 2, 2, 1, 1], // Sun
    ];

    $levelClass = [
        0 => 'bg-muted',
        1 => 'bg-success/30',
        2 => 'bg-success/50',
        3 => 'bg-success/75',
        4 => 'bg-success',
    ];

    $levelLabels = [
        0 => __('No activity'),
        1 => __('Low'),
        2 => __('Moderate'),
        3 => __('High'),
        4 => __('Very high'),
    ];
@endphp

<x-ui.card {{ $attributes->merge(['class' => 'w-full']) }}>
    <div class="flex flex-col gap-2 p-6 pb-4">
        <h3 class="text-base font-semibold text-foreground">{{ __($heading) }}</h3>
        <p class="text-sm text-muted-foreground">{{ __($subheading) }}</p>
    </div>

    <div class="px-6 pb-6">
        <div class="overflow-x-auto">
            <div
                role="img"
                aria-label="{{ __('Weekly traffic heatmap') }}"
                class="grid min-w-[28rem] gap-2"
                style="grid-template-columns: auto repeat(8, minmax(0, 1fr));"
            >
                {{-- Header row: empty corner + bucket labels --}}
                <div aria-hidden="true"></div>
                @foreach ($buckets as $bucket)
                    <div class="text-center text-xs text-muted-foreground" aria-hidden="true">
                        {{ $bucket }}
                    </div>
                @endforeach

                {{-- Day rows --}}
                @foreach ($data as $i => $row)
                    <div class="flex items-center pe-2 text-end text-xs text-muted-foreground" aria-hidden="true">
                        {{ $days[$i] ?? '' }}
                    </div>
                    @foreach ($row as $j => $lvl)
                        @php $level = (int) $lvl; @endphp
                        <div
                            class="aspect-square rounded-sm {{ $levelClass[$level] ?? $levelClass[0] }}"
                            title="{{ ($days[$i] ?? '') . ' ' . ($buckets[$j] ?? '') . ' — ' . ($levelLabels[$level] ?? '') }}"
                        ></div>
                    @endforeach
                @endforeach
            </div>
        </div>

        {{-- Legend --}}
        <div class="mt-4 flex items-center gap-2 text-xs text-muted-foreground">
            <span class="ms-auto">{{ __('Low') }}</span>
            <span class="flex items-center gap-2" aria-hidden="true">
                <span class="size-3 rounded-sm bg-muted"></span>
                <span class="size-3 rounded-sm bg-success/30"></span>
                <span class="size-3 rounded-sm bg-success/50"></span>
                <span class="size-3 rounded-sm bg-success/75"></span>
                <span class="size-3 rounded-sm bg-success"></span>
            </span>
            <span>{{ __('High') }}</span>
        </div>
    </div>
</x-ui.card>

Ownership & lifecycle

Owner, release state, review evidence and adoption for this item.
Owner
Platform UI (@JoshJML)
Current version
1.0.3
Status
Stable
License
open
Deprecation
Not deprecated
Contract
v1
Foundation
≥ 1.0.0