mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
feat: Wildlife Sightings layer from iNaturalist and Acartia
Recent community wildlife observations, as a new Wildlife group in the layer panel. - Server: keyless iNaturalist proxy (v2 observations with only the projected fields; undocumented v1 UTFGrid density tiles, decoded on the server) sharing one paced queue (burst 4, ~1/s, 60/min, 8,000/day budget, up to four in flight), in-memory caches and upstream-only cooldowns; Acartia Salish Sea marine-mammal feed rounded to 0.01 degrees with comments dropped. - Layer: grid counts drawn as a soft view-ranked density glow; real sampled sightings as taxon badges at their true positions with ambient photo thumbnails and labels; obscured records stay privacy cells; a clicked sighting stays pinned through camera moves and refreshes. - Anchored photo card per selection with the single iNaturalist link; attribution in the layer row and the Data attribution popover. - Filters (CONFIRMED, taxa presets) round-trip in share links with token 9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
edd6212793
commit
14f88b3e08
120 files changed
+21260
-285
No files matched your search
@@ -25,7 +25,11 @@ import {
|
||||
placementVariants,
|
||||
roundedRectPath,
|
||||
} from './worldOverlayDraw.js';
|
||||
import { createCctvThumbnailOverlayEntry, createFrameSlot } from '../data/cctvCards.js';
|
||||
import {
|
||||
createCctvThumbnailOverlayEntry,
|
||||
createFrameSlot,
|
||||
} from '../data/cctvCards.js';
|
||||
import { normalizeOverlayEntry } from './worldOverlay.js';
|
||||
import {
|
||||
CARD_PLATE_ALPHA,
|
||||
DETECTION_PLATE_BAND,
|
||||
@@ -35,7 +39,9 @@ import {
|
||||
} from './worldOverlayTokens.js';
|
||||
|
||||
function alphaOf(rgba) {
|
||||
const match = /rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*([0-9.]+)\s*\)/.exec(String(rgba));
|
||||
const match = /rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*([0-9.]+)\s*\)/.exec(
|
||||
String(rgba),
|
||||
);
|
||||
assert.ok(match, `expected an rgba() colour, got ${rgba}`);
|
||||
return Number(match[1]);
|
||||
}
|
||||
@@ -48,28 +54,64 @@ function mockContext() {
|
||||
calls,
|
||||
font: '',
|
||||
globalAlpha: 1,
|
||||
get strokeStyle() { return strokeStyle; },
|
||||
set strokeStyle(value) { strokeStyle = value; calls.push(['strokeStyle', value]); },
|
||||
get lineWidth() { return lineWidth; },
|
||||
set lineWidth(value) { lineWidth = value; calls.push(['lineWidth', value]); },
|
||||
get strokeStyle() {
|
||||
return strokeStyle;
|
||||
},
|
||||
set strokeStyle(value) {
|
||||
strokeStyle = value;
|
||||
calls.push(['strokeStyle', value]);
|
||||
},
|
||||
get lineWidth() {
|
||||
return lineWidth;
|
||||
},
|
||||
set lineWidth(value) {
|
||||
lineWidth = value;
|
||||
calls.push(['lineWidth', value]);
|
||||
},
|
||||
measureCount: 0,
|
||||
measureText(text) {
|
||||
this.measureCount++;
|
||||
return { width: String(text).length * 6 };
|
||||
},
|
||||
save() { calls.push(['save']); },
|
||||
restore() { calls.push(['restore']); },
|
||||
beginPath() { calls.push(['beginPath']); },
|
||||
roundRect(...args) { calls.push(['roundRect', ...args]); },
|
||||
moveTo(...args) { calls.push(['moveTo', ...args]); },
|
||||
lineTo(...args) { calls.push(['lineTo', ...args]); },
|
||||
arcTo(...args) { calls.push(['arcTo', ...args]); },
|
||||
closePath() { calls.push(['closePath']); },
|
||||
fill() { calls.push(['fill']); },
|
||||
stroke() { calls.push(['stroke']); },
|
||||
fillRect(...args) { calls.push(['fillRect', ...args]); },
|
||||
fillText(...args) { calls.push(['fillText', ...args]); },
|
||||
drawImage(...args) { calls.push(['drawImage', ...args]); },
|
||||
save() {
|
||||
calls.push(['save']);
|
||||
},
|
||||
restore() {
|
||||
calls.push(['restore']);
|
||||
},
|
||||
beginPath() {
|
||||
calls.push(['beginPath']);
|
||||
},
|
||||
roundRect(...args) {
|
||||
calls.push(['roundRect', ...args]);
|
||||
},
|
||||
moveTo(...args) {
|
||||
calls.push(['moveTo', ...args]);
|
||||
},
|
||||
lineTo(...args) {
|
||||
calls.push(['lineTo', ...args]);
|
||||
},
|
||||
arcTo(...args) {
|
||||
calls.push(['arcTo', ...args]);
|
||||
},
|
||||
closePath() {
|
||||
calls.push(['closePath']);
|
||||
},
|
||||
fill() {
|
||||
calls.push(['fill']);
|
||||
},
|
||||
stroke() {
|
||||
calls.push(['stroke']);
|
||||
},
|
||||
fillRect(...args) {
|
||||
calls.push(['fillRect', ...args]);
|
||||
},
|
||||
fillText(...args) {
|
||||
calls.push(['fillText', ...args]);
|
||||
},
|
||||
drawImage(...args) {
|
||||
calls.push(['drawImage', ...args]);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,14 +127,17 @@ test('every detection theme carries a callout plate inside the ambient band', ()
|
||||
const plate = alphaOf(theme.calloutPlate);
|
||||
const space = alphaOf(theme.calloutPlateSpace);
|
||||
assert.ok(
|
||||
plate >= DETECTION_PLATE_BAND.min * CARD_PLATE_ALPHA
|
||||
&& plate <= DETECTION_PLATE_BAND.max * CARD_PLATE_ALPHA,
|
||||
plate >= DETECTION_PLATE_BAND.min * CARD_PLATE_ALPHA &&
|
||||
plate <= DETECTION_PLATE_BAND.max * CARD_PLATE_ALPHA,
|
||||
`${name} callout plate ${plate} outside the ambient band`,
|
||||
);
|
||||
// The owner's spec: satellites read over the lit Earth disc, so the space
|
||||
// tier pops slightly harder — but never as heavy as the tracked card.
|
||||
assert.ok(space > plate, `${name} space plate must exceed the base plate`);
|
||||
assert.ok(space < CARD_PLATE_ALPHA, `${name} space plate must stay under the card`);
|
||||
assert.ok(
|
||||
space < CARD_PLATE_ALPHA,
|
||||
`${name} space plate must stay under the card`,
|
||||
);
|
||||
// The scanline wash is a separate token and must not have been repurposed.
|
||||
assert.notEqual(theme.calloutPlate, theme.labelBg);
|
||||
}
|
||||
@@ -100,47 +145,78 @@ test('every detection theme carries a callout plate inside the ambient band', ()
|
||||
|
||||
test('an ambient detection callout paints its backing plate under its text', () => {
|
||||
const ctx = mockContext();
|
||||
paintDetectionCallout(ctx, {
|
||||
x: 20, y: 30, w: 80, h: 18,
|
||||
primaryX: 27, microX: 70, baseline: 42,
|
||||
leadFromX: 60, leadFromY: 60, leadToX: 60, leadToY: 48,
|
||||
plate: 'rgba(2, 18, 26, 0.52)',
|
||||
accent: '#22e0ff',
|
||||
label: 'rgba(200, 250, 255, 0.97)',
|
||||
primary: 'JA23NF',
|
||||
micro: 'FL017',
|
||||
font: '10px JetBrains Mono, monospace',
|
||||
microFont: '9px JetBrains Mono, monospace',
|
||||
}, 1);
|
||||
paintDetectionCallout(
|
||||
ctx,
|
||||
{
|
||||
x: 20,
|
||||
y: 30,
|
||||
w: 80,
|
||||
h: 18,
|
||||
primaryX: 27,
|
||||
microX: 70,
|
||||
baseline: 42,
|
||||
leadFromX: 60,
|
||||
leadFromY: 60,
|
||||
leadToX: 60,
|
||||
leadToY: 48,
|
||||
plate: 'rgba(2, 18, 26, 0.52)',
|
||||
accent: '#22e0ff',
|
||||
label: 'rgba(200, 250, 255, 0.97)',
|
||||
primary: 'JA23NF',
|
||||
micro: 'FL017',
|
||||
font: '10px JetBrains Mono, monospace',
|
||||
microFont: '9px JetBrains Mono, monospace',
|
||||
},
|
||||
1,
|
||||
);
|
||||
|
||||
const names = ctx.calls.map(([name]) => name);
|
||||
const firstFill = names.indexOf('fill');
|
||||
const firstText = names.indexOf('fillText');
|
||||
assert.ok(firstFill >= 0, 'the callout must fill a backing plate');
|
||||
assert.ok(firstText > firstFill, 'the plate must be painted before the callsign');
|
||||
assert.ok(
|
||||
firstText > firstFill,
|
||||
'the plate must be painted before the callsign',
|
||||
);
|
||||
// Plate geometry: a rounded rect covering the whole measured label box.
|
||||
assert.deepEqual(
|
||||
ctx.calls.find(([name]) => name === 'roundRect'),
|
||||
['roundRect', 20, 30, 80, 18, 3],
|
||||
);
|
||||
assert.ok(ctx.calls.some(([name, text]) => name === 'fillText' && text === 'JA23NF'));
|
||||
assert.ok(ctx.calls.some(([name, text]) => name === 'fillText' && text === 'FL017'));
|
||||
assert.ok(
|
||||
ctx.calls.some(([name, text]) => name === 'fillText' && text === 'JA23NF'),
|
||||
);
|
||||
assert.ok(
|
||||
ctx.calls.some(([name, text]) => name === 'fillText' && text === 'FL017'),
|
||||
);
|
||||
});
|
||||
|
||||
test('a callout with no micro-field paints one text run and still gets a plate', () => {
|
||||
const ctx = mockContext();
|
||||
paintDetectionCallout(ctx, {
|
||||
x: 0, y: 0, w: 40, h: 18,
|
||||
primaryX: 7, microX: 30, baseline: 12,
|
||||
leadFromX: 20, leadFromY: 30, leadToX: 20, leadToY: 18,
|
||||
plate: 'rgba(2, 18, 26, 0.52)',
|
||||
accent: '#22e0ff',
|
||||
label: '#fff',
|
||||
primary: 'N12345',
|
||||
micro: '',
|
||||
font: '10px mono',
|
||||
microFont: '9px mono',
|
||||
}, 0.5);
|
||||
paintDetectionCallout(
|
||||
ctx,
|
||||
{
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: 40,
|
||||
h: 18,
|
||||
primaryX: 7,
|
||||
microX: 30,
|
||||
baseline: 12,
|
||||
leadFromX: 20,
|
||||
leadFromY: 30,
|
||||
leadToX: 20,
|
||||
leadToY: 18,
|
||||
plate: 'rgba(2, 18, 26, 0.52)',
|
||||
accent: '#22e0ff',
|
||||
label: '#fff',
|
||||
primary: 'N12345',
|
||||
micro: '',
|
||||
font: '10px mono',
|
||||
microFont: '9px mono',
|
||||
},
|
||||
0.5,
|
||||
);
|
||||
|
||||
assert.ok(ctx.calls.some(([name]) => name === 'fill'));
|
||||
assert.equal(ctx.calls.filter(([name]) => name === 'fillText').length, 1);
|
||||
@@ -167,7 +243,7 @@ test('distance scale matches the legacy infrastructure NearFarScalar curve', ()
|
||||
assert.equal(distanceScale(1_000_000, null), 1);
|
||||
});
|
||||
|
||||
test('altitude scale preserves CCTV\'s exact smoothstep and linear waypoints', () => {
|
||||
test("altitude scale preserves CCTV's exact smoothstep and linear waypoints", () => {
|
||||
const curve = {
|
||||
fullEnd: 1800,
|
||||
midEnd: 6000,
|
||||
@@ -185,13 +261,16 @@ test('altitude scale preserves CCTV\'s exact smoothstep and linear waypoints', (
|
||||
});
|
||||
|
||||
test('the five-channel alpha chain is multiplicative and clamps inputs', () => {
|
||||
assert.equal(combinedOverlayAlpha({
|
||||
sourceAlpha: 0.5,
|
||||
temporalFade: 0.8,
|
||||
distanceFade: 0.5,
|
||||
altitudeFade: 0.5,
|
||||
keyholeEdgeFade: 0.25,
|
||||
}), 0.025);
|
||||
assert.equal(
|
||||
combinedOverlayAlpha({
|
||||
sourceAlpha: 0.5,
|
||||
temporalFade: 0.8,
|
||||
distanceFade: 0.5,
|
||||
altitudeFade: 0.5,
|
||||
keyholeEdgeFade: 0.25,
|
||||
}),
|
||||
0.025,
|
||||
);
|
||||
assert.equal(combinedOverlayAlpha({ sourceAlpha: 2, temporalFade: -1 }), 0);
|
||||
});
|
||||
|
||||
@@ -205,7 +284,10 @@ test('placement variants flip below near the top and stay viewport-clamped', ()
|
||||
viewportHeight: 100,
|
||||
gap: 10,
|
||||
});
|
||||
assert.deepEqual(nearTop.map((item) => item.corner), ['below', 'above', 'right', 'left']);
|
||||
assert.deepEqual(
|
||||
nearTop.map((item) => item.corner),
|
||||
['below', 'above', 'right', 'left'],
|
||||
);
|
||||
for (const placement of nearTop) {
|
||||
assert.ok(placement.rect.x >= 4);
|
||||
assert.ok(placement.rect.y >= 4);
|
||||
@@ -213,14 +295,20 @@ test('placement variants flip below near the top and stay viewport-clamped', ()
|
||||
assert.ok(placement.rect.y + placement.rect.h <= 96);
|
||||
}
|
||||
const reused = nearTop.slice();
|
||||
assert.equal(placementVariants({
|
||||
anchorX: 100,
|
||||
anchorY: 80,
|
||||
width: 40,
|
||||
height: 20,
|
||||
viewportWidth: 200,
|
||||
viewportHeight: 100,
|
||||
}, reused), reused);
|
||||
assert.equal(
|
||||
placementVariants(
|
||||
{
|
||||
anchorX: 100,
|
||||
anchorY: 80,
|
||||
width: 40,
|
||||
height: 20,
|
||||
viewportWidth: 200,
|
||||
viewportHeight: 100,
|
||||
},
|
||||
reused,
|
||||
),
|
||||
reused,
|
||||
);
|
||||
assert.equal(reused[0].corner, 'above');
|
||||
});
|
||||
|
||||
@@ -236,10 +324,16 @@ test('tactical cards retain vertical-only placement and sprite-edge leaders', ()
|
||||
leaderOffset: 14,
|
||||
verticalOnly: true,
|
||||
});
|
||||
assert.deepEqual(placements.map(({ corner }) => corner), ['above', 'below']);
|
||||
assert.deepEqual(
|
||||
placements.map(({ corner }) => corner),
|
||||
['above', 'below'],
|
||||
);
|
||||
assert.equal(placements[0].leadFromY, 80);
|
||||
assert.equal(placements[0].leaderOffset, -14);
|
||||
assert.equal(placements[0].leadToY, placements[0].rect.y + placements[0].rect.h);
|
||||
assert.equal(
|
||||
placements[0].leadToY,
|
||||
placements[0].rect.y + placements[0].rect.h,
|
||||
);
|
||||
});
|
||||
|
||||
test('edge-clamped CCTV placements keep leaders vertical unless the anchor is outside the card', () => {
|
||||
@@ -254,7 +348,11 @@ test('edge-clamped CCTV placements keep leaders vertical unless the anchor is ou
|
||||
leaderOffset: 16,
|
||||
verticalOnly: true,
|
||||
})[0];
|
||||
assert.equal(edgeClamped.rect.x, 4, 'card is horizontally clamped at the viewport edge');
|
||||
assert.equal(
|
||||
edgeClamped.rect.x,
|
||||
4,
|
||||
'card is horizontally clamped at the viewport edge',
|
||||
);
|
||||
assert.equal(edgeClamped.leadFromX, 20);
|
||||
assert.equal(edgeClamped.leadToX, 20, 'leader stays strictly vertical at sx');
|
||||
|
||||
@@ -277,8 +375,11 @@ test('edge-clamped CCTV placements keep leaders vertical unless the anchor is ou
|
||||
// camera". Vertical always, even when the card has been clamped sideways off
|
||||
// its anchor.
|
||||
assert.equal(offRectAnchor.leadFromX, 2);
|
||||
assert.equal(offRectAnchor.leadToX, 2,
|
||||
'an off-rect anchor keeps the leader vertical rather than slanting it to the card');
|
||||
assert.equal(
|
||||
offRectAnchor.leadToX,
|
||||
2,
|
||||
'an off-rect anchor keeps the leader vertical rather than slanting it to the card',
|
||||
);
|
||||
});
|
||||
|
||||
test('rounded rectangles use native support and retain a fallback path', () => {
|
||||
@@ -334,7 +435,8 @@ test('text measurement cache is font-aware and font hooks follow host lifetime',
|
||||
test('text measurement cache caps LRU retention at 1024 entries', () => {
|
||||
clearWorldOverlayTextMeasureCache();
|
||||
const ctx = mockContext();
|
||||
for (let i = 0; i < 1100; i++) measureWorldOverlayText(ctx, `label-${i}`, '10px mono');
|
||||
for (let i = 0; i < 1100; i++)
|
||||
measureWorldOverlayText(ctx, `label-${i}`, '10px mono');
|
||||
assert.equal(getWorldOverlayTextMeasureCacheSize(), 1024);
|
||||
const measured = ctx.measureCount;
|
||||
measureWorldOverlayText(ctx, 'label-0', '10px mono');
|
||||
@@ -355,10 +457,28 @@ test('variant measurement and all six painters remain renderer-local', () => {
|
||||
thumbnailWidth: 96,
|
||||
thumbnailHeight: 54,
|
||||
};
|
||||
const variants = ['label', 'track', 'card', 'thumbnail', 'selected', 'tracked'];
|
||||
const painters = [paintLabel, paintTrack, paintCard, paintThumbnail, paintSelected, paintTracked];
|
||||
const variants = [
|
||||
'label',
|
||||
'track',
|
||||
'card',
|
||||
'thumbnail',
|
||||
'selected',
|
||||
'tracked',
|
||||
];
|
||||
const painters = [
|
||||
paintLabel,
|
||||
paintTrack,
|
||||
paintCard,
|
||||
paintThumbnail,
|
||||
paintSelected,
|
||||
paintTracked,
|
||||
];
|
||||
for (let i = 0; i < variants.length; i++) {
|
||||
const variantEntry = { ...entry, variant: variants[i], selected: variants[i] === 'selected' };
|
||||
const variantEntry = {
|
||||
...entry,
|
||||
variant: variants[i],
|
||||
selected: variants[i] === 'selected',
|
||||
};
|
||||
const layout = measureOverlayEntry(ctx, variantEntry, {});
|
||||
variantEntry._overlayLayout = layout;
|
||||
const placement = placementVariants({
|
||||
@@ -369,18 +489,27 @@ test('variant measurement and all six painters remain renderer-local', () => {
|
||||
viewportWidth: 400,
|
||||
viewportHeight: 300,
|
||||
})[0];
|
||||
assert.equal(painters[i](ctx, variantEntry, placement, 0.5), placement.rect);
|
||||
assert.equal(
|
||||
painters[i](ctx, variantEntry, placement, 0.5),
|
||||
placement.rect,
|
||||
);
|
||||
}
|
||||
assert.ok(ctx.calls.some(([name]) => name === 'drawImage'));
|
||||
assert.ok(ctx.calls.filter(([name]) => name === 'fillText').length >= variants.length);
|
||||
const trackLayout = measureOverlayEntry(ctx, { ...entry, variant: 'track' }, {});
|
||||
assert.ok(
|
||||
ctx.calls.filter(([name]) => name === 'fillText').length >= variants.length,
|
||||
);
|
||||
const trackLayout = measureOverlayEntry(
|
||||
ctx,
|
||||
{ ...entry, variant: 'track' },
|
||||
{},
|
||||
);
|
||||
assert.ok(trackLayout.w >= 'CAMERA 12 · LIVE'.length * 6);
|
||||
});
|
||||
|
||||
test('thumbnail painter preserves the shipped CCTV 104x77 geometry and drawing coordinates', () => {
|
||||
const ctx = mockContext();
|
||||
const frameSlot = createFrameSlot();
|
||||
frameSlot.frame = { width: 192, height: 108 };
|
||||
frameSlot.frame = { width: 192, height: 144 };
|
||||
frameSlot.stamp = 123;
|
||||
const entry = createCctvThumbnailOverlayEntry({
|
||||
id: 'cam-a',
|
||||
@@ -411,7 +540,10 @@ test('thumbnail painter preserves the shipped CCTV 104x77 geometry and drawing c
|
||||
['strokeStyle', 'rgba(107, 232, 255, 0.6)'],
|
||||
'CCTV leader uses the source cyan token rather than the generic leader fallback',
|
||||
);
|
||||
assert.deepEqual(ctx.calls.find(([name]) => name === 'moveTo'), ['moveTo', 200, 184]);
|
||||
assert.deepEqual(
|
||||
ctx.calls.find(([name]) => name === 'moveTo'),
|
||||
['moveTo', 200, 184],
|
||||
);
|
||||
assert.deepEqual(
|
||||
ctx.calls.find(([name]) => name === 'drawImage'),
|
||||
['drawImage', frameSlot.frame, 152, 105, 96, 54],
|
||||
@@ -422,6 +554,69 @@ test('thumbnail painter preserves the shipped CCTV 104x77 geometry and drawing c
|
||||
);
|
||||
});
|
||||
|
||||
test('photo thumbnails letterbox square images and visibly paint attribution and disclaimers', () => {
|
||||
const ctx = mockContext();
|
||||
const entry = {
|
||||
...createCctvThumbnailOverlayEntry({
|
||||
id: 'photo',
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
title: 'Synthetic bird',
|
||||
frameSlot: { frame: { width: 75, height: 75 } },
|
||||
}),
|
||||
thumbnailHeight: 72,
|
||||
thumbnailFit: 'contain',
|
||||
details: ['Photo: Synthetic photographer · CC BY', 'Not a census'],
|
||||
};
|
||||
entry._overlayLayout = measureOverlayEntry(ctx, entry, {});
|
||||
const { w, h, lineH } = entry._overlayLayout;
|
||||
assert.equal(w, 104, 'canvas photos keep the compact image width');
|
||||
assert.equal(h, 4 + 72 + 2 + 13 + 2 * lineH + 4);
|
||||
const placement = { rect: { x: 10, y: 20, w, h } };
|
||||
paintThumbnail(ctx, entry, placement);
|
||||
assert.deepEqual(
|
||||
ctx.calls.find(([name]) => name === 'drawImage'),
|
||||
['drawImage', entry.image.frame, 26, 24, 72, 72],
|
||||
);
|
||||
for (const detail of entry.details)
|
||||
assert.ok(
|
||||
ctx.calls.some(([name, text]) => name === 'fillText' && text === detail),
|
||||
detail,
|
||||
);
|
||||
});
|
||||
|
||||
test('fixed-width photo thumbnails truncate the title and creator inside the 96px image width', () => {
|
||||
const ctx = mockContext();
|
||||
const entry = normalizeOverlayEntry('compact-photos', {
|
||||
...createCctvThumbnailOverlayEntry({
|
||||
id: 'compact-photo',
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
title: 'A long synthetic organism name',
|
||||
frameSlot: { frame: { width: 75, height: 75 } },
|
||||
}),
|
||||
thumbnailHeight: 72,
|
||||
thumbnailFixedWidth: true,
|
||||
details: ['© A very long synthetic photographer name'],
|
||||
});
|
||||
entry._overlayLayout = measureOverlayEntry(ctx, entry, {});
|
||||
const { w, h, lineH } = entry._overlayLayout;
|
||||
assert.equal(w, 104, '96px image plus the shared 4px padding on each side');
|
||||
assert.equal(h, 4 + 72 + 2 + 13 + lineH + 4, 'exactly one creator line');
|
||||
const placement = { rect: { x: 10, y: 20, w, h } };
|
||||
paintThumbnail(ctx, entry, placement);
|
||||
const text = ctx.calls.filter(([name]) => name === 'fillText');
|
||||
assert.equal(text.length, 2);
|
||||
assert.equal(
|
||||
text[0][1],
|
||||
'A LONG SYNTHETI',
|
||||
'the shared title character limit remains active',
|
||||
);
|
||||
assert.equal(text[1][1], '© A very long s…');
|
||||
for (const [, label, x] of text) {
|
||||
assert.equal(x, 14);
|
||||
assert.ok(ctx.measureText(label).width <= 96, label);
|
||||
}
|
||||
});
|
||||
|
||||
test('tracked painter preserves centered multi-line readout metrics', () => {
|
||||
const ctx = mockContext();
|
||||
const entry = {
|
||||
@@ -482,15 +677,24 @@ test('shared tactical painter preserves FIRMS card metrics and top-rule treatmen
|
||||
verticalOnly: true,
|
||||
})[0];
|
||||
assert.equal(paintTacticalCard(ctx, entry, placement, 0.5), placement.rect);
|
||||
assert.deepEqual(ctx.calls.find(([name]) => name === 'moveTo'), ['moveTo', 200, 146]);
|
||||
assert.equal(ctx.calls.filter(([name]) => name === 'stroke').length, 2, 'leader + selected border');
|
||||
assert.deepEqual(
|
||||
ctx.calls.find(([name]) => name === 'moveTo'),
|
||||
['moveTo', 200, 146],
|
||||
);
|
||||
assert.equal(
|
||||
ctx.calls.filter(([name]) => name === 'stroke').length,
|
||||
2,
|
||||
'leader + selected border',
|
||||
);
|
||||
assert.equal(ctx.calls.filter(([name]) => name === 'fillText').length, 3);
|
||||
assert.equal(ctx.calls.at(-1)[0], 'restore');
|
||||
});
|
||||
|
||||
test('selected elbow leader reveals from the glyph before its card fades in', () => {
|
||||
const animation = {
|
||||
leaderAnimationMs: 1000, leaderAnimationStartedAt: 100, leaderDrawRatio: 0.7,
|
||||
leaderAnimationMs: 1000,
|
||||
leaderAnimationStartedAt: 100,
|
||||
leaderDrawRatio: 0.7,
|
||||
};
|
||||
assert.equal(leaderRevealProgress(animation, 100), 0);
|
||||
assert.ok(leaderRevealProgress(animation, 450) > 0.8);
|
||||
@@ -500,20 +704,44 @@ test('selected elbow leader reveals from the glyph before its card fades in', ()
|
||||
assert.equal(tacticalCardRevealAlpha(animation, 1100), 1);
|
||||
const ctx = mockContext();
|
||||
const entry = {
|
||||
variant: 'selected', selected: true, cardStyle: 'tactical', title: 'ALPR-2516',
|
||||
details: ['OSM MAPPED'], accent: '#ff6474', leaderStyle: 'elbow',
|
||||
leaderAnimationMs: 1, leaderAnimationStartedAt: 0,
|
||||
variant: 'selected',
|
||||
selected: true,
|
||||
cardStyle: 'tactical',
|
||||
title: 'ALPR-2516',
|
||||
details: ['OSM MAPPED'],
|
||||
accent: '#ff6474',
|
||||
leaderStyle: 'elbow',
|
||||
leaderAnimationMs: 1,
|
||||
leaderAnimationStartedAt: 0,
|
||||
};
|
||||
entry._overlayLayout = measureOverlayEntry(ctx, entry, {});
|
||||
const placement = placementVariants({
|
||||
anchorX: 240, anchorY: 180, width: entry._overlayLayout.w, height: entry._overlayLayout.h,
|
||||
viewportWidth: 500, viewportHeight: 300, gap: 20, leaderOffset: 30, verticalOnly: true,
|
||||
anchorX: 240,
|
||||
anchorY: 180,
|
||||
width: entry._overlayLayout.w,
|
||||
height: entry._overlayLayout.h,
|
||||
viewportWidth: 500,
|
||||
viewportHeight: 300,
|
||||
gap: 20,
|
||||
leaderOffset: 30,
|
||||
verticalOnly: true,
|
||||
})[0];
|
||||
paintTacticalCard(ctx, entry, placement, 1);
|
||||
assert.deepEqual(ctx.calls.find(([name]) => name === 'moveTo'), ['moveTo', 210, 180]);
|
||||
assert.deepEqual(
|
||||
ctx.calls.find(([name]) => name === 'moveTo'),
|
||||
['moveTo', 210, 180],
|
||||
);
|
||||
const lines = ctx.calls.filter(([name]) => name === 'lineTo');
|
||||
assert.ok(lines.length >= 2, 'leader draws horizontally from the glyph, then vertically to the card');
|
||||
assert.ok(ctx.calls.some(([name, value]) => name === 'strokeStyle' && value === 'rgba(255, 100, 116, 0.95)'));
|
||||
assert.ok(
|
||||
lines.length >= 2,
|
||||
'leader draws horizontally from the glyph, then vertically to the card',
|
||||
);
|
||||
assert.ok(
|
||||
ctx.calls.some(
|
||||
([name, value]) =>
|
||||
name === 'strokeStyle' && value === 'rgba(255, 100, 116, 0.95)',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('track display text is cached across measure and paint and invalidates on content change', () => {
|
||||
@@ -558,16 +786,33 @@ function alphaProbe() {
|
||||
const ctx = mockContext();
|
||||
const alphas = { fill: [], text: [], stroke: [] };
|
||||
const inner = { fill: ctx.fill, fillText: ctx.fillText, stroke: ctx.stroke };
|
||||
ctx.fill = function fill(...args) { alphas.fill.push(this.globalAlpha); return inner.fill.apply(this, args); };
|
||||
ctx.fillText = function fillText(...args) { alphas.text.push(this.globalAlpha); return inner.fillText.apply(this, args); };
|
||||
ctx.stroke = function stroke(...args) { alphas.stroke.push(this.globalAlpha); return inner.stroke.apply(this, args); };
|
||||
ctx.fill = function fill(...args) {
|
||||
alphas.fill.push(this.globalAlpha);
|
||||
return inner.fill.apply(this, args);
|
||||
};
|
||||
ctx.fillText = function fillText(...args) {
|
||||
alphas.text.push(this.globalAlpha);
|
||||
return inner.fillText.apply(this, args);
|
||||
};
|
||||
ctx.stroke = function stroke(...args) {
|
||||
alphas.stroke.push(this.globalAlpha);
|
||||
return inner.stroke.apply(this, args);
|
||||
};
|
||||
return { ctx, alphas };
|
||||
}
|
||||
|
||||
const CALLOUT_FIXTURE = Object.freeze({
|
||||
x: 20, y: 30, w: 80, h: 18,
|
||||
primaryX: 27, microX: 70, baseline: 42,
|
||||
leadFromX: 60, leadFromY: 60, leadToX: 60, leadToY: 48,
|
||||
x: 20,
|
||||
y: 30,
|
||||
w: 80,
|
||||
h: 18,
|
||||
primaryX: 27,
|
||||
microX: 70,
|
||||
baseline: 42,
|
||||
leadFromX: 60,
|
||||
leadFromY: 60,
|
||||
leadToX: 60,
|
||||
leadToY: 48,
|
||||
plate: 'rgba(2, 18, 26, 0.52)',
|
||||
accent: '#22e0ff',
|
||||
label: 'rgba(200, 250, 255, 0.97)',
|
||||
@@ -585,20 +830,36 @@ test('a sky-backed callout feathers its PLATE and nothing else', () => {
|
||||
const ground = alphaProbe();
|
||||
paintDetectionCallout(ground.ctx, { ...CALLOUT_FIXTURE, plateScale: 1 }, 0.8);
|
||||
const sky = alphaProbe();
|
||||
paintDetectionCallout(sky.ctx, { ...CALLOUT_FIXTURE, plateScale: SKY_PLATE_SCALE }, 0.8);
|
||||
paintDetectionCallout(
|
||||
sky.ctx,
|
||||
{ ...CALLOUT_FIXTURE, plateScale: SKY_PLATE_SCALE },
|
||||
0.8,
|
||||
);
|
||||
|
||||
// The plate is the FIRST fill; the tier accent bar is the second.
|
||||
assert.ok(Math.abs(ground.alphas.fill[0] - 0.8) < 1e-12, 'ground keeps the full plate');
|
||||
assert.ok(
|
||||
Math.abs(ground.alphas.fill[0] - 0.8) < 1e-12,
|
||||
'ground keeps the full plate',
|
||||
);
|
||||
assert.ok(
|
||||
Math.abs(sky.alphas.fill[0] - 0.8 * SKY_PLATE_SCALE) < 1e-12,
|
||||
'sky scales the plate by the token, not by some other number',
|
||||
);
|
||||
assert.deepEqual(
|
||||
sky.alphas.fill.slice(1), ground.alphas.fill.slice(1),
|
||||
sky.alphas.fill.slice(1),
|
||||
ground.alphas.fill.slice(1),
|
||||
'the accent bar must not inherit the plate feather',
|
||||
);
|
||||
assert.deepEqual(sky.alphas.text, ground.alphas.text, 'text opacity is untouched');
|
||||
assert.deepEqual(sky.alphas.stroke, ground.alphas.stroke, 'the leader is untouched');
|
||||
assert.deepEqual(
|
||||
sky.alphas.text,
|
||||
ground.alphas.text,
|
||||
'text opacity is untouched',
|
||||
);
|
||||
assert.deepEqual(
|
||||
sky.alphas.stroke,
|
||||
ground.alphas.stroke,
|
||||
'the leader is untouched',
|
||||
);
|
||||
// Same fill token in both: the theme's plate hue is scaled, never swapped.
|
||||
assert.equal(
|
||||
sky.ctx.calls.find(([name]) => name === 'fillStyle')?.[1],
|
||||
@@ -622,7 +883,12 @@ test('the sky plate scale is a whisper, not a second plate', () => {
|
||||
assert.ok(SKY_PLATE_SCALE > 0 && SKY_PLATE_SCALE <= 0.35);
|
||||
// Against the lightest shipped plate this must resolve to near-invisible.
|
||||
const lightest = Math.min(
|
||||
...Object.values(DETECTION_THEME_MAP).map((theme) => alphaOf(theme.calloutPlate)),
|
||||
...Object.values(DETECTION_THEME_MAP).map((theme) =>
|
||||
alphaOf(theme.calloutPlate),
|
||||
),
|
||||
);
|
||||
assert.ok(
|
||||
lightest * SKY_PLATE_SCALE < 0.12,
|
||||
'the feathered plate must read as bare text',
|
||||
);
|
||||
assert.ok(lightest * SKY_PLATE_SCALE < 0.12, 'the feathered plate must read as bare text');
|
||||
});
|
||||
Reference in new issue
Block a user