@metronforge/concept-map 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/layout/stages/fixed-annotations.d.ts +5 -0
- package/dist/layout/stages/fixed-annotations.d.ts.map +1 -0
- package/dist/layout/stages/fixed-annotations.js +30 -0
- package/dist/layout/stages/fixed-annotations.js.map +1 -0
- package/dist/layout/stages/label-placement.d.ts +1 -1
- package/dist/layout/stages/label-placement.d.ts.map +1 -1
- package/dist/layout/stages/label-placement.js +12 -9
- package/dist/layout/stages/label-placement.js.map +1 -1
- package/dist/layout/stages/number-placement.d.ts +1 -1
- package/dist/layout/stages/number-placement.d.ts.map +1 -1
- package/dist/layout/stages/number-placement.js +17 -7
- package/dist/layout/stages/number-placement.js.map +1 -1
- package/dist/layout/stages/placement.d.ts +2 -2
- package/dist/layout/stages/placement.d.ts.map +1 -1
- package/dist/layout/stages/placement.js +3 -3
- package/dist/layout/stages/placement.js.map +1 -1
- package/dist/layout/stages/refine.d.ts +1 -1
- package/dist/layout/stages/refine.d.ts.map +1 -1
- package/dist/layout/stages/refine.js +6 -5
- package/dist/layout/stages/refine.js.map +1 -1
- package/package.json +1 -1
- package/src/layout/stages/fixed-annotations.ts +40 -0
- package/src/layout/stages/label-placement.ts +18 -11
- package/src/layout/stages/number-placement.ts +22 -7
- package/src/layout/stages/placement.ts +6 -3
- package/src/layout/stages/refine.ts +6 -6
package/README.md
CHANGED
|
@@ -55,11 +55,11 @@ Load the stylesheet, one module script and one element on an HTML page:
|
|
|
55
55
|
```html
|
|
56
56
|
<link
|
|
57
57
|
rel="stylesheet"
|
|
58
|
-
href="https://esm.sh/@metronforge/concept-map@0.3.
|
|
58
|
+
href="https://esm.sh/@metronforge/concept-map@0.3.2/css"
|
|
59
59
|
/>
|
|
60
60
|
<script
|
|
61
61
|
type="module"
|
|
62
|
-
src="https://esm.sh/@metronforge/concept-map@0.3.
|
|
62
|
+
src="https://esm.sh/@metronforge/concept-map@0.3.2/element"
|
|
63
63
|
></script>
|
|
64
64
|
<concept-map src="./map.json" layout="dagre"></concept-map>
|
|
65
65
|
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ResolvedMap } from "../../schema.js";
|
|
2
|
+
import type { Measurer } from "../ports.js";
|
|
3
|
+
/** Checker IDs eligible to stay at their re-measured positions. */
|
|
4
|
+
export declare function fixedAnnotations(map: ResolvedMap, measurer: Measurer): Set<string>;
|
|
5
|
+
//# sourceMappingURL=fixed-annotations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixed-annotations.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/fixed-annotations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAK5C,mEAAmE;AACnE,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,eAmBpE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { measured } from "../measured.js";
|
|
2
|
+
import { checkLabels } from "./label-check.js";
|
|
3
|
+
/** Checker IDs eligible to stay at their re-measured positions. */
|
|
4
|
+
export function fixedAnnotations(map, measurer) {
|
|
5
|
+
const report = checkLabels(map, map, {
|
|
6
|
+
measureLabel: (text, style) => paintedSize(measurer, text, style),
|
|
7
|
+
});
|
|
8
|
+
const touching = new Set(Object.values(report).flatMap((group) => Object.values(group).flatMap((contacts) => contacts.flatMap(({ a, b }) => [a, b]))));
|
|
9
|
+
const ids = Object.entries(map.edges).flatMap(([id, edge]) => [
|
|
10
|
+
...(edge.label ? [`label:${id}`] : []),
|
|
11
|
+
...(edge.badge ? [`step:${id}`] : []),
|
|
12
|
+
]);
|
|
13
|
+
for (const [i, scenario] of map.scenarios.entries())
|
|
14
|
+
for (const repeat of scenario.repeatBadges ?? [])
|
|
15
|
+
ids.push(`repeat:${i}:${repeat.step}`);
|
|
16
|
+
return new Set(ids.filter((id) => !touching.has(id)));
|
|
17
|
+
}
|
|
18
|
+
/** Include the painted halo without changing checker thresholds or metadata. */
|
|
19
|
+
function paintedSize(measurer, text, style) {
|
|
20
|
+
const size = measured(measurer.measure.bind(measurer), text, style);
|
|
21
|
+
const padding = size.padding ?? 0;
|
|
22
|
+
return {
|
|
23
|
+
...size,
|
|
24
|
+
left: (size.left ?? 0) - padding,
|
|
25
|
+
ascent: (size.ascent ?? (size.height * 5) / 6) + padding,
|
|
26
|
+
width: size.width + 2 * padding,
|
|
27
|
+
height: size.height + 2 * padding,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=fixed-annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixed-annotations.js","sourceRoot":"","sources":["../../../src/layout/stages/fixed-annotations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,mEAAmE;AACnE,MAAM,UAAU,gBAAgB,CAAC,GAAgB,EAAE,QAAkB;IACnE,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;QACnC,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC;KAClE,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CACtB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACtC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CACxC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,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AO;QAChC,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO;QACxD,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO;QAC/B,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ResolvedMap } from "../../schema.js";
|
|
2
2
|
/** Keep clear labels; reduce overlaps without introducing or deepening any. */
|
|
3
|
-
export declare function placeLabels(map: ResolvedMap): ResolvedMap;
|
|
3
|
+
export declare function placeLabels(map: ResolvedMap, fixed?: ReadonlySet<string>): ResolvedMap;
|
|
4
4
|
//# sourceMappingURL=label-placement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label-placement.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/label-placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAcnD,+EAA+E;AAC/E,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"label-placement.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/label-placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAcnD,+EAA+E;AAC/E,wBAAgB,WAAW,CACzB,GAAG,EAAE,WAAW,EAChB,KAAK,GAAE,WAAW,CAAC,MAAM,CAAa,GACrC,WAAW,CAcb"}
|
|
@@ -6,25 +6,25 @@ import { nodeSteps, TEXT } from "./drawn.js";
|
|
|
6
6
|
import { labelCandidates, labelCost, } from "./label-candidates.js";
|
|
7
7
|
import { labelBox } from "./number-placement.js";
|
|
8
8
|
/** Keep clear labels; reduce overlaps without introducing or deepening any. */
|
|
9
|
-
export function placeLabels(map) {
|
|
9
|
+
export function placeLabels(map, fixed = new Set()) {
|
|
10
10
|
// Every move reduces an integer penetration sum without worsening any gap,
|
|
11
11
|
// so the initial finite sum bounds the number of successful passes.
|
|
12
12
|
let current = map;
|
|
13
13
|
for (;;) {
|
|
14
|
-
const next = placeLabelPass(current);
|
|
14
|
+
const next = placeLabelPass(current, fixed);
|
|
15
15
|
if (Object.keys(next.edges).every((id) => next.edges[id] === current.edges[id]))
|
|
16
16
|
return next;
|
|
17
17
|
current = next;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
function placeLabelPass(map) {
|
|
20
|
+
function placeLabelPass(map, fixed) {
|
|
21
21
|
const { boxes, nodes, lines, steps, nodeStepPoints } = obstacles(map);
|
|
22
22
|
const gaps = lineGaps(Object.values(lines).flat());
|
|
23
23
|
const edges = { ...map.edges };
|
|
24
24
|
for (const [id, box] of Object.entries(boxes)) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (fixed.has(`label:${id}`))
|
|
26
|
+
continue;
|
|
27
|
+
const obstacles = nodes.concat(otherValues(boxes, id));
|
|
28
28
|
const contacts = contactReduction(box, [
|
|
29
29
|
...obstacles.map((o) => (b) => rectGap(b, o)),
|
|
30
30
|
...gaps,
|
|
@@ -34,9 +34,7 @@ function placeLabelPass(map) {
|
|
|
34
34
|
if (!contacts &&
|
|
35
35
|
!requiredPinStepContact(map, edge.label.at, size, box, nodeStepPoints))
|
|
36
36
|
continue;
|
|
37
|
-
const at = position(edge.label.at, map.viewBox, contacts ?? (() => 0), steps, size, obstacles, lines[id],
|
|
38
|
-
.filter(([key]) => key !== id)
|
|
39
|
-
.flatMap(([, route]) => route));
|
|
37
|
+
const at = position(edge.label.at, map.viewBox, contacts ?? (() => 0), steps, size, obstacles, lines[id], otherValues(lines, id).flat());
|
|
40
38
|
if (at === edge.label.at)
|
|
41
39
|
continue;
|
|
42
40
|
edges[id] = { ...edge, label: { ...edge.label, at } };
|
|
@@ -103,4 +101,9 @@ function candidateBaseline([cx, cy], box, at, size, viewBox) {
|
|
|
103
101
|
const y = Math.max(padding, Math.min(viewBox[1] - box[3] - padding, cy));
|
|
104
102
|
return [at[0] + x - box[0], at[1] + y - box[1]];
|
|
105
103
|
}
|
|
104
|
+
function otherValues(values, id) {
|
|
105
|
+
return Object.entries(values)
|
|
106
|
+
.filter(([key]) => key !== id)
|
|
107
|
+
.map(([, value]) => value);
|
|
108
|
+
}
|
|
106
109
|
//# sourceMappingURL=label-placement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"label-placement.js","sourceRoot":"","sources":["../../../src/layout/stages/label-placement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,SAAS,GAEV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,+EAA+E;AAC/E,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"label-placement.js","sourceRoot":"","sources":["../../../src/layout/stages/label-placement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,SAAS,GAEV,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,CAAC;AAC/B,CAAC"}
|
|
@@ -2,5 +2,5 @@ import type { ResolvedMap } from "../../schema.js";
|
|
|
2
2
|
import type { LayoutBox, LayoutPoint, LabelSize } from "../types.js";
|
|
3
3
|
export declare function labelBox(at: LayoutPoint, size: LabelSize, padding: number): LayoutBox;
|
|
4
4
|
/** One number-placement stage for engine output and measured hand drawings. */
|
|
5
|
-
export declare function placeNumbers(map: ResolvedMap): ResolvedMap;
|
|
5
|
+
export declare function placeNumbers(map: ResolvedMap, fixed?: ReadonlySet<string>): ResolvedMap;
|
|
6
6
|
//# sourceMappingURL=number-placement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-placement.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/number-placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGrE,wBAAgB,QAAQ,CACtB,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,GACd,SAAS,CAOX;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,
|
|
1
|
+
{"version":3,"file":"number-placement.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/number-placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGrE,wBAAgB,QAAQ,CACtB,EAAE,EAAE,WAAW,EACf,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,GACd,SAAS,CAOX;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAC1B,GAAG,EAAE,WAAW,EAChB,KAAK,GAAE,WAAW,CAAC,MAAM,CAAa,GACrC,WAAW,CAmBb"}
|
|
@@ -8,9 +8,10 @@ export function labelBox(at, size, padding) {
|
|
|
8
8
|
];
|
|
9
9
|
}
|
|
10
10
|
/** One number-placement stage for engine output and measured hand drawings. */
|
|
11
|
-
export function placeNumbers(map) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
export function placeNumbers(map, fixed = new Set()) {
|
|
12
|
+
const pinned = fixedNumberBoxes(map, fixed);
|
|
13
|
+
const obstacles = numberObstacles(map).concat(pinned);
|
|
14
|
+
const search = numberObstacles(map, true).concat(pinned);
|
|
14
15
|
const badge = (at) => {
|
|
15
16
|
const point = placeBadge(at, obstacles, map.viewBox, search);
|
|
16
17
|
const box = [point[0] - 8, point[1] - 8, 16, 16];
|
|
@@ -19,12 +20,13 @@ export function placeNumbers(map) {
|
|
|
19
20
|
return point;
|
|
20
21
|
};
|
|
21
22
|
const result = JSON.parse(JSON.stringify(map));
|
|
22
|
-
for (const edge of Object.
|
|
23
|
-
if (edge.badge)
|
|
23
|
+
for (const [id, edge] of Object.entries(result.edges))
|
|
24
|
+
if (edge.badge && !fixed.has(`step:${id}`))
|
|
24
25
|
edge.badge = badge(edge.badge);
|
|
25
|
-
for (const scenario of result.scenarios)
|
|
26
|
+
for (const [i, scenario] of result.scenarios.entries())
|
|
26
27
|
for (const repeat of scenario.repeatBadges ?? [])
|
|
27
|
-
|
|
28
|
+
if (!fixed.has(`repeat:${i}:${repeat.step}`))
|
|
29
|
+
repeat.at = badge(repeat.at);
|
|
28
30
|
return result;
|
|
29
31
|
}
|
|
30
32
|
function numberObstacles(map, rounded = false) {
|
|
@@ -38,4 +40,12 @@ function numberObstacles(map, rounded = false) {
|
|
|
38
40
|
}
|
|
39
41
|
return boxes;
|
|
40
42
|
}
|
|
43
|
+
function fixedNumberBoxes(map, fixed) {
|
|
44
|
+
const points = Object.entries(map.edges).flatMap(([id, edge]) => edge.badge && fixed.has(`step:${id}`) ? [edge.badge] : []);
|
|
45
|
+
for (const [i, scenario] of map.scenarios.entries())
|
|
46
|
+
for (const repeat of scenario.repeatBadges ?? [])
|
|
47
|
+
if (fixed.has(`repeat:${i}:${repeat.step}`))
|
|
48
|
+
points.push(repeat.at);
|
|
49
|
+
return points.map(([x, y]) => [x - 8, y - 8, 16, 16]);
|
|
50
|
+
}
|
|
41
51
|
//# sourceMappingURL=number-placement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-placement.js","sourceRoot":"","sources":["../../../src/layout/stages/number-placement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,UAAU,QAAQ,CACtB,EAAe,EACf,IAAe,EACf,OAAe;IAEf,OAAO;QACL,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;QAClC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO;QACxD,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO;KAC1B,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,YAAY,
|
|
1
|
+
{"version":3,"file":"number-placement.js","sourceRoot":"","sources":["../../../src/layout/stages/number-placement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,UAAU,QAAQ,CACtB,EAAe,EACf,IAAe,EACf,OAAe;IAEf,OAAO;QACL,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,OAAO;QAClC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAA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AAgB,CAAC,GAAgB,EAAE,KAA0B;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAC9D,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAC1D,CAAC;IACF,KAAK,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE;QACjD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,YAAY,IAAI,EAAE;YAC9C,IAAI,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACxE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAa,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ResolvedMap } from "../../schema.js";
|
|
2
|
-
/** Shared
|
|
3
|
-
export declare function placeAnnotations(map: ResolvedMap): ResolvedMap;
|
|
2
|
+
/** Shared placement; fixed IDs use the checker’s label/step/repeat names. */
|
|
3
|
+
export declare function placeAnnotations(map: ResolvedMap, fixed?: ReadonlySet<string>): ResolvedMap;
|
|
4
4
|
//# sourceMappingURL=placement.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,
|
|
1
|
+
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/placement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,EAChB,KAAK,GAAE,WAAW,CAAC,MAAM,CAAa,GACrC,WAAW,CAEb"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { placeNumbers } from "./number-placement.js";
|
|
2
2
|
import { placeLabels } from "./label-placement.js";
|
|
3
|
-
/** Shared
|
|
4
|
-
export function placeAnnotations(map) {
|
|
5
|
-
return placeLabels(placeNumbers(map));
|
|
3
|
+
/** Shared placement; fixed IDs use the checker’s label/step/repeat names. */
|
|
4
|
+
export function placeAnnotations(map, fixed = new Set()) {
|
|
5
|
+
return placeLabels(placeNumbers(map, fixed), fixed);
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=placement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placement.js","sourceRoot":"","sources":["../../../src/layout/stages/placement.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,
|
|
1
|
+
{"version":3,"file":"placement.js","sourceRoot":"","sources":["../../../src/layout/stages/placement.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAC9B,GAAgB,EAChB,QAA6B,IAAI,GAAG,EAAE;IAEtC,OAAO,WAAW,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResolvedMap } from "../../schema.js";
|
|
2
2
|
import type { Measurer } from "../ports.js";
|
|
3
3
|
/** Re-measure text and place labels and numbers, keeping all fixed geometry.
|
|
4
|
-
*
|
|
4
|
+
* Authored anchors stay put until a previous measurement is available.
|
|
5
5
|
* No input is mutated; the checker measures independently of this metadata. */
|
|
6
6
|
export declare function refine(map: ResolvedMap, measurer: Measurer): ResolvedMap;
|
|
7
7
|
//# sourceMappingURL=refine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refine.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/refine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"refine.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/refine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAkC5C;;+EAE+E;AAC/E,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAQxE"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { measureMono } from "../text-size.js";
|
|
2
1
|
import { measured } from "../measured.js";
|
|
3
2
|
import { placeAnnotations } from "./placement.js";
|
|
3
|
+
import { fixedAnnotations } from "./fixed-annotations.js";
|
|
4
4
|
const style = { fontSize: 10.5, mono: true };
|
|
5
5
|
function labels(map, measurer) {
|
|
6
6
|
const sizes = {};
|
|
7
7
|
const edges = Object.fromEntries(Object.entries(map.edges).map(([id, edge]) => {
|
|
8
8
|
if (!edge.label)
|
|
9
9
|
return [id, edge];
|
|
10
|
-
const previous = map.measurement?.labels[id] ?? measureMono(edge.label.text, style);
|
|
11
10
|
const size = measured(measurer.measure.bind(measurer), edge.label.text, {
|
|
12
11
|
...style,
|
|
13
12
|
edge: id,
|
|
14
13
|
});
|
|
14
|
+
const previous = map.measurement?.labels[id] ?? size;
|
|
15
15
|
const [x, y] = edge.label.at;
|
|
16
16
|
const at = [
|
|
17
17
|
x +
|
|
@@ -28,14 +28,15 @@ function labels(map, measurer) {
|
|
|
28
28
|
return { sizes, edges };
|
|
29
29
|
}
|
|
30
30
|
/** Re-measure text and place labels and numbers, keeping all fixed geometry.
|
|
31
|
-
*
|
|
31
|
+
* Authored anchors stay put until a previous measurement is available.
|
|
32
32
|
* No input is mutated; the checker measures independently of this metadata. */
|
|
33
33
|
export function refine(map, measurer) {
|
|
34
34
|
const text = labels(map, measurer);
|
|
35
|
-
|
|
35
|
+
const measuredMap = {
|
|
36
36
|
...map,
|
|
37
37
|
measurement: { name: measurer.name, labels: text.sizes },
|
|
38
38
|
edges: text.edges,
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
|
+
return placeAnnotations(measuredMap, fixedAnnotations(measuredMap, measurer));
|
|
40
41
|
}
|
|
41
42
|
//# sourceMappingURL=refine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refine.js","sourceRoot":"","sources":["../../../src/layout/stages/refine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"refine.js","sourceRoot":"","sources":["../../../src/layout/stages/refine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,MAAM,KAAK,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAE7C,SAAS,MA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CAAC,GAAG,IAAI,CAAC;QACjB,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzD,CAAC,CAAC,CACH,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC;AAED;;+EAE+E;AAC/E,MAAM,UAAU,MAAM,CAAC,GAAgB,EAAE,QAAkB;IACzD,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACnC,MAAM,WAAW,GAAG;QAClB,GAAG,GAAG;QACN,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE;QACxD,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;IACF,OAAO,gBAAgB,CAAC,WAAW,EAAE,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AAChF,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ResolvedMap } from "../../schema.js";
|
|
2
|
+
import type { Measurer } from "../ports.js";
|
|
3
|
+
import { measured } from "../measured.js";
|
|
4
|
+
import type { LabelStyle } from "../types.js";
|
|
5
|
+
import { checkLabels } from "./label-check.js";
|
|
6
|
+
|
|
7
|
+
/** Checker IDs eligible to stay at their re-measured positions. */
|
|
8
|
+
export function fixedAnnotations(map: ResolvedMap, measurer: Measurer) {
|
|
9
|
+
const report = checkLabels(map, map, {
|
|
10
|
+
measureLabel: (text, style) => paintedSize(measurer, text, style),
|
|
11
|
+
});
|
|
12
|
+
const touching = new Set(
|
|
13
|
+
Object.values(report).flatMap((group) =>
|
|
14
|
+
Object.values(group).flatMap((contacts) =>
|
|
15
|
+
contacts.flatMap(({ a, b }) => [a, b]),
|
|
16
|
+
),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
const ids = Object.entries(map.edges).flatMap(([id, edge]) => [
|
|
20
|
+
...(edge.label ? [`label:${id}`] : []),
|
|
21
|
+
...(edge.badge ? [`step:${id}`] : []),
|
|
22
|
+
]);
|
|
23
|
+
for (const [i, scenario] of map.scenarios.entries())
|
|
24
|
+
for (const repeat of scenario.repeatBadges ?? [])
|
|
25
|
+
ids.push(`repeat:${i}:${repeat.step}`);
|
|
26
|
+
return new Set(ids.filter((id) => !touching.has(id)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Include the painted halo without changing checker thresholds or metadata. */
|
|
30
|
+
function paintedSize(measurer: Measurer, text: string, style: LabelStyle) {
|
|
31
|
+
const size = measured(measurer.measure.bind(measurer), text, style);
|
|
32
|
+
const padding = size.padding ?? 0;
|
|
33
|
+
return {
|
|
34
|
+
...size,
|
|
35
|
+
left: (size.left ?? 0) - padding,
|
|
36
|
+
ascent: (size.ascent ?? (size.height * 5) / 6) + padding,
|
|
37
|
+
width: size.width + 2 * padding,
|
|
38
|
+
height: size.height + 2 * padding,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -13,12 +13,15 @@ import {
|
|
|
13
13
|
import { labelBox } from "./number-placement.js";
|
|
14
14
|
|
|
15
15
|
/** Keep clear labels; reduce overlaps without introducing or deepening any. */
|
|
16
|
-
export function placeLabels(
|
|
16
|
+
export function placeLabels(
|
|
17
|
+
map: ResolvedMap,
|
|
18
|
+
fixed: ReadonlySet<string> = new Set(),
|
|
19
|
+
): ResolvedMap {
|
|
17
20
|
// Every move reduces an integer penetration sum without worsening any gap,
|
|
18
21
|
// so the initial finite sum bounds the number of successful passes.
|
|
19
22
|
let current = map;
|
|
20
23
|
for (;;) {
|
|
21
|
-
const next = placeLabelPass(current);
|
|
24
|
+
const next = placeLabelPass(current, fixed);
|
|
22
25
|
if (
|
|
23
26
|
Object.keys(next.edges).every(
|
|
24
27
|
(id) => next.edges[id] === current.edges[id],
|
|
@@ -29,16 +32,16 @@ export function placeLabels(map: ResolvedMap): ResolvedMap {
|
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
function placeLabelPass(
|
|
35
|
+
function placeLabelPass(
|
|
36
|
+
map: ResolvedMap,
|
|
37
|
+
fixed: ReadonlySet<string>,
|
|
38
|
+
): ResolvedMap {
|
|
33
39
|
const { boxes, nodes, lines, steps, nodeStepPoints } = obstacles(map);
|
|
34
40
|
const gaps = lineGaps(Object.values(lines).flat());
|
|
35
41
|
const edges = { ...map.edges };
|
|
36
42
|
for (const [id, box] of Object.entries(boxes)) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.filter(([key]) => key !== id)
|
|
40
|
-
.map(([, b]) => b),
|
|
41
|
-
);
|
|
43
|
+
if (fixed.has(`label:${id}`)) continue;
|
|
44
|
+
const obstacles = nodes.concat(otherValues(boxes, id));
|
|
42
45
|
const contacts = contactReduction(box, [
|
|
43
46
|
...obstacles.map((o) => (b: LayoutBox) => rectGap(b, o)),
|
|
44
47
|
...gaps,
|
|
@@ -58,9 +61,7 @@ function placeLabelPass(map: ResolvedMap): ResolvedMap {
|
|
|
58
61
|
size,
|
|
59
62
|
obstacles,
|
|
60
63
|
lines[id],
|
|
61
|
-
|
|
62
|
-
.filter(([key]) => key !== id)
|
|
63
|
-
.flatMap(([, route]) => route),
|
|
64
|
+
otherValues(lines, id).flat(),
|
|
64
65
|
);
|
|
65
66
|
if (at === edge.label!.at) continue;
|
|
66
67
|
edges[id] = { ...edge, label: { ...edge.label!, at } };
|
|
@@ -166,3 +167,9 @@ function candidateBaseline(
|
|
|
166
167
|
const y = Math.max(padding, Math.min(viewBox[1] - box[3] - padding, cy));
|
|
167
168
|
return [at[0] + x - box[0], at[1] + y - box[1]];
|
|
168
169
|
}
|
|
170
|
+
|
|
171
|
+
function otherValues<T>(values: Record<string, T>, id: string): T[] {
|
|
172
|
+
return Object.entries(values)
|
|
173
|
+
.filter(([key]) => key !== id)
|
|
174
|
+
.map(([, value]) => value);
|
|
175
|
+
}
|
|
@@ -16,9 +16,13 @@ export function labelBox(
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** One number-placement stage for engine output and measured hand drawings. */
|
|
19
|
-
export function placeNumbers(
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export function placeNumbers(
|
|
20
|
+
map: ResolvedMap,
|
|
21
|
+
fixed: ReadonlySet<string> = new Set(),
|
|
22
|
+
): ResolvedMap {
|
|
23
|
+
const pinned = fixedNumberBoxes(map, fixed);
|
|
24
|
+
const obstacles = numberObstacles(map).concat(pinned);
|
|
25
|
+
const search = numberObstacles(map, true).concat(pinned);
|
|
22
26
|
const badge = (at: LayoutPoint) => {
|
|
23
27
|
const point = placeBadge(at, obstacles, map.viewBox, search);
|
|
24
28
|
const box: LayoutBox = [point[0] - 8, point[1] - 8, 16, 16];
|
|
@@ -27,11 +31,12 @@ export function placeNumbers(map: ResolvedMap): ResolvedMap {
|
|
|
27
31
|
return point;
|
|
28
32
|
};
|
|
29
33
|
const result = JSON.parse(JSON.stringify(map)) as ResolvedMap;
|
|
30
|
-
for (const edge of Object.
|
|
31
|
-
if (edge.badge) edge.badge = badge(edge.badge);
|
|
32
|
-
for (const scenario of result.scenarios)
|
|
34
|
+
for (const [id, edge] of Object.entries(result.edges))
|
|
35
|
+
if (edge.badge && !fixed.has(`step:${id}`)) edge.badge = badge(edge.badge);
|
|
36
|
+
for (const [i, scenario] of result.scenarios.entries())
|
|
33
37
|
for (const repeat of scenario.repeatBadges ?? [])
|
|
34
|
-
|
|
38
|
+
if (!fixed.has(`repeat:${i}:${repeat.step}`))
|
|
39
|
+
repeat.at = badge(repeat.at);
|
|
35
40
|
return result;
|
|
36
41
|
}
|
|
37
42
|
|
|
@@ -51,3 +56,13 @@ function numberObstacles(map: ResolvedMap, rounded = false) {
|
|
|
51
56
|
}
|
|
52
57
|
return boxes;
|
|
53
58
|
}
|
|
59
|
+
|
|
60
|
+
function fixedNumberBoxes(map: ResolvedMap, fixed: ReadonlySet<string>) {
|
|
61
|
+
const points = Object.entries(map.edges).flatMap(([id, edge]) =>
|
|
62
|
+
edge.badge && fixed.has(`step:${id}`) ? [edge.badge] : [],
|
|
63
|
+
);
|
|
64
|
+
for (const [i, scenario] of map.scenarios.entries())
|
|
65
|
+
for (const repeat of scenario.repeatBadges ?? [])
|
|
66
|
+
if (fixed.has(`repeat:${i}:${repeat.step}`)) points.push(repeat.at);
|
|
67
|
+
return points.map(([x, y]): LayoutBox => [x - 8, y - 8, 16, 16]);
|
|
68
|
+
}
|
|
@@ -2,7 +2,10 @@ import type { ResolvedMap } from "../../schema.js";
|
|
|
2
2
|
import { placeNumbers } from "./number-placement.js";
|
|
3
3
|
import { placeLabels } from "./label-placement.js";
|
|
4
4
|
|
|
5
|
-
/** Shared
|
|
6
|
-
export function placeAnnotations(
|
|
7
|
-
|
|
5
|
+
/** Shared placement; fixed IDs use the checker’s label/step/repeat names. */
|
|
6
|
+
export function placeAnnotations(
|
|
7
|
+
map: ResolvedMap,
|
|
8
|
+
fixed: ReadonlySet<string> = new Set(),
|
|
9
|
+
): ResolvedMap {
|
|
10
|
+
return placeLabels(placeNumbers(map, fixed), fixed);
|
|
8
11
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ResolvedMap } from "../../schema.js";
|
|
2
2
|
import type { Measurer } from "../ports.js";
|
|
3
3
|
import type { LabelSize, LayoutPoint } from "../types.js";
|
|
4
|
-
import { measureMono } from "../text-size.js";
|
|
5
4
|
import { measured } from "../measured.js";
|
|
6
5
|
import { placeAnnotations } from "./placement.js";
|
|
6
|
+
import { fixedAnnotations } from "./fixed-annotations.js";
|
|
7
7
|
const style = { fontSize: 10.5, mono: true };
|
|
8
8
|
|
|
9
9
|
function labels(map: ResolvedMap, measurer: Measurer) {
|
|
@@ -11,12 +11,11 @@ function labels(map: ResolvedMap, measurer: Measurer) {
|
|
|
11
11
|
const edges = Object.fromEntries(
|
|
12
12
|
Object.entries(map.edges).map(([id, edge]) => {
|
|
13
13
|
if (!edge.label) return [id, edge];
|
|
14
|
-
const previous =
|
|
15
|
-
map.measurement?.labels[id] ?? measureMono(edge.label.text, style);
|
|
16
14
|
const size = measured(measurer.measure.bind(measurer), edge.label.text, {
|
|
17
15
|
...style,
|
|
18
16
|
edge: id,
|
|
19
17
|
});
|
|
18
|
+
const previous = map.measurement?.labels[id] ?? size;
|
|
20
19
|
const [x, y] = edge.label.at;
|
|
21
20
|
const at: LayoutPoint = [
|
|
22
21
|
x +
|
|
@@ -35,13 +34,14 @@ function labels(map: ResolvedMap, measurer: Measurer) {
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
/** Re-measure text and place labels and numbers, keeping all fixed geometry.
|
|
38
|
-
*
|
|
37
|
+
* Authored anchors stay put until a previous measurement is available.
|
|
39
38
|
* No input is mutated; the checker measures independently of this metadata. */
|
|
40
39
|
export function refine(map: ResolvedMap, measurer: Measurer): ResolvedMap {
|
|
41
40
|
const text = labels(map, measurer);
|
|
42
|
-
|
|
41
|
+
const measuredMap = {
|
|
43
42
|
...map,
|
|
44
43
|
measurement: { name: measurer.name, labels: text.sizes },
|
|
45
44
|
edges: text.edges,
|
|
46
|
-
}
|
|
45
|
+
};
|
|
46
|
+
return placeAnnotations(measuredMap, fixedAnnotations(measuredMap, measurer));
|
|
47
47
|
}
|