Zoom/Linien/Texte: weniger empfindliches Rad, Display-Strichbreite waechst sanft mit dem Zoom, Mindestbreite 1 px, Texte nach Groesse statt alles-oder-nichts ausblenden
This commit is contained in:
1 parent
98b85c55ea
commit
129516073c
6 files changed
+68
-16
No files matched your search
@@ -9,6 +9,7 @@ import { describe, expect, it } from "vitest";
|
||||
import type { Primitive } from "../generatePlan";
|
||||
import {
|
||||
expandRegion,
|
||||
indexedInRegion,
|
||||
primitiveBoundsVb,
|
||||
primitivesInRegion,
|
||||
regionContains,
|
||||
@@ -191,3 +192,17 @@ describe("primitivesInRegion", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('indexedInRegion: Text-Budget', () => {
|
||||
const txt = (h: number) => ({ kind: 'drawingText', heightM: h, at: { x: 0, y: 0 }, text: 'x', drawingId: 'd' }) as unknown as Primitive;
|
||||
const region = { minX: -1e9, minY: -1e9, maxX: 1e9, maxY: 1e9 };
|
||||
it('behält über dem Budget nur die grössten Texte', () => {
|
||||
const items = [1, 2, 3, 4, 5].map((h, i) => ({ p: txt(h), i }));
|
||||
const out = indexedInRegion(items, region, 0, 3);
|
||||
expect(out.map((o) => o.i)).toEqual([2, 3, 4]);
|
||||
});
|
||||
it('lässt alles durch, wenn das Budget reicht', () => {
|
||||
const items = [1, 2, 3].map((h, i) => ({ p: txt(h), i }));
|
||||
expect(indexedInRegion(items, region, 0, 10)).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
@@ -164,17 +164,47 @@ export function primitivesInRegion(
|
||||
return indexedInRegion(primitives.map((p, i) => ({ p, i })), region, minTextHeightVb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Höchstzahl gleichzeitig gezeichneter Text-Elemente (SVG-Overlay). Darüber werden
|
||||
* die GRÖSSTEN behalten und die kleinsten ausgeblendet — wie bei Karten: beim
|
||||
* Rauszoomen bleiben die wichtigen (grossen) Beschriftungen stehen, statt dass
|
||||
* ab einer festen Schwelle ALLE Texte auf einmal verschwinden.
|
||||
*/
|
||||
export const MAX_TEXT_ELEMENTS = 3000;
|
||||
|
||||
function textHeightVb(p: Primitive): number | null {
|
||||
return p.kind === "drawingText" || p.kind === "drawingTextPath" ? p.heightM * PX_PER_M : null;
|
||||
}
|
||||
|
||||
/** Wie {@link primitivesInRegion}, aber über eine schon vorgefilterte, indizierte Liste. */
|
||||
export function indexedInRegion(
|
||||
items: ReadonlyArray<{ p: Primitive; i: number }>,
|
||||
region: Bounds,
|
||||
minTextHeightVb = 0,
|
||||
maxTexts = MAX_TEXT_ELEMENTS,
|
||||
): Array<{ p: Primitive; i: number }> {
|
||||
const out: Array<{ p: Primitive; i: number }> = [];
|
||||
let texts = 0;
|
||||
for (const item of items) {
|
||||
if (isTooSmallToRead(item.p, minTextHeightVb)) continue;
|
||||
const b = primitiveBoundsVb(item.p);
|
||||
if (b === null || intersects(b, region)) out.push(item);
|
||||
if (b === null || intersects(b, region)) {
|
||||
out.push(item);
|
||||
if (textHeightVb(item.p) !== null) texts++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
if (texts <= maxTexts) return out;
|
||||
// Zu viele Texte: nur die grössten maxTexts behalten (Schwelle = Höhe des
|
||||
// maxTexts-grössten; Gleichstand darf die Grenze leicht überschreiten).
|
||||
const heights: number[] = [];
|
||||
for (const item of out) {
|
||||
const h = textHeightVb(item.p);
|
||||
if (h !== null) heights.push(h);
|
||||
}
|
||||
heights.sort((a, b) => b - a);
|
||||
const threshold = heights[maxTexts - 1];
|
||||
return out.filter((item) => {
|
||||
const h = textHeightVb(item.p);
|
||||
return h === null || h >= threshold;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user