feat(fires): FRP intensity filter, confidence switch and six-stop color ramp (HAL-676)

Color every FIRMS detection by fire radiative power on the Portolan
cold → hot ramp (blue · teal · lime · amber · orange · red at
0 · 5 · 20 · 50 · 100 · 300 MW), replacing the three warm stops that
made a 2 MW and a 40 MW fire look alike. Heat cells, glow sprites and
card accents all read the same ramp (src/data/firmsIntensity.js).

Add a minimum-FRP log slider whose track is painted with the ramp (so
it doubles as the legend), an All / Nominal+ / High confidence switch
and an "N of M shown" counter to the Active Fires row. The filter runs
once in ingestion.applyFilter(), so markers, cards, heat cells, the
context store, the top-fires query and the analyst records all see one
set. Default is 0 MW / All: many of the strongest fires are rated low.

Persist both options in the layer state (token w: minFrp `f`,
confidence `c`), including the short share codec, and give the agent's
get_active_fires tool matching min_frp_mw / confidence arguments.

Layer panel gains generic `slider` and `segmented` row descriptors
(src/ui/rowFilterControls.js). New strings in es / ru / zh-CN.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
German KhokhlovandClaude Fable 5.1 committed 2026-10-27 13:09:32 +04:00
1 parent 15de9d738c
commit 38d29f2beb
27 files changed
+1500 -70

No files matched your search

+48 -6
View File
@@ -1,4 +1,5 @@
import { syncChipGroup } from './chipGroup.js';
import { syncSegmentedGroup, syncSliderBlock } from './rowFilterControls.js';
import { syncRowList } from './rowList.js';
import { layerFeedState } from '../data/feedState.js';
export { layerFeedState } from '../data/feedState.js';
@@ -388,18 +389,42 @@ export class LayerPanel {
const controls = document.createElement('div');
controls.className = 'data-toggle-controls';
this._bind(controls, 'click', (event) => {
const button = event.target?.closest?.('.data-toggle-chip');
const button =
event.target?.closest?.('.data-toggle-chip') ||
event.target?.closest?.('.data-toggle-segment');
if (!button || button.disabled) return;
// Re-read the live descriptor rather than trusting the rendered
// chip, so a stale row can never apply an inverted toggle.
const chip = this._rowControlsFor(layer.id)?.chips?.find(
(entry) => entry.id === button.dataset.chipId,
);
const live = this._rowControlsFor(layer.id);
const chip =
live?.chips?.find(
(entry) => entry.id === button.dataset.chipId,
) ||
live?.segmented?.options?.find(
(entry) => entry.id === button.dataset.chipId,
);
if (!chip || chip.disabled || !this.isEnabled(layer.id)) return;
if (typeof chip.onClick === 'function') chip.onClick();
else if (chip.params)
this.setLayerParams(layer.id, chip.params, { origin: 'user' });
});
// A row slider (e.g. the Active Fires minimum-FRP filter) maps its
// position to params through the live descriptor on every tick.
this._bind(controls, 'input', (event) => {
const input = event.target;
if (!input?.matches?.('.data-toggle-slider-input')) return;
const slider = this._rowControlsFor(layer.id)?.slider;
if (
!slider ||
slider.id !== input.dataset.sliderId ||
typeof slider.params !== 'function' ||
!this.isEnabled(layer.id)
)
return;
this.setLayerParams(layer.id, slider.params(input.value), {
origin: 'user',
});
});
row.appendChild(controls);
// An ordered list below the chips, for a layer whose row carries a
// sequence (turn-by-turn directions). Its own delegated listener, its
@@ -521,13 +546,30 @@ export class LayerPanel {
const chips = controls?.chips || [];
const legend = controls?.legend || [];
const infoText = controls?.info;
const slider = controls?.slider || null;
const segmented = controls?.segmented || null;
this._syncRowList(listContainer, controls?.list || null);
container.hidden = chips.length === 0 && legend.length === 0 && !infoText;
container.hidden =
chips.length === 0 &&
legend.length === 0 &&
!infoText &&
!slider &&
!segmented;
const info = container._rowControlsInfo || null;
const firstLegend = container.querySelector('.data-toggle-legend-item');
syncChipGroup(container, chips, { before: firstLegend || info });
// Order: chips, switch, slider, legend, info.
syncSegmentedGroup(container, segmented, { before: firstLegend || info });
const switchNode = container.querySelector('.data-toggle-segmented');
syncSliderBlock(container, slider, {
before: switchNode?.nextSibling || firstLegend || info,
});
const firstControl =
switchNode || container.querySelector('.data-toggle-slider');
syncChipGroup(container, chips, {
before: firstControl || firstLegend || info,
});
const legendSignature = JSON.stringify(
legend.map(({ label, color, count, blurb }) => [
+169
View File
@@ -0,0 +1,169 @@
import { createSlider } from './slider.js';
import { syncSegmentedControl } from './segmentedControl.js';
const set = (node, key, value) => {
if (node[key] !== value) node[key] = value;
};
const attribute = (node, key, value) => {
if (node.getAttribute(key) !== value) node.setAttribute(key, value);
};
// Custom properties need setProperty; test fixtures carry a plain style bag.
const styleVar = (node, name, value) => {
if (typeof node.style?.setProperty === 'function') {
if (value) node.style.setProperty(name, value);
else node.style.removeProperty(name);
} else if (node.style) node.style[name] = value || '';
};
/**
* Reconcile a layer row's quantitative slider block in place (keyed by the
* descriptor id), so a refresh triggered by the slider's own input never
* replaces the node under the pointer. The caller owns dispatch: it listens
* for `input` on the row container and reads `.data-toggle-slider-input`.
*
* Descriptor: `{ id, label, ariaLabel, valueText, min, max, step, value,
* track, ticks: [{ at, label }] }` — `track` is a CSS background painting the
* runnable track (a color ramp doubles as the legend), `at` is 0..1.
* @param {HTMLElement} container The row's `.data-toggle-controls` node.
* @param {?object} slider Descriptor, or null to remove the block.
* @param {{before?: ?Node}} [options] Insertion anchor for a new block.
* @returns {?HTMLElement} The block, when rendered.
*/
export function syncSliderBlock(container, slider, { before = null } = {}) {
if (!container) return null;
const document = container.ownerDocument ?? globalThis.document;
const existing = [...container.children].find(
(node) => node.dataset?.sliderId,
);
if (!slider) {
existing?.remove();
return null;
}
let block = existing;
if (!block || block.dataset.sliderId !== slider.id) {
existing?.remove();
block = document.createElement('div');
block.className = 'data-toggle-slider';
block.dataset.sliderId = slider.id;
const head = document.createElement('div');
head.className = 'data-toggle-slider-head';
const label = document.createElement('span');
label.className = 'data-toggle-slider-label';
const value = document.createElement('span');
value.className = 'data-toggle-slider-value gev-slider-value';
head.append(label, value);
const input = createSlider({
documentRef: document,
className: 'data-toggle-slider-input',
min: slider.min,
max: slider.max,
step: slider.step,
value: slider.value,
});
input.dataset.sliderId = slider.id;
const ticks = document.createElement('div');
ticks.className = 'data-toggle-slider-ticks';
block.append(head, input, ticks);
block._parts = { label, value, input, ticks };
container.insertBefore(block, before);
}
const { label, value, input, ticks } = block._parts;
set(label, 'textContent', slider.label ?? '');
set(value, 'textContent', slider.valueText ?? '');
set(input, 'min', String(slider.min));
set(input, 'max', String(slider.max));
set(input, 'step', String(slider.step ?? 1));
// Never move the thumb under an active drag: the layer's rounded value can
// sit a hair off the pointer, and a refresh runs on every input tick.
if (document.activeElement !== input)
set(input, 'value', String(slider.value));
if (slider.ariaLabel) attribute(input, 'aria-label', slider.ariaLabel);
if (slider.valueText) attribute(input, 'aria-valuetext', slider.valueText);
const track = slider.track || '';
if ((block.dataset.track || '') !== track) {
styleVar(input, '--slider-track', track);
block.dataset.track = track;
}
const signature = JSON.stringify(slider.ticks || []);
if (block.dataset.ticks !== signature) {
for (const node of [...ticks.children]) node.remove();
for (const tick of slider.ticks || []) {
const node = document.createElement('span');
node.className = 'data-toggle-slider-tick';
styleVar(node, '--at', `${(tick.at * 100).toFixed(2)}%`);
node.textContent = tick.label;
ticks.appendChild(node);
}
block.dataset.ticks = signature;
}
return block;
}
/**
* Reconcile a one-of-many switch (`.gev-segmented` radiogroup) in place.
* Buttons carry `data-chip-id` like chips so the row's delegated click handler
* can resolve them; the caller matches `.data-toggle-segment`.
*
* Descriptor: `{ id, ariaLabel, options: [{ id, label, title, active,
* disabled, params }] }`.
* @param {HTMLElement} container The row's `.data-toggle-controls` node.
* @param {?object} segmented Descriptor, or null to remove the group.
* @param {{before?: ?Node}} [options] Insertion anchor for a new group.
* @returns {?HTMLElement} The group, when rendered.
*/
export function syncSegmentedGroup(
container,
segmented,
{ before = null } = {},
) {
if (!container) return null;
const document = container.ownerDocument ?? globalThis.document;
const existing = [...container.children].find(
(node) => node.dataset?.segmentedId,
);
if (!segmented) {
existing?.remove();
return null;
}
let group = existing;
if (!group || group.dataset.segmentedId !== segmented.id) {
existing?.remove();
group = document.createElement('div');
group.className = 'gev-segmented data-toggle-segmented';
group.dataset.segmentedId = segmented.id;
group.setAttribute('role', 'radiogroup');
container.insertBefore(group, before);
}
if (segmented.ariaLabel) attribute(group, 'aria-label', segmented.ariaLabel);
const stale = new Map();
for (const node of [...group.children])
if (node.dataset?.chipId) stale.set(node.dataset.chipId, node);
const ordered = [];
for (const option of segmented.options || []) {
let button = stale.get(option.id);
stale.delete(option.id);
if (!button) {
button = document.createElement('button');
button.type = 'button';
button.className = 'gev-segment data-toggle-segment';
button.dataset.chipId = option.id;
button.setAttribute('role', 'radio');
}
set(button, 'textContent', option.label);
set(button, 'title', option.title || '');
set(button, 'disabled', Boolean(option.disabled));
ordered.push(button);
}
for (const node of stale.values()) node.remove();
ordered.forEach((node, index) => {
if (group.children[index] !== node)
group.insertBefore(node, group.children[index] || null);
});
const active = (segmented.options || []).find((option) => option.active);
syncSegmentedControl(ordered, active?.id, {
valueOf: (button) => button.dataset.chipId,
activeClass: 'active',
rovingFocus: true,
});
return group;
}
+207
View File
@@ -0,0 +1,207 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { syncSegmentedGroup, syncSliderBlock } from './rowFilterControls.js';
import { railFixture } from './railTestFixture.mjs';
const sliderDescriptor = (overrides = {}) => ({
id: 'min-frp',
label: 'MIN FRP',
ariaLabel: 'Minimum fire radiative power',
valueText: 'All',
min: 0,
max: 1000,
step: 1,
value: 0,
track: 'linear-gradient(90deg, #4a5bd4 0% 23%, #d1382a 82% 100%)',
ticks: [
{ at: 0, label: '0' },
{ at: 0.233, label: '5' },
{ at: 0.826, label: '300' },
],
params: (value) => ({ minFrp: Number(value) }),
...overrides,
});
const segmentedDescriptor = (active = 'all') => ({
id: 'confidence',
ariaLabel: 'Detection confidence',
options: ['all', 'nominal', 'high'].map((mode) => ({
id: `confidence-${mode}`,
label: mode.toUpperCase(),
title: `${mode} title`,
active: mode === active,
params: { confidence: mode },
})),
});
test('the slider block renders label, value, painted track and ticks, and is reconciled in place', () => {
const f = railFixture();
const container = f.document.createElement('div');
const block = syncSliderBlock(container, sliderDescriptor());
assert.equal(block.className, 'data-toggle-slider');
assert.equal(block.dataset.sliderId, 'min-frp');
const input = block.querySelector('.data-toggle-slider-input');
assert.equal(input.type, 'range');
assert.equal(input.max, '1000');
assert.equal(input.value, '0');
assert.equal(
input.getAttribute('aria-label'),
'Minimum fire radiative power',
);
assert.equal(input.getAttribute('aria-valuetext'), 'All');
assert.match(input.style['--slider-track'], /^linear-gradient/);
assert.equal(
block.querySelector('.data-toggle-slider-label').textContent,
'MIN FRP',
);
assert.equal(
block.querySelector('.data-toggle-slider-value').textContent,
'All',
);
const ticks = block.querySelector('.data-toggle-slider-ticks');
assert.deepEqual(
ticks.children.map((node) => [node.textContent, node.style['--at']]),
[
['0', '0.00%'],
['5', '23.30%'],
['300', '82.60%'],
],
);
const again = syncSliderBlock(
container,
sliderDescriptor({ value: 434, valueText: '20 MW' }),
);
assert.equal(again, block, 'same node — a refresh never drops the thumb');
assert.equal(input.value, '434');
assert.equal(
block.querySelector('.data-toggle-slider-value').textContent,
'20 MW',
);
assert.equal(container.children.length, 1);
// A thumb under the pointer is never moved by a refresh.
input.focus();
syncSliderBlock(container, sliderDescriptor({ value: 0 }));
assert.equal(input.value, '434');
syncSliderBlock(container, null);
assert.equal(container.children.length, 0);
});
test('the segmented group is a radiogroup whose active option reads checked, reconciled by id', () => {
const f = railFixture();
const container = f.document.createElement('div');
const group = syncSegmentedGroup(container, segmentedDescriptor('all'));
assert.equal(group.getAttribute('role'), 'radiogroup');
assert.equal(group.getAttribute('aria-label'), 'Detection confidence');
assert.ok(group.className.split(' ').includes('gev-segmented'));
const buttons = group.children;
assert.deepEqual(
buttons.map((b) => [
b.dataset.chipId,
b.textContent,
b.getAttribute('aria-checked'),
b.getAttribute('tabindex'),
]),
[
['confidence-all', 'ALL', 'true', '0'],
['confidence-nominal', 'NOMINAL', 'false', '-1'],
['confidence-high', 'HIGH', 'false', '-1'],
],
);
assert.equal(buttons[0].getAttribute('role'), 'radio');
assert.equal(buttons[1].title, 'nominal title');
syncSegmentedGroup(container, segmentedDescriptor('high'));
assert.equal(group.children[0], buttons[0], 'buttons are reused');
assert.equal(buttons[0].getAttribute('aria-checked'), 'false');
assert.equal(buttons[2].getAttribute('aria-checked'), 'true');
assert.ok(buttons[2].classList.contains('active'));
assert.equal(container.children.length, 1);
syncSegmentedGroup(container, null);
assert.equal(container.children.length, 0);
});
test('a layer row dispatches slider input and switch clicks as user params', async () => {
const { LayerPanel } = await import('./layerPanel.js');
const f = railFixture();
const previousDocument = globalThis.document;
globalThis.document = f.document;
const calls = [];
let controls = {
slider: sliderDescriptor(),
segmented: segmentedDescriptor('all'),
info: '12 of 40 shown',
};
const panel = new LayerPanel({
getLayers: () => [
{
id: 'local-firms',
name: 'Active Fires',
icon: '▲',
source: 'NASA FIRMS',
enabled: true,
showInTogglePanel: true,
stats: {},
},
],
isEnabled: () => true,
setEnabled: () => {},
setLayerParams: (...args) => calls.push(args),
hasRowControls: () => true,
subscribeRowControls: () => {},
getRowControls: () => controls,
});
try {
panel.mount(f.container);
const row = f.find((n) => n.dataset.layerId === 'local-firms');
const container = row.querySelector('.data-toggle-controls');
assert.equal(container.hidden, false);
assert.equal(
row.querySelector('.data-toggle-controls-info').textContent,
'12 of 40 shown',
);
// Order: switch, slider, info.
assert.deepEqual(
container.children.map((node) => node.className.split(' ')[0]),
['gev-segmented', 'data-toggle-slider', 'data-toggle-controls-info'],
);
const input = row.querySelector('.data-toggle-slider-input');
input.value = '434';
const inputEvent = new Event('input');
Object.defineProperty(inputEvent, 'target', { value: input });
container.dispatchEvent(inputEvent);
assert.deepEqual(calls.at(-1), [
'local-firms',
{ minFrp: 434 },
{ origin: 'user' },
]);
const high = row
.querySelector('.data-toggle-segmented')
.children.find((b) => b.dataset.chipId === 'confidence-high');
high.click();
assert.deepEqual(calls.at(-1), [
'local-firms',
{ confidence: 'high' },
{ origin: 'user' },
]);
// A stale descriptor never applies: the live one decides.
controls = { ...controls, segmented: segmentedDescriptor('high') };
// The fixture DOM has no attribute selectors, so sync the row directly.
panel._syncRowControls(container, { id: 'local-firms', enabled: true });
assert.equal(high.getAttribute('aria-checked'), 'true');
assert.equal(
row.querySelector('.data-toggle-slider-input'),
input,
'the slider survives a refresh',
);
} finally {
panel.destroy();
globalThis.document = previousDocument;
}
});
+102
View File
@@ -1035,6 +1035,108 @@ html:not([lang='en']) .data-row-list-text {
padding-top: 3px;
overflow-wrap: anywhere;
}
/* Optional per-layer one-of-many switch (Active Fires confidence). The shared
.gev-segmented surface, sized to the chip row. */
.data-toggle-controls .data-toggle-segmented {
flex-basis: 100%;
max-width: 220px;
}
.data-toggle-controls .data-toggle-segment {
min-height: 20px;
padding: 3px 6px;
font-size: 8px;
letter-spacing: 0.8px;
}
/* Optional per-layer quantitative slider (Active Fires minimum FRP). The
track is painted by the layer (`--slider-track`, a stepped color ramp), so
the slider doubles as the marker legend; ticks sit under their thresholds. */
.data-toggle-slider {
flex-basis: 100%;
display: grid;
gap: 2px;
padding-top: 2px;
}
.data-toggle-slider-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 8px;
font-family: var(--font-mono);
font-size: 8px;
letter-spacing: 1.2px;
color: var(--text-dim);
text-transform: uppercase;
}
.data-toggle-slider-value {
min-width: 0;
font-size: 9px;
letter-spacing: 0.5px;
text-transform: none;
}
.data-toggle-slider-input {
height: 14px;
}
.data-toggle-slider-input::-webkit-slider-runnable-track {
height: 5px;
border-radius: 3px;
background: var(--slider-track, rgba(255, 255, 255, 0.08));
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.data-toggle-slider-input::-moz-range-track,
.data-toggle-slider-input::-moz-range-progress {
height: 5px;
border-radius: 3px;
background: var(--slider-track, rgba(255, 255, 255, 0.08));
}
.data-toggle-slider-input::-webkit-slider-thumb {
width: 11px;
height: 11px;
margin-top: -3px;
background: var(--text-primary);
box-shadow:
0 0 0 1px rgba(0, 0, 0, 0.6),
0 0 6px rgba(255, 255, 255, 0.35);
}
.data-toggle-slider-input::-moz-range-thumb {
width: 11px;
height: 11px;
background: var(--text-primary);
box-shadow:
0 0 0 1px rgba(0, 0, 0, 0.6),
0 0 6px rgba(255, 255, 255, 0.35);
}
.data-toggle-slider-ticks {
position: relative;
height: 10px;
margin: 0 5px;
font-family: var(--font-mono);
font-size: 7px;
letter-spacing: 0.4px;
color: var(--text-dim);
}
.data-toggle-slider-tick {
position: absolute;
top: 0;
left: var(--at);
transform: translateX(-50%);
white-space: nowrap;
}
.data-toggle-slider-tick:first-child {
transform: none;
}
/* ── Local RTL-SDR card (FM + Local ADS-B receiver) ── */
.sdr-radio-card {
display: grid;