Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ Built with React 19, Vite, MapLibre GL (through `react-map-gl`), deck.gl (`@deck
- **Sea ports layer:** the bundled ports GeoJSON, drawn as green points. Click a point to see its properties.
- **Heatmap layer (WebGPU only):** a two-pass compute shader bins airport positions into a 1024 x 512 grid and colorizes it into a bitmap overlay. It runs once, after the airports load. The layer toggle appears only after that compute succeeds, so it is hidden while airports load, when WebGPU is unavailable, and when the airports fetch or the compute fails.
- **Stress test:** a slider from 0 to 5,000,000 points in steps of 100,000. Points are generated on the main thread 150 ms after the slider stops moving, then drawn as a deck.gl binary attribute layer.
- **GPU info panel:** adapter name, render tier (`WebGPU`, `WebGL Fallback`, or `Detecting...`), active point count, frame time with a 60-frame sparkline, compute throughput (a 64 MB storage buffer read and written once per second, reported in GB/s), and heatmap compute time.
- **GPU info panel:** adapter name, render tier (`WebGPU`, `WebGL Fallback`, or `Detecting...`), active point count, frame time with a 60-frame sparkline, compute throughput (a 64 MB storage buffer read and written once per second, reported in GB/s), and heatmap compute time. At 1024px wide or less it shows only the render tier, active point count, and frame time. On small screens (see below) it is hidden while a feature popup is open.
- **Small screens** (640px wide or less, or up to 1024px wide and 500px tall or less): the layer panel starts collapsed behind a "Sensor layers" button, the header drops the coordinates and status, and the feature popup opens as a bottom sheet.

## Requirements

- **Node.js:** current LTS (CI uses `lts/*`). Vite 8 needs Node 20.19+ or 22.12+.
- **Browser:** any browser with WebGL 2 for the map and point layers. deck.gl draws through WebGL; WebGPU is used only for compute.
- **WebGPU (optional):** needed for the heatmap and the COMPUTE readout. Use a browser and GPU where `navigator.gpu.requestAdapter()` returns an adapter, for example current Chrome or Edge on desktop. Without it the app still runs: the panel shows `WebGL Fallback`, the heatmap toggle never appears, and COMPUTE shows `--`.
- **WebGPU (optional):** needed for the heatmap and the COMPUTE readout. Use a browser and GPU where `navigator.gpu.requestAdapter()` returns an adapter, for example current Chrome or Edge on desktop. Without it the app still runs: the panel shows `WebGL Fallback`, the heatmap toggle never appears, and on screens wider than 1024px COMPUTE shows `--`.
- **Network access:** the basemap style and tiles come from CARTO and the airports CSV comes from GitHub at runtime. The ports data is bundled.

## Setup from a clean clone
Expand Down Expand Up @@ -62,7 +63,7 @@ src/
components/ MapView (MapLibre + deck.gl), LayerPanel, GPUInfoPanel, FeaturePopup
config/ data URLs, layer ids, basemap style, MapLibre worker setup
hooks/ data loading (useAirports, usePorts), WebGPU (useGPUCapabilities,
useGPUCompute, useGPUHeatmap), useStressPoints
useGPUCompute, useGPUHeatmap), useStressPoints, useMediaQuery
layers/index.js buildLayers(): visibility and data to deck.gl layers
store/mapStore.js zustand store: viewport, layer visibility, stress count, selection
public/data/ports.geojson bundled ports data
Expand Down
83 changes: 83 additions & 0 deletions docs/plans/2026-11-07-issue-5-layout-breaks-on-mobile.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/components/GPUInfoPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function GPUInfoPanel({ capabilities }) {

return (
<div className="gpu-info-panel">
<span className="gpu-info-item">
<span className="gpu-info-item gpu-info-secondary">
<span className="gpu-info-key">GPU</span>
<span className="gpu-info-val">{deviceLabel}</span>
</span>
<span className="gpu-info-sep">|</span>
<span className="gpu-info-sep gpu-info-secondary">|</span>
<span className="gpu-info-item">
<span className="gpu-info-key">RENDER</span>
<span className={`gpu-info-val ${isWebGPU ? 'ok' : 'warn'}`}>{renderLabel}</span>
Expand All @@ -64,13 +64,13 @@ export function GPUInfoPanel({ capabilities }) {
<Sparkline history={frameHistory} />
</span>
</span>
<span className="gpu-info-sep">|</span>
<span className="gpu-info-item">
<span className="gpu-info-sep gpu-info-secondary">|</span>
<span className="gpu-info-item gpu-info-secondary">
<span className="gpu-info-key">COMPUTE</span>
<span className="gpu-info-val">{gpuThroughput}</span>
</span>
<span className="gpu-info-sep">|</span>
<span className="gpu-info-item">
<span className="gpu-info-sep gpu-info-secondary">|</span>
<span className="gpu-info-item gpu-info-secondary">
<span className="gpu-info-key">HEATMAP</span>
<span className="gpu-info-val">
{heatmapComputeMs != null ? `${heatmapComputeMs} ms` : '--'}
Expand Down
22 changes: 21 additions & 1 deletion src/components/GPUInfoPanel.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,24 @@ describe('GPUInfoPanel', () => {
render(<GPUInfoPanel capabilities={{ ...base, heatmapComputeMs: null }} />)
expect(screen.getByText('HEATMAP')).toBeInTheDocument()
})
})
})
describe('GPUInfoPanel secondary stats', () => {
it('marks GPU, COMPUTE, and HEATMAP as secondary and keeps RENDER, PTS, FRAME primary', () => {
render(<GPUInfoPanel capabilities={{ ...base, heatmapComputeMs: 42 }} />)
const item = (key) => screen.getByText(key).closest('.gpu-info-item')
for (const key of ['GPU', 'COMPUTE', 'HEATMAP']) {
expect(item(key)).toHaveClass('gpu-info-secondary')
}
for (const key of ['RENDER', 'PTS', 'FRAME']) {
expect(item(key)).not.toHaveClass('gpu-info-secondary')
}
})

it('leaves only the separators between RENDER, PTS, and FRAME primary', () => {
const { container } = render(<GPUInfoPanel capabilities={base} />)
const visible = Array.from(container.querySelector('.gpu-info-panel').children)
.filter((el) => !el.classList.contains('gpu-info-secondary'))
.map((el) => (el.classList.contains('gpu-info-sep') ? '|' : el.querySelector('.gpu-info-key').textContent))
expect(visible).toEqual(['RENDER', '|', 'PTS', '|', 'FRAME'])
})
})
123 changes: 74 additions & 49 deletions src/components/LayerPanel.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useId, useState } from 'react'
import { LAYERS } from '../config/sources.js'
import { useMapStore } from '../store/mapStore.js'
import { useMediaQuery, NARROW_QUERY } from '../hooks/useMediaQuery.js'

const LAYER_COLORS = {
airports: 'var(--amber)',
Expand All @@ -19,6 +21,10 @@ function formatValueText(n) {

export function LayerPanel({ visibility, onToggle, heatmapSupported }) {
const { stressCount, setStressCount } = useMapStore()
const narrow = useMediaQuery(NARROW_QUERY)
const [open, setOpen] = useState(false)
const bodyId = useId()
const expanded = !narrow || open

const layerList = Object.values(LAYERS).filter(
({ id }) => id !== 'heatmap' || heatmapSupported
Expand All @@ -27,60 +33,79 @@ export function LayerPanel({ visibility, onToggle, heatmapSupported }) {
const totalCount = layerList.length

return (
<aside className="layer-panel">
<div className="panel-header">
<span className="panel-title">SENSOR LAYERS</span>
<span className="panel-indicator" />
</div>
<aside className={`layer-panel${expanded ? '' : ' collapsed'}`}>
{narrow ? (
<button
type="button"
className="panel-header panel-toggle"
aria-expanded={open}
aria-controls={bodyId}
aria-label="Sensor layers"
onClick={() => setOpen((o) => !o)}
>
<span className="panel-title">SENSOR LAYERS</span>
<span className="panel-chevron" aria-hidden="true">
{open ? '\u25B2' : '\u25BC'}
</span>
<span className="panel-indicator" />
</button>
) : (
<div className="panel-header">
<span className="panel-title">SENSOR LAYERS</span>
<span className="panel-indicator" />
</div>
)}

{layerList.map(({ id, label }) => {
const active = visibility[id] ?? true
return (
<label key={id} className={`layer-row${active ? ' active' : ''}`}>
<input
type="checkbox"
className="visually-hidden"
aria-label={`${label} layer`}
checked={active}
onChange={(e) => onToggle(id, e.target.checked)}
/>
<span
className="layer-dot"
aria-hidden="true"
style={{ background: active ? LAYER_COLORS[id] : 'var(--text-dim)' }}
/>
<span className="layer-label">{label.toUpperCase()}</span>
<span className={`layer-toggle ${active ? 'on' : 'off'}`} aria-hidden="true">
{active ? 'ON' : 'OFF'}
</span>
</label>
)
})}
<div id={bodyId} className="panel-body" hidden={!expanded}>
{layerList.map(({ id, label }) => {
const active = visibility[id] ?? true
return (
<label key={id} className={`layer-row${active ? ' active' : ''}`}>
<input
type="checkbox"
className="visually-hidden"
aria-label={`${label} layer`}
checked={active}
onChange={(e) => onToggle(id, e.target.checked)}
/>
<span
className="layer-dot"
aria-hidden="true"
style={{ background: active ? LAYER_COLORS[id] : 'var(--text-dim)' }}
/>
<span className="layer-label">{label.toUpperCase()}</span>
<span className={`layer-toggle ${active ? 'on' : 'off'}`} aria-hidden="true">
{active ? 'ON' : 'OFF'}
</span>
</label>
)
})}

<div className="panel-divider" />
<div className="panel-divider" />

<div className="stress-section">
<span className="panel-title">STRESS TEST</span>
<div className="stress-row">
<input
type="range"
min={0}
max={5000000}
step={100000}
value={stressCount}
onChange={(e) => setStressCount(Number(e.target.value))}
className="stress-slider"
aria-label="Stress test point count"
aria-valuetext={formatValueText(stressCount)}
/>
<span className="stress-count">{formatCount(stressCount)}</span>
<div className="stress-section">
<span className="panel-title">STRESS TEST</span>
<div className="stress-row">
<input
type="range"
min={0}
max={5000000}
step={100000}
value={stressCount}
onChange={(e) => setStressCount(Number(e.target.value))}
className="stress-slider"
aria-label="Stress test point count"
aria-valuetext={formatValueText(stressCount)}
/>
<span className="stress-count">{formatCount(stressCount)}</span>
</div>
</div>
</div>

<div className="panel-footer">
<span className="footer-stat">
ACTIVE&nbsp;{activeCount}/{totalCount}
</span>
<div className="panel-footer">
<span className="footer-stat">
ACTIVE&nbsp;{activeCount}/{totalCount}
</span>
</div>
</div>
</aside>
)
Expand Down
105 changes: 104 additions & 1 deletion src/components/LayerPanel.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { LayerPanel } from './LayerPanel.jsx'
import { LAYERS } from '../config/sources.js'
import { useMapStore } from '../store/mapStore.js'
import { NARROW_QUERY } from '../hooks/useMediaQuery.js'

const visibility = { airports: true, ports: true }

Expand Down Expand Up @@ -192,3 +193,105 @@ describe('LayerPanel keyboard and screen reader access', () => {
expect(slider).toHaveAttribute('aria-valuetext', '100,000 points')
})
})

function stubMatchMedia(matches) {
vi.stubGlobal(
'matchMedia',
vi.fn((query) => ({
matches: query === NARROW_QUERY ? matches : false,
media: query,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
}))
)
}

describe('LayerPanel on narrow screens', () => {
const allOn = { airports: true, ports: true, heatmap: true }

beforeEach(() => {
stubMatchMedia(true)
})

afterEach(() => {
vi.unstubAllGlobals()
})

it('renders a collapsed Sensor layers toggle that controls the panel body', () => {
const { container } = render(
<LayerPanel visibility={allOn} onToggle={vi.fn()} heatmapSupported={true} />
)
const toggle = screen.getByRole('button', { name: 'Sensor layers' })
expect(toggle).toHaveAttribute('type', 'button')
expect(toggle).toHaveAttribute('aria-expanded', 'false')
const bodyId = toggle.getAttribute('aria-controls')
expect(bodyId).toBeTruthy()
const body = container.querySelector(`[id="${bodyId}"]`)
expect(body).toBeInTheDocument()
expect(body).toHaveAttribute('hidden')
expect(container.querySelector('.layer-panel')).toHaveClass('collapsed')
})

it('keeps the layer checkboxes and slider out of the accessibility tree when collapsed', () => {
render(<LayerPanel visibility={allOn} onToggle={vi.fn()} heatmapSupported={true} />)
expect(screen.queryByRole('checkbox', { name: 'Airports layer' })).not.toBeInTheDocument()
expect(screen.queryByRole('slider', { name: 'Stress test point count' })).not.toBeInTheDocument()
})

it('expands on click and collapses on a second click', async () => {
const user = userEvent.setup()
const { container } = render(
<LayerPanel visibility={allOn} onToggle={vi.fn()} heatmapSupported={true} />
)
const toggle = screen.getByRole('button', { name: 'Sensor layers' })
await user.click(toggle)
expect(toggle).toHaveAttribute('aria-expanded', 'true')
expect(screen.getByRole('checkbox', { name: 'Airports layer' })).toBeInTheDocument()
expect(screen.getByRole('slider', { name: 'Stress test point count' })).toBeInTheDocument()
expect(container.querySelector('.layer-panel')).not.toHaveClass('collapsed')
await user.click(toggle)
expect(toggle).toHaveAttribute('aria-expanded', 'false')
expect(screen.queryByRole('checkbox', { name: 'Airports layer' })).not.toBeInTheDocument()
})

it('focuses the toggle first with Tab and toggles with Enter and Space', async () => {
const user = userEvent.setup()
render(<LayerPanel visibility={allOn} onToggle={vi.fn()} heatmapSupported={true} />)
await user.tab()
const toggle = screen.getByRole('button', { name: 'Sensor layers' })
expect(toggle).toHaveFocus()
await user.keyboard('{Enter}')
expect(toggle).toHaveAttribute('aria-expanded', 'true')
await user.keyboard(' ')
expect(toggle).toHaveAttribute('aria-expanded', 'false')
await user.keyboard(' ')
expect(toggle).toHaveAttribute('aria-expanded', 'true')
await user.tab()
expect(screen.getByRole('checkbox', { name: 'Airports layer' })).toHaveFocus()
})
})

describe('LayerPanel on wide screens', () => {
const allOn = { airports: true, ports: true, heatmap: true }

afterEach(() => {
vi.unstubAllGlobals()
})

it('renders no toggle and shows the checkboxes when the query does not match', () => {
stubMatchMedia(false)
const { container } = render(
<LayerPanel visibility={allOn} onToggle={vi.fn()} heatmapSupported={true} />
)
expect(screen.queryByRole('button', { name: 'Sensor layers' })).not.toBeInTheDocument()
expect(screen.getByRole('checkbox', { name: 'Airports layer' })).toBeInTheDocument()
expect(container.querySelector('.layer-panel')).not.toHaveClass('collapsed')
})

it('renders no toggle and shows the checkboxes without matchMedia', () => {
vi.stubGlobal('matchMedia', undefined)
render(<LayerPanel visibility={allOn} onToggle={vi.fn()} heatmapSupported={true} />)
expect(screen.queryByRole('button', { name: 'Sensor layers' })).not.toBeInTheDocument()
expect(screen.getByRole('checkbox', { name: 'Airports layer' })).toBeInTheDocument()
})
})
27 changes: 27 additions & 0 deletions src/hooks/useMediaQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useCallback, useSyncExternalStore } from 'react'

export const NARROW_QUERY = '(max-width: 640px), (max-width: 1024px) and (max-height: 500px)'

function hasMatchMedia() {
return typeof window !== 'undefined' && typeof window.matchMedia === 'function'
}

function getServerSnapshot() {
return false
}

export function useMediaQuery(query) {
const subscribe = useCallback(
(onChange) => {
if (!hasMatchMedia()) return () => {}
const mql = window.matchMedia(query)
mql.addEventListener('change', onChange)
return () => mql.removeEventListener('change', onChange)
},
[query]
)

const getSnapshot = () => (hasMatchMedia() ? window.matchMedia(query).matches : false)

return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
}
Loading
Loading