@sentropic/design-system-svelte 0.34.75 → 0.35.1
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/LICENSE +21 -0
- package/LICENSE.THIRD-PARTY.md +141 -0
- package/dist/ForceGraph.svelte +13 -135
- package/dist/ForceGraph.svelte.d.ts.map +1 -1
- package/dist/{GeoMap.svelte → GeoChart.svelte} +72 -72
- package/dist/{GeoMap.svelte.d.ts → GeoChart.svelte.d.ts} +44 -44
- package/dist/GeoChart.svelte.d.ts.map +1 -0
- package/dist/Icon.svelte +35 -3
- package/dist/Icon.svelte.d.ts +5 -1
- package/dist/Icon.svelte.d.ts.map +1 -1
- package/dist/PriorityMatrix.svelte +241 -0
- package/dist/PriorityMatrix.svelte.d.ts +29 -0
- package/dist/PriorityMatrix.svelte.d.ts.map +1 -0
- package/dist/TimeRangePicker.svelte +38 -1
- package/dist/TimeRangePicker.svelte.d.ts +12 -0
- package/dist/TimeRangePicker.svelte.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/priorityLabels.d.ts +143 -0
- package/dist/priorityLabels.d.ts.map +1 -0
- package/dist/priorityLabels.js +239 -0
- package/package.json +5 -3
- package/dist/GeoMap.svelte.d.ts.map +0 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal priority-label placement for the DS PriorityMatrix component.
|
|
3
|
+
*
|
|
4
|
+
* STRUCTURAL TWIN of packages/dataviz-core/src/priorityMatrix.ts: same
|
|
5
|
+
* algorithm, same types, same behaviour. Duplicated (not imported) on purpose:
|
|
6
|
+
* the DS layer must not depend on @sentropic/dataviz-core, so this copy is
|
|
7
|
+
* kept in sync by hand. A shared golden-vector test pins all five copies to
|
|
8
|
+
* identical placements. Not exported from the package barrel (internal
|
|
9
|
+
* component use only).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Priority-matrix label placement (2x2 value/effort matrix).
|
|
13
|
+
*
|
|
14
|
+
* Pure TypeScript, no DOM. Given anchor points in frame pixels, label box
|
|
15
|
+
* sizes and a plot frame, returns label positions with leader lines back to
|
|
16
|
+
* their anchors. Deterministic: a fixed-seed PRNG drives the simulated-
|
|
17
|
+
* annealing refinement (d3-labeler style energy), so repeated calls with
|
|
18
|
+
* identical inputs return byte-identical outputs.
|
|
19
|
+
*
|
|
20
|
+
* Pipeline: greedy 8-candidate seeding around each anchor, then annealing over
|
|
21
|
+
* overlap area + anchor distance + point-cover + out-of-frame penalties, with
|
|
22
|
+
* hard clamping into the frame after every move.
|
|
23
|
+
*
|
|
24
|
+
* Best effort, not a guarantee: on dense sets labels may still overlap each
|
|
25
|
+
* other, cover points, cross the threshold lines or hide a quadrant name.
|
|
26
|
+
* Known limits (recommended cap around 50 points, estimated boxes, fixed
|
|
27
|
+
* frame, input-order dependence) are documented on `placePriorityLabels`.
|
|
28
|
+
*/
|
|
29
|
+
/** One matrix point in DATA space (0-100 per axis). */
|
|
30
|
+
export interface PriorityMatrixPoint {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
label: string;
|
|
34
|
+
}
|
|
35
|
+
/** Label box size in frame pixels (measured or estimated by the caller). */
|
|
36
|
+
export interface PriorityMatrixBox {
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
}
|
|
40
|
+
/** Plot frame in pixels: outer size plus inner plot margins. */
|
|
41
|
+
export interface PriorityMatrixFrame {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
marginLeft: number;
|
|
45
|
+
marginTop: number;
|
|
46
|
+
plotWidth: number;
|
|
47
|
+
plotHeight: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Fixed obstacle rectangle in frame pixels: a threshold keep-out band or a
|
|
51
|
+
* quadrant-name box derived by the caller from its own layout. Overlap with an
|
|
52
|
+
* obstacle is a soft cost weighted 4x above label/label overlap per px2, so a
|
|
53
|
+
* label crosses a thin threshold band only when every alternative is worse.
|
|
54
|
+
* Degenerate rectangles (non-finite or non-positive size) are ignored.
|
|
55
|
+
*/
|
|
56
|
+
export interface PriorityMatrixObstacle {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
w: number;
|
|
60
|
+
h: number;
|
|
61
|
+
}
|
|
62
|
+
/** Placed label: top-left box origin plus leader segment endpoints. */
|
|
63
|
+
export interface PriorityMatrixPlacement {
|
|
64
|
+
/** Index into the input points array. */
|
|
65
|
+
index: number;
|
|
66
|
+
/** Top-left box origin, clamped inside the frame. */
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
w: number;
|
|
70
|
+
h: number;
|
|
71
|
+
/** Anchor (point) position in frame pixels. */
|
|
72
|
+
anchorX: number;
|
|
73
|
+
anchorY: number;
|
|
74
|
+
/** Leader line from box edge (x1,y1) to anchor (x2,y2). */
|
|
75
|
+
leaderX1: number;
|
|
76
|
+
leaderY1: number;
|
|
77
|
+
leaderX2: number;
|
|
78
|
+
leaderY2: number;
|
|
79
|
+
/** Quadrant id of the datum. */
|
|
80
|
+
quadrant: PriorityQuadrant;
|
|
81
|
+
}
|
|
82
|
+
export type PriorityQuadrant = 'quick-wins' | 'major-projects' | 'wait' | 'drop';
|
|
83
|
+
/**
|
|
84
|
+
* Quadrant of a datum given thresholds (defaults 50/50).
|
|
85
|
+
* x = complexity (low left), y = value (high top).
|
|
86
|
+
*/
|
|
87
|
+
export declare function priorityQuadrant(x: number, y: number, xThreshold?: number, yThreshold?: number): PriorityQuadrant;
|
|
88
|
+
/**
|
|
89
|
+
* Rough box estimate from a label string when the caller has no measurement.
|
|
90
|
+
* Single line up to 12 chars, two lines beyond; capped at 120px wide.
|
|
91
|
+
*
|
|
92
|
+
* This is a glyph-count MODEL, not a measurement: it assumes narrow latin
|
|
93
|
+
* glyphs at 11px. Wide latin runs overflow the box (Inter 11px measured in
|
|
94
|
+
* Chromium, review figures: "MMMMMMMMMM" by 17.7px, "WWWWWWWWWWWW" by 26.7px;
|
|
95
|
+
* same-direction check with DejaVu Sans 11px advances: 12.9px and 34.5px) and
|
|
96
|
+
* CJK text overflows further ("データ可視化の基盤" by 24.0px in Inter 11px).
|
|
97
|
+
* The non-overlap behaviour only holds for narrow latin; there is currently
|
|
98
|
+
* no prop to pass caller-measured boxes through the DS components.
|
|
99
|
+
*/
|
|
100
|
+
export declare function estimatePriorityLabelBox(label: string): PriorityMatrixBox;
|
|
101
|
+
export interface PlacePriorityLabelsOptions {
|
|
102
|
+
xThreshold?: number;
|
|
103
|
+
yThreshold?: number;
|
|
104
|
+
/**
|
|
105
|
+
* PRNG seed for the annealing refinement; default 42. Identical inputs with
|
|
106
|
+
* the same seed return byte-identical outputs. Note: output is NOT stable
|
|
107
|
+
* across input orders — reversing the input array moves every label (13/13
|
|
108
|
+
* on the reference set, up to 177.4px, leaders 343px to 306px). Sort or
|
|
109
|
+
* stabilise the input order upstream when stability across data refreshes
|
|
110
|
+
* matters.
|
|
111
|
+
*/
|
|
112
|
+
seed?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Fixed obstacle rectangles (threshold bands, quadrant-name boxes) in frame
|
|
115
|
+
* pixels. Overlap with an obstacle costs 4x a label/label overlap per px2.
|
|
116
|
+
*/
|
|
117
|
+
obstacles?: readonly PriorityMatrixObstacle[];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Place one label per point. Never throws on degenerate input: non-finite
|
|
121
|
+
* coordinates fall back to the plot origin, empty arrays yield [].
|
|
122
|
+
*
|
|
123
|
+
* Cost model: label/label overlap area, point-cover (a label box covering ANY
|
|
124
|
+
* anchor — including its own — costs 300 in seeding, 800 in annealing, so
|
|
125
|
+
* opaque label boxes avoid hiding points), obstacle overlap, anchor distance,
|
|
126
|
+
* and out-of-frame penalties, refined by fixed-schedule simulated annealing.
|
|
127
|
+
*
|
|
128
|
+
* Complexity is O(n^2) per energy evaluation with max(1500, n*120) iterations,
|
|
129
|
+
* i.e. O(n^3) overall (the 1500 floor only dominates below 13 points, since n*120 passes 1500 at n=13). Measured
|
|
130
|
+
* (Node 22, desktop class, seeded random sets with long 2-line labels):
|
|
131
|
+
* n=13 in 3.2ms, n=30 in 13.7ms, n=50 in 36.8ms, n=80 in 137.8ms, n=100 in
|
|
132
|
+
* 258.9ms. Overlap counts are set-dependent (0/1/15/83/176 on that
|
|
133
|
+
* adversarial set). Recommended cap: around 50 points; beyond that both
|
|
134
|
+
* latency and overlaps degrade.
|
|
135
|
+
*
|
|
136
|
+
* Frame floor: with the shipped DS configuration (splitLabel boxes, threshold
|
|
137
|
+
* and name obstacles) the 13-point reference set is clean at 640x400, shows
|
|
138
|
+
* 1 overlap at 480x300 and 400x250, 9 overlaps at 320x200, 35 at 200x140, and
|
|
139
|
+
* 78 overlaps plus 12 out-of-plot boxes at 120x90. Do not render below
|
|
140
|
+
* roughly 480x300.
|
|
141
|
+
*/
|
|
142
|
+
export declare function placePriorityLabels(points: readonly PriorityMatrixPoint[], boxes: readonly PriorityMatrixBox[], frame: PriorityMatrixFrame, opts?: PlacePriorityLabelsOptions): PriorityMatrixPlacement[];
|
|
143
|
+
//# sourceMappingURL=priorityLabels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priorityLabels.d.ts","sourceRoot":"","sources":["../src/lib/priorityLabels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,uDAAuD;AACvD,MAAM,WAAW,mBAAmB;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;CACf;AAED,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,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;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,sBAAsB,EAAE,CAAC;CAC/C;AAoCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,mBAAmB,EAAE,EACtC,KAAK,EAAE,SAAS,iBAAiB,EAAE,EACnC,KAAK,EAAE,mBAAmB,EAC1B,IAAI,GAAE,0BAA+B,GACpC,uBAAuB,EAAE,CAkJ3B"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal priority-label placement for the DS PriorityMatrix component.
|
|
3
|
+
*
|
|
4
|
+
* STRUCTURAL TWIN of packages/dataviz-core/src/priorityMatrix.ts: same
|
|
5
|
+
* algorithm, same types, same behaviour. Duplicated (not imported) on purpose:
|
|
6
|
+
* the DS layer must not depend on @sentropic/dataviz-core, so this copy is
|
|
7
|
+
* kept in sync by hand. A shared golden-vector test pins all five copies to
|
|
8
|
+
* identical placements. Not exported from the package barrel (internal
|
|
9
|
+
* component use only).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Quadrant of a datum given thresholds (defaults 50/50).
|
|
13
|
+
* x = complexity (low left), y = value (high top).
|
|
14
|
+
*/
|
|
15
|
+
export function priorityQuadrant(x, y, xThreshold = 50, yThreshold = 50) {
|
|
16
|
+
if (x < xThreshold && y >= yThreshold)
|
|
17
|
+
return 'quick-wins';
|
|
18
|
+
if (x >= xThreshold && y >= yThreshold)
|
|
19
|
+
return 'major-projects';
|
|
20
|
+
if (x < xThreshold && y < yThreshold)
|
|
21
|
+
return 'wait';
|
|
22
|
+
return 'drop';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Rough box estimate from a label string when the caller has no measurement.
|
|
26
|
+
* Single line up to 12 chars, two lines beyond; capped at 120px wide.
|
|
27
|
+
*
|
|
28
|
+
* This is a glyph-count MODEL, not a measurement: it assumes narrow latin
|
|
29
|
+
* glyphs at 11px. Wide latin runs overflow the box (Inter 11px measured in
|
|
30
|
+
* Chromium, review figures: "MMMMMMMMMM" by 17.7px, "WWWWWWWWWWWW" by 26.7px;
|
|
31
|
+
* same-direction check with DejaVu Sans 11px advances: 12.9px and 34.5px) and
|
|
32
|
+
* CJK text overflows further ("データ可視化の基盤" by 24.0px in Inter 11px).
|
|
33
|
+
* The non-overlap behaviour only holds for narrow latin; there is currently
|
|
34
|
+
* no prop to pass caller-measured boxes through the DS components.
|
|
35
|
+
*/
|
|
36
|
+
export function estimatePriorityLabelBox(label) {
|
|
37
|
+
const chars = [...label].length;
|
|
38
|
+
if (chars === 0)
|
|
39
|
+
return { w: 12, h: 20 };
|
|
40
|
+
const lines = chars > 12 ? 2 : 1;
|
|
41
|
+
const longest = lines === 2 ? Math.ceil(chars / 2) : chars;
|
|
42
|
+
return { w: Math.min(120, 12 + 7 * longest), h: lines === 2 ? 34 : 20 };
|
|
43
|
+
}
|
|
44
|
+
const CANDIDATE_GAP = 8;
|
|
45
|
+
function mulberry32(seed) {
|
|
46
|
+
let a = seed >>> 0;
|
|
47
|
+
return () => {
|
|
48
|
+
a |= 0;
|
|
49
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
50
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
51
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
52
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function overlapArea(ax, ay, aw, ah, bx, by, bw, bh) {
|
|
56
|
+
const dx = Math.min(ax + aw, bx + bw) - Math.max(ax, bx);
|
|
57
|
+
const dy = Math.min(ay + ah, by + bh) - Math.max(ay, by);
|
|
58
|
+
return dx > 0 && dy > 0 ? dx * dy : 0;
|
|
59
|
+
}
|
|
60
|
+
function pointInBox(px, py, x, y, w, h, pad = 4) {
|
|
61
|
+
return px > x - pad && px < x + w + pad && py > y - pad && py < y + h + pad;
|
|
62
|
+
}
|
|
63
|
+
function clampInto(x, y, w, h, f) {
|
|
64
|
+
const minX = f.marginLeft;
|
|
65
|
+
const minY = f.marginTop;
|
|
66
|
+
const maxX = f.marginLeft + f.plotWidth - w;
|
|
67
|
+
const maxY = f.marginTop + f.plotHeight - h;
|
|
68
|
+
// Box wider/taller than the plot: pin to the origin instead of inverting.
|
|
69
|
+
if (maxX < minX)
|
|
70
|
+
return { x: minX, y: Math.min(Math.max(y, minY), Math.max(minY, f.marginTop + f.plotHeight - h)) };
|
|
71
|
+
if (maxY < minY)
|
|
72
|
+
return { x: Math.min(Math.max(x, minX), maxX), y: minY };
|
|
73
|
+
return { x: Math.min(Math.max(x, minX), maxX), y: Math.min(Math.max(y, minY), maxY) };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Place one label per point. Never throws on degenerate input: non-finite
|
|
77
|
+
* coordinates fall back to the plot origin, empty arrays yield [].
|
|
78
|
+
*
|
|
79
|
+
* Cost model: label/label overlap area, point-cover (a label box covering ANY
|
|
80
|
+
* anchor — including its own — costs 300 in seeding, 800 in annealing, so
|
|
81
|
+
* opaque label boxes avoid hiding points), obstacle overlap, anchor distance,
|
|
82
|
+
* and out-of-frame penalties, refined by fixed-schedule simulated annealing.
|
|
83
|
+
*
|
|
84
|
+
* Complexity is O(n^2) per energy evaluation with max(1500, n*120) iterations,
|
|
85
|
+
* i.e. O(n^3) overall (the 1500 floor only dominates below 13 points, since n*120 passes 1500 at n=13). Measured
|
|
86
|
+
* (Node 22, desktop class, seeded random sets with long 2-line labels):
|
|
87
|
+
* n=13 in 3.2ms, n=30 in 13.7ms, n=50 in 36.8ms, n=80 in 137.8ms, n=100 in
|
|
88
|
+
* 258.9ms. Overlap counts are set-dependent (0/1/15/83/176 on that
|
|
89
|
+
* adversarial set). Recommended cap: around 50 points; beyond that both
|
|
90
|
+
* latency and overlaps degrade.
|
|
91
|
+
*
|
|
92
|
+
* Frame floor: with the shipped DS configuration (splitLabel boxes, threshold
|
|
93
|
+
* and name obstacles) the 13-point reference set is clean at 640x400, shows
|
|
94
|
+
* 1 overlap at 480x300 and 400x250, 9 overlaps at 320x200, 35 at 200x140, and
|
|
95
|
+
* 78 overlaps plus 12 out-of-plot boxes at 120x90. Do not render below
|
|
96
|
+
* roughly 480x300.
|
|
97
|
+
*/
|
|
98
|
+
export function placePriorityLabels(points, boxes, frame, opts = {}) {
|
|
99
|
+
const xT = opts.xThreshold ?? 50;
|
|
100
|
+
const yT = opts.yThreshold ?? 50;
|
|
101
|
+
const seed = opts.seed ?? 42;
|
|
102
|
+
const obstacles = (opts.obstacles ?? []).filter((o) => Number.isFinite(o.x) && Number.isFinite(o.y) && o.w > 0 && o.h > 0);
|
|
103
|
+
const n = points.length;
|
|
104
|
+
if (n === 0)
|
|
105
|
+
return [];
|
|
106
|
+
const anchors = points.map((p) => ({
|
|
107
|
+
ax: Number.isFinite(p.x)
|
|
108
|
+
? frame.marginLeft + (Math.min(Math.max(p.x, 0), 100) / 100) * frame.plotWidth
|
|
109
|
+
: frame.marginLeft,
|
|
110
|
+
ay: Number.isFinite(p.y)
|
|
111
|
+
? frame.marginTop + (1 - Math.min(Math.max(p.y, 0), 100) / 100) * frame.plotHeight
|
|
112
|
+
: frame.marginTop,
|
|
113
|
+
}));
|
|
114
|
+
const sizes = points.map((_, i) => {
|
|
115
|
+
const b = boxes[i];
|
|
116
|
+
const w = b && Number.isFinite(b.w) && b.w > 0 ? b.w : 12;
|
|
117
|
+
const h = b && Number.isFinite(b.h) && b.h > 0 ? b.h : 20;
|
|
118
|
+
return { w, h };
|
|
119
|
+
});
|
|
120
|
+
const offsets = [
|
|
121
|
+
[0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1],
|
|
122
|
+
];
|
|
123
|
+
const costAt = (idx, x, y, pos) => {
|
|
124
|
+
let c = 0;
|
|
125
|
+
const { w, h } = sizes[idx];
|
|
126
|
+
const left = frame.marginLeft;
|
|
127
|
+
const top = frame.marginTop;
|
|
128
|
+
const right = left + frame.plotWidth;
|
|
129
|
+
const bottom = top + frame.plotHeight;
|
|
130
|
+
c += (Math.max(left - x, 0) + Math.max(x + w - right, 0) + Math.max(top - y, 0) + Math.max(y + h - bottom, 0)) * 400;
|
|
131
|
+
for (let j = 0; j < n; j++) {
|
|
132
|
+
if (j === idx || pos[j] === undefined)
|
|
133
|
+
continue;
|
|
134
|
+
c += overlapArea(x, y, w, h, pos[j].x, pos[j].y, sizes[j].w, sizes[j].h) * 2;
|
|
135
|
+
}
|
|
136
|
+
for (let j = 0; j < n; j++) {
|
|
137
|
+
if (pointInBox(anchors[j].ax, anchors[j].ay, x, y, w, h))
|
|
138
|
+
c += 300;
|
|
139
|
+
}
|
|
140
|
+
// Obstacles (threshold bands, quadrant names) cost 4x a label/label overlap
|
|
141
|
+
// per px2. That is a nudge, not a veto: crossing a 6px band with a 68x20
|
|
142
|
+
// box costs 960 here against 2720 for fully overlapping another label,
|
|
143
|
+
// about a third, so a band is still crossed when nothing else fits.
|
|
144
|
+
for (const o of obstacles) {
|
|
145
|
+
c += overlapArea(x, y, w, h, o.x, o.y, o.w, o.h) * 8;
|
|
146
|
+
}
|
|
147
|
+
c += Math.hypot(x + w / 2 - anchors[idx].ax, y + h / 2 - anchors[idx].ay) * 0.5;
|
|
148
|
+
return c;
|
|
149
|
+
};
|
|
150
|
+
// Greedy seeding in stable y-then-x order.
|
|
151
|
+
const order = points.map((_, i) => i).sort((a, b) => anchors[a].ay - anchors[b].ay || anchors[a].ax - anchors[b].ax);
|
|
152
|
+
const pos = new Array(n);
|
|
153
|
+
for (const idx of order) {
|
|
154
|
+
let bestX = anchors[idx].ax;
|
|
155
|
+
let bestY = anchors[idx].ay;
|
|
156
|
+
let bestC = Infinity;
|
|
157
|
+
for (const [dx, dy] of offsets) {
|
|
158
|
+
const cx = anchors[idx].ax + dx * (sizes[idx].w / 2 + CANDIDATE_GAP) - sizes[idx].w / 2;
|
|
159
|
+
const cy = anchors[idx].ay + dy * (sizes[idx].h / 2 + CANDIDATE_GAP) - sizes[idx].h / 2;
|
|
160
|
+
const cc = costAt(idx, cx, cy, pos);
|
|
161
|
+
if (cc < bestC) {
|
|
162
|
+
bestC = cc;
|
|
163
|
+
bestX = cx;
|
|
164
|
+
bestY = cy;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const cl = clampInto(bestX, bestY, sizes[idx].w, sizes[idx].h, frame);
|
|
168
|
+
pos[idx] = cl;
|
|
169
|
+
}
|
|
170
|
+
// Simulated-annealing refinement (fixed seed ⇒ deterministic).
|
|
171
|
+
const rnd = mulberry32(seed);
|
|
172
|
+
const energy = () => {
|
|
173
|
+
let e = 0;
|
|
174
|
+
for (let i = 0; i < n; i++) {
|
|
175
|
+
const { w, h } = sizes[i];
|
|
176
|
+
e += Math.hypot(pos[i].x + w / 2 - anchors[i].ax, pos[i].y + h / 2 - anchors[i].ay) * 0.6;
|
|
177
|
+
if (pos[i].x < frame.marginLeft ||
|
|
178
|
+
pos[i].y < frame.marginTop ||
|
|
179
|
+
pos[i].x + w > frame.marginLeft + frame.plotWidth ||
|
|
180
|
+
pos[i].y + h > frame.marginTop + frame.plotHeight) {
|
|
181
|
+
e += 5000;
|
|
182
|
+
}
|
|
183
|
+
for (let j = 0; j < n; j++) {
|
|
184
|
+
if (pointInBox(anchors[j].ax, anchors[j].ay, pos[i].x, pos[i].y, w, h))
|
|
185
|
+
e += 800;
|
|
186
|
+
}
|
|
187
|
+
for (const o of obstacles) {
|
|
188
|
+
e += overlapArea(pos[i].x, pos[i].y, w, h, o.x, o.y, o.w, o.h) * 12;
|
|
189
|
+
}
|
|
190
|
+
for (let j = i + 1; j < n; j++) {
|
|
191
|
+
e += overlapArea(pos[i].x, pos[i].y, w, h, pos[j].x, pos[j].y, sizes[j].w, sizes[j].h) * 3;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return e;
|
|
195
|
+
};
|
|
196
|
+
let e = energy();
|
|
197
|
+
let temp = 800;
|
|
198
|
+
const iters = Math.max(1500, n * 120);
|
|
199
|
+
const cool = Math.pow(1 / 800, 1 / iters);
|
|
200
|
+
for (let k = 0; k < iters; k++) {
|
|
201
|
+
const i = Math.floor(rnd() * n);
|
|
202
|
+
const ox = pos[i].x;
|
|
203
|
+
const oy = pos[i].y;
|
|
204
|
+
const step = 6 + temp / 40;
|
|
205
|
+
const cl = clampInto(pos[i].x + (rnd() * 2 - 1) * step, pos[i].y + (rnd() * 2 - 1) * step, sizes[i].w, sizes[i].h, frame);
|
|
206
|
+
pos[i] = cl;
|
|
207
|
+
const ne = energy();
|
|
208
|
+
if (ne < e || rnd() < Math.exp((e - ne) / Math.max(temp, 1e-9))) {
|
|
209
|
+
e = ne;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
pos[i] = { x: ox, y: oy };
|
|
213
|
+
}
|
|
214
|
+
temp *= cool;
|
|
215
|
+
}
|
|
216
|
+
return points.map((p, i) => {
|
|
217
|
+
const { w, h } = sizes[i];
|
|
218
|
+
const bx = pos[i].x;
|
|
219
|
+
const by = pos[i].y;
|
|
220
|
+
// Leader from the closest point of the box to the anchor (edge-clamped;
|
|
221
|
+
// zero-length when the anchor lies inside the box) to the anchor.
|
|
222
|
+
const cx = Math.min(Math.max(anchors[i].ax, bx), bx + w);
|
|
223
|
+
const cy = Math.min(Math.max(anchors[i].ay, by), by + h);
|
|
224
|
+
return {
|
|
225
|
+
index: i,
|
|
226
|
+
x: bx,
|
|
227
|
+
y: by,
|
|
228
|
+
w,
|
|
229
|
+
h,
|
|
230
|
+
anchorX: anchors[i].ax,
|
|
231
|
+
anchorY: anchors[i].ay,
|
|
232
|
+
leaderX1: cx,
|
|
233
|
+
leaderY1: cy,
|
|
234
|
+
leaderX2: anchors[i].ax,
|
|
235
|
+
leaderY2: anchors[i].ay,
|
|
236
|
+
quadrant: priorityQuadrant(p.x, p.y, xT, yT),
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/design-system-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.1",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"publishConfig": {
|
|
6
7
|
"access": "public"
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
],
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@lucide/svelte": "^0.562.0",
|
|
35
|
-
"@sentropic/design-system-themes": "0.11.0"
|
|
36
|
+
"@sentropic/design-system-themes": "0.11.0",
|
|
37
|
+
"@sentropic/graph": "0.3.0"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"svelte": "^5.53.2"
|
|
@@ -50,6 +52,6 @@
|
|
|
50
52
|
"@testing-library/svelte": "^5.2.8",
|
|
51
53
|
"svelte": "^5.53.2",
|
|
52
54
|
"vite": "^8.0.16",
|
|
53
|
-
"vitest": "^4.
|
|
55
|
+
"vitest": "^4.1.11"
|
|
54
56
|
}
|
|
55
57
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeoMap.svelte.d.ts","sourceRoot":"","sources":["../src/lib/GeoMap.svelte.ts"],"names":[],"mappings":"AAGE,MAAM,MAAM,UAAU,GAClB,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,GACrD,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1D,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,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