@opendata-ai/openchart-vanilla 9.0.0-rc.2 → 9.0.0
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 +10 -0
- package/dist/{chunk-RY5JEGFM.js → chunk-42WVDS3V.js} +161 -26
- package/dist/chunk-42WVDS3V.js.map +1 -0
- package/dist/{chunk-46E3QB6O.js → chunk-6GRMMSQA.js} +2 -2
- package/dist/{chunk-A5C4VCUO.js → chunk-7XFFPRQ7.js} +13 -4
- package/dist/chunk-7XFFPRQ7.js.map +1 -0
- package/dist/chunk-E3ETKTJQ.js +130 -0
- package/dist/chunk-E3ETKTJQ.js.map +1 -0
- package/dist/{chunk-5ZLSMZRM.js → chunk-HQ5GADZ4.js} +9 -8
- package/dist/{chunk-5ZLSMZRM.js.map → chunk-HQ5GADZ4.js.map} +1 -1
- package/dist/{chunk-5OQZRGUL.js → chunk-NGNHQOXO.js} +1064 -971
- package/dist/chunk-NGNHQOXO.js.map +1 -0
- package/dist/{chunk-RBXIZJPE.js → chunk-OEJHSKFZ.js} +2 -2
- package/dist/{chunk-CMIJA63X.js → chunk-RWP23N4D.js} +3 -3
- package/dist/chunk-SKQAAHHR.js +533 -0
- package/dist/chunk-SKQAAHHR.js.map +1 -0
- package/dist/{chunk-NLKQ5AOA.js → chunk-XR4B3SPC.js} +70 -30
- package/dist/chunk-XR4B3SPC.js.map +1 -0
- package/dist/export-gif.js +4 -4
- package/dist/graph-3d/index.js +4 -4
- package/dist/index.d.ts +41 -51
- package/dist/index.js +85 -216
- package/dist/index.js.map +1 -1
- package/dist/static.d.ts +10 -21
- package/dist/static.js +417 -118
- package/dist/static.js.map +1 -1
- package/dist/story/index.js +7 -7
- package/dist/styles.css.map +1 -1
- package/package.json +4 -7
- package/dist/chunk-5OQZRGUL.js.map +0 -1
- package/dist/chunk-A5C4VCUO.js.map +0 -1
- package/dist/chunk-FFP5GXIP.js +0 -45
- package/dist/chunk-FFP5GXIP.js.map +0 -1
- package/dist/chunk-LDSPJFOU.js +0 -297
- package/dist/chunk-LDSPJFOU.js.map +0 -1
- package/dist/chunk-NLKQ5AOA.js.map +0 -1
- package/dist/chunk-RY5JEGFM.js.map +0 -1
- /package/dist/{chunk-46E3QB6O.js.map → chunk-6GRMMSQA.js.map} +0 -0
- /package/dist/{chunk-RBXIZJPE.js.map → chunk-OEJHSKFZ.js.map} +0 -0
- /package/dist/{chunk-CMIJA63X.js.map → chunk-RWP23N4D.js.map} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
clamp01,
|
|
3
|
+
createRenderContext,
|
|
3
4
|
cubicInOut,
|
|
4
5
|
cubicOut,
|
|
5
6
|
lerp,
|
|
@@ -10,36 +11,17 @@ import {
|
|
|
10
11
|
renderChromeElement,
|
|
11
12
|
resolvedSurface,
|
|
12
13
|
stampThemeProperties
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-XR4B3SPC.js";
|
|
14
15
|
import {
|
|
15
16
|
SVG_NS,
|
|
16
17
|
applyKnockoutHalo,
|
|
17
18
|
applyTextStyle,
|
|
18
19
|
createSVGElement,
|
|
19
20
|
setAttrs
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
|
|
22
|
-
// src/svg-ids.ts
|
|
23
|
-
var counter = 0;
|
|
24
|
-
var idPrefix = "";
|
|
25
|
-
function captureSvgIdState() {
|
|
26
|
-
return { counter, prefix: idPrefix };
|
|
27
|
-
}
|
|
28
|
-
function restoreSvgIdState(state) {
|
|
29
|
-
counter = state.counter;
|
|
30
|
-
idPrefix = state.prefix;
|
|
31
|
-
}
|
|
32
|
-
function nextSvgId(prefix) {
|
|
33
|
-
return `${idPrefix}${prefix}-${counter++}`;
|
|
34
|
-
}
|
|
35
|
-
function resetSvgIdCounter(prefix = "") {
|
|
36
|
-
counter = 0;
|
|
37
|
-
idPrefix = prefix ? `${prefix}-` : "";
|
|
38
|
-
}
|
|
21
|
+
} from "./chunk-E3ETKTJQ.js";
|
|
39
22
|
|
|
40
23
|
// src/gradient-utils.ts
|
|
41
24
|
import { isGradientDef } from "@opendata-ai/openchart-core";
|
|
42
|
-
var SVG_NS2 = "http://www.w3.org/2000/svg";
|
|
43
25
|
function gradientKey(def) {
|
|
44
26
|
return sortedStringify(def);
|
|
45
27
|
}
|
|
@@ -52,14 +34,14 @@ function sortedStringify(value) {
|
|
|
52
34
|
}
|
|
53
35
|
return JSON.stringify(value);
|
|
54
36
|
}
|
|
55
|
-
function createGradientElement(def, id) {
|
|
37
|
+
function createGradientElement(def, id, ctx = createRenderContext()) {
|
|
56
38
|
if (def.gradient === "linear") {
|
|
57
|
-
return createLinearGradient(def, id);
|
|
39
|
+
return createLinearGradient(def, id, ctx);
|
|
58
40
|
}
|
|
59
|
-
return createRadialGradient(def, id);
|
|
41
|
+
return createRadialGradient(def, id, ctx);
|
|
60
42
|
}
|
|
61
|
-
function createLinearGradient(def, id) {
|
|
62
|
-
const el =
|
|
43
|
+
function createLinearGradient(def, id, ctx = createRenderContext()) {
|
|
44
|
+
const el = ctx.factory.svg("linearGradient");
|
|
63
45
|
el.setAttribute("id", id);
|
|
64
46
|
el.setAttribute("gradientUnits", "objectBoundingBox");
|
|
65
47
|
el.setAttribute("x1", String(def.x1 ?? 0));
|
|
@@ -67,12 +49,12 @@ function createLinearGradient(def, id) {
|
|
|
67
49
|
el.setAttribute("x2", String(def.x2 ?? 0));
|
|
68
50
|
el.setAttribute("y2", String(def.y2 ?? 1));
|
|
69
51
|
for (const stop of def.stops) {
|
|
70
|
-
appendStop(el, stop);
|
|
52
|
+
appendStop(el, stop, ctx);
|
|
71
53
|
}
|
|
72
54
|
return el;
|
|
73
55
|
}
|
|
74
|
-
function createRadialGradient(def, id) {
|
|
75
|
-
const el =
|
|
56
|
+
function createRadialGradient(def, id, ctx = createRenderContext()) {
|
|
57
|
+
const el = ctx.factory.svg("radialGradient");
|
|
76
58
|
el.setAttribute("id", id);
|
|
77
59
|
el.setAttribute("gradientUnits", "objectBoundingBox");
|
|
78
60
|
el.setAttribute("cx", String(def.x2 ?? 0.5));
|
|
@@ -82,12 +64,12 @@ function createRadialGradient(def, id) {
|
|
|
82
64
|
el.setAttribute("fy", String(def.y1 ?? 0.5));
|
|
83
65
|
el.setAttribute("fr", String(def.r1 ?? 0));
|
|
84
66
|
for (const stop of def.stops) {
|
|
85
|
-
appendStop(el, stop);
|
|
67
|
+
appendStop(el, stop, ctx);
|
|
86
68
|
}
|
|
87
69
|
return el;
|
|
88
70
|
}
|
|
89
|
-
function appendStop(parent, stop) {
|
|
90
|
-
const stopEl =
|
|
71
|
+
function appendStop(parent, stop, ctx = createRenderContext()) {
|
|
72
|
+
const stopEl = ctx.factory.svg("stop");
|
|
91
73
|
stopEl.setAttribute("offset", String(stop.offset));
|
|
92
74
|
stopEl.setAttribute("stop-color", stop.color);
|
|
93
75
|
if (stop.opacity !== void 0) {
|
|
@@ -95,15 +77,15 @@ function appendStop(parent, stop) {
|
|
|
95
77
|
}
|
|
96
78
|
parent.appendChild(stopEl);
|
|
97
79
|
}
|
|
98
|
-
function buildGradientDefs(marks, defs) {
|
|
80
|
+
function buildGradientDefs(marks, defs, ctx = createRenderContext()) {
|
|
99
81
|
const map = /* @__PURE__ */ new Map();
|
|
100
82
|
for (const mark of marks) {
|
|
101
83
|
const fill = mark.fill;
|
|
102
84
|
if (fill && isGradientDef(fill)) {
|
|
103
85
|
const key = gradientKey(fill);
|
|
104
86
|
if (!map.has(key)) {
|
|
105
|
-
const id =
|
|
106
|
-
const el = createGradientElement(fill, id);
|
|
87
|
+
const id = ctx.ids.next("oc-grad");
|
|
88
|
+
const el = createGradientElement(fill, id, ctx);
|
|
107
89
|
defs.appendChild(el);
|
|
108
90
|
map.set(key, id);
|
|
109
91
|
}
|
|
@@ -119,25 +101,24 @@ function resolveMarkFill(fill, gradientMap) {
|
|
|
119
101
|
}
|
|
120
102
|
|
|
121
103
|
// src/pattern-utils.ts
|
|
122
|
-
var SVG_NS3 = "http://www.w3.org/2000/svg";
|
|
123
104
|
var TILE = 6;
|
|
124
105
|
var LINE_OPACITY = 0.55;
|
|
125
106
|
function patternKey(p) {
|
|
126
107
|
return `${p.type}|${p.base}|${p.line}`;
|
|
127
108
|
}
|
|
128
|
-
function createPatternElement(p, id) {
|
|
129
|
-
const el =
|
|
109
|
+
function createPatternElement(p, id, ctx = createRenderContext()) {
|
|
110
|
+
const el = ctx.factory.svg("pattern");
|
|
130
111
|
el.setAttribute("id", id);
|
|
131
112
|
el.setAttribute("patternUnits", "userSpaceOnUse");
|
|
132
113
|
el.setAttribute("width", String(TILE));
|
|
133
114
|
el.setAttribute("height", String(TILE));
|
|
134
|
-
const bg =
|
|
115
|
+
const bg = ctx.factory.svg("rect");
|
|
135
116
|
bg.setAttribute("width", String(TILE));
|
|
136
117
|
bg.setAttribute("height", String(TILE));
|
|
137
118
|
bg.setAttribute("fill", p.base);
|
|
138
119
|
el.appendChild(bg);
|
|
139
120
|
if (p.type === "dot") {
|
|
140
|
-
const dot =
|
|
121
|
+
const dot = ctx.factory.svg("circle");
|
|
141
122
|
dot.setAttribute("cx", String(TILE / 2));
|
|
142
123
|
dot.setAttribute("cy", String(TILE / 2));
|
|
143
124
|
dot.setAttribute("r", "1.2");
|
|
@@ -147,7 +128,7 @@ function createPatternElement(p, id) {
|
|
|
147
128
|
return el;
|
|
148
129
|
}
|
|
149
130
|
const d = p.type === "diagonal" ? `M0,${TILE} l${TILE},-${TILE} M-1.5,1.5 l3,-3 M${TILE - 1.5},${TILE + 1.5} l3,-3` : p.type === "crosshatch" ? `M0,0 l${TILE},${TILE} M${TILE},0 l-${TILE},${TILE}` : `M${TILE / 2},0 V${TILE}`;
|
|
150
|
-
const path =
|
|
131
|
+
const path = ctx.factory.svg("path");
|
|
151
132
|
path.setAttribute("d", d);
|
|
152
133
|
path.setAttribute("stroke", p.line);
|
|
153
134
|
path.setAttribute("stroke-width", "1");
|
|
@@ -155,15 +136,15 @@ function createPatternElement(p, id) {
|
|
|
155
136
|
el.appendChild(path);
|
|
156
137
|
return el;
|
|
157
138
|
}
|
|
158
|
-
function buildPatternDefs(marks, defs) {
|
|
139
|
+
function buildPatternDefs(marks, defs, ctx = createRenderContext()) {
|
|
159
140
|
const map = /* @__PURE__ */ new Map();
|
|
160
141
|
for (const mark of marks) {
|
|
161
142
|
const pattern = mark.pattern;
|
|
162
143
|
if (!pattern) continue;
|
|
163
144
|
const key = patternKey(pattern);
|
|
164
145
|
if (!map.has(key)) {
|
|
165
|
-
const id =
|
|
166
|
-
defs.appendChild(createPatternElement(pattern, id));
|
|
146
|
+
const id = ctx.ids.next("oc-pattern");
|
|
147
|
+
defs.appendChild(createPatternElement(pattern, id, ctx));
|
|
167
148
|
map.set(key, id);
|
|
168
149
|
}
|
|
169
150
|
}
|
|
@@ -175,35 +156,19 @@ function resolvePatternFill(pattern, patternMap) {
|
|
|
175
156
|
}
|
|
176
157
|
|
|
177
158
|
// src/renderers/marks.ts
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
function resetMarkRenderState() {
|
|
189
|
-
currentAnimation = void 0;
|
|
190
|
-
currentGradientMap = /* @__PURE__ */ new Map();
|
|
191
|
-
currentPatternMap = /* @__PURE__ */ new Map();
|
|
192
|
-
currentSurface = "";
|
|
193
|
-
}
|
|
194
|
-
function applyLabelHalo(text2, label) {
|
|
195
|
-
if (!currentSurface || label.halo === false) return;
|
|
196
|
-
applyKnockoutHalo(text2, currentSurface, label.style.fontSize);
|
|
197
|
-
}
|
|
198
|
-
function resolveFillOrPattern(fill, pattern) {
|
|
199
|
-
if (pattern) return resolvePatternFill(pattern, currentPatternMap);
|
|
200
|
-
return resolveMarkFill(fill, currentGradientMap);
|
|
201
|
-
}
|
|
202
|
-
function stampAnimationAttrs(el, mark, fallbackIndex) {
|
|
159
|
+
function applyLabelHalo(text2, label, ctx) {
|
|
160
|
+
if (!ctx.marks.surface || label.halo === false) return;
|
|
161
|
+
applyKnockoutHalo(text2, ctx.marks.surface, label.style.fontSize);
|
|
162
|
+
}
|
|
163
|
+
function resolveFillOrPattern(fill, pattern, ctx) {
|
|
164
|
+
if (pattern) return resolvePatternFill(pattern, ctx.marks.patternMap);
|
|
165
|
+
return resolveMarkFill(fill, ctx.marks.gradientMap);
|
|
166
|
+
}
|
|
167
|
+
function stampAnimationAttrs(el, mark, fallbackIndex, ctx) {
|
|
203
168
|
if (mark.key) {
|
|
204
169
|
el.setAttribute("data-key", mark.key);
|
|
205
170
|
}
|
|
206
|
-
if (!
|
|
171
|
+
if (!ctx.marks.animation?.enter) return;
|
|
207
172
|
const idx = mark.animationIndex ?? fallbackIndex;
|
|
208
173
|
el.setAttribute("data-animation-index", String(idx));
|
|
209
174
|
el.style.setProperty("--oc-mark-index", String(idx));
|
|
@@ -212,13 +177,13 @@ var markRenderers = {};
|
|
|
212
177
|
function registerMarkRenderer(type, renderer) {
|
|
213
178
|
markRenderers[type] = renderer;
|
|
214
179
|
}
|
|
215
|
-
function renderLineMark(mark, index) {
|
|
216
|
-
const g = createSVGElement("g");
|
|
180
|
+
function renderLineMark(mark, index, ctx = createRenderContext()) {
|
|
181
|
+
const g = createSVGElement("g", ctx.factory);
|
|
217
182
|
g.setAttribute("data-mark-id", `line-${index}`);
|
|
218
183
|
g.setAttribute("class", "oc-mark oc-mark-line");
|
|
219
|
-
stampAnimationAttrs(g, mark, index);
|
|
184
|
+
stampAnimationAttrs(g, mark, index, ctx);
|
|
220
185
|
if (mark.points.length > 1) {
|
|
221
|
-
const path = createSVGElement("path");
|
|
186
|
+
const path = createSVGElement("path", ctx.factory);
|
|
222
187
|
const d = mark.path ?? mark.points.map((p, i) => `${i === 0 ? "M" : "L"}${p.x},${p.y}`).join(" ");
|
|
223
188
|
setAttrs(path, {
|
|
224
189
|
d,
|
|
@@ -239,7 +204,7 @@ function renderLineMark(mark, index) {
|
|
|
239
204
|
g.appendChild(path);
|
|
240
205
|
}
|
|
241
206
|
if (mark.label?.visible) {
|
|
242
|
-
const label = createSVGElement("text");
|
|
207
|
+
const label = createSVGElement("text", ctx.factory);
|
|
243
208
|
label.setAttribute("class", "oc-mark-label");
|
|
244
209
|
if (mark.key) label.setAttribute("data-label-key", mark.key);
|
|
245
210
|
if (mark.seriesKey) {
|
|
@@ -247,11 +212,11 @@ function renderLineMark(mark, index) {
|
|
|
247
212
|
}
|
|
248
213
|
setAttrs(label, { x: mark.label.x, y: mark.label.y });
|
|
249
214
|
applyTextStyle(label, mark.label.style);
|
|
250
|
-
applyLabelHalo(label, mark.label);
|
|
215
|
+
applyLabelHalo(label, mark.label, ctx);
|
|
251
216
|
label.textContent = mark.label.text;
|
|
252
217
|
g.appendChild(label);
|
|
253
218
|
if (mark.label.connector) {
|
|
254
|
-
const connector = createSVGElement("line");
|
|
219
|
+
const connector = createSVGElement("line", ctx.factory);
|
|
255
220
|
connector.setAttribute("class", "oc-mark-connector");
|
|
256
221
|
setAttrs(connector, {
|
|
257
222
|
x1: mark.label.connector.from.x,
|
|
@@ -267,22 +232,22 @@ function renderLineMark(mark, index) {
|
|
|
267
232
|
}
|
|
268
233
|
return g;
|
|
269
234
|
}
|
|
270
|
-
function renderAreaMark(mark, index) {
|
|
271
|
-
const g = createSVGElement("g");
|
|
235
|
+
function renderAreaMark(mark, index, ctx = createRenderContext()) {
|
|
236
|
+
const g = createSVGElement("g", ctx.factory);
|
|
272
237
|
g.setAttribute("data-mark-id", `area-${index}`);
|
|
273
238
|
g.setAttribute("class", "oc-mark oc-mark-area");
|
|
274
|
-
stampAnimationAttrs(g, mark, index);
|
|
239
|
+
stampAnimationAttrs(g, mark, index, ctx);
|
|
275
240
|
if (mark.path) {
|
|
276
|
-
const fill = createSVGElement("path");
|
|
241
|
+
const fill = createSVGElement("path", ctx.factory);
|
|
277
242
|
setAttrs(fill, {
|
|
278
243
|
d: mark.path,
|
|
279
|
-
fill: resolveFillOrPattern(mark.fill, mark.pattern),
|
|
244
|
+
fill: resolveFillOrPattern(mark.fill, mark.pattern, ctx),
|
|
280
245
|
"fill-opacity": mark.fillOpacity,
|
|
281
246
|
stroke: "none"
|
|
282
247
|
});
|
|
283
248
|
g.appendChild(fill);
|
|
284
249
|
if (mark.stroke && mark.topPath) {
|
|
285
|
-
const strokePath = createSVGElement("path");
|
|
250
|
+
const strokePath = createSVGElement("path", ctx.factory);
|
|
286
251
|
strokePath.setAttribute("class", "oc-area-top");
|
|
287
252
|
setAttrs(strokePath, {
|
|
288
253
|
d: mark.topPath,
|
|
@@ -317,17 +282,17 @@ function rectPathWithCorners(mark, sides) {
|
|
|
317
282
|
"Z"
|
|
318
283
|
].filter(Boolean).join(" ");
|
|
319
284
|
}
|
|
320
|
-
function renderRectMark(mark, index) {
|
|
321
|
-
const g = createSVGElement("g");
|
|
285
|
+
function renderRectMark(mark, index, ctx = createRenderContext()) {
|
|
286
|
+
const g = createSVGElement("g", ctx.factory);
|
|
322
287
|
g.setAttribute("data-mark-id", `rect-${index}`);
|
|
323
288
|
g.setAttribute("class", "oc-mark oc-mark-rect");
|
|
324
|
-
stampAnimationAttrs(g, mark, index);
|
|
325
|
-
if (
|
|
289
|
+
stampAnimationAttrs(g, mark, index, ctx);
|
|
290
|
+
if (ctx.marks.animation?.enter && mark.orient === "horizontal") {
|
|
326
291
|
g.setAttribute("data-orient", "horizontal");
|
|
327
292
|
}
|
|
328
293
|
const sides = mark.cornerRadiusSides;
|
|
329
294
|
const partialCorners = !!sides && (!sides.tl || !sides.tr || !sides.br || !sides.bl) && !!mark.cornerRadius;
|
|
330
|
-
const shapeEl = partialCorners ? createSVGElement("path") : createSVGElement("rect");
|
|
295
|
+
const shapeEl = partialCorners ? createSVGElement("path", ctx.factory) : createSVGElement("rect", ctx.factory);
|
|
331
296
|
if (partialCorners) {
|
|
332
297
|
shapeEl.setAttribute("d", rectPathWithCorners(mark, sides));
|
|
333
298
|
} else {
|
|
@@ -341,7 +306,7 @@ function renderRectMark(mark, index) {
|
|
|
341
306
|
setAttrs(shapeEl, { rx: mark.cornerRadius, ry: mark.cornerRadius });
|
|
342
307
|
}
|
|
343
308
|
}
|
|
344
|
-
shapeEl.setAttribute("fill", resolveFillOrPattern(mark.fill, mark.pattern));
|
|
309
|
+
shapeEl.setAttribute("fill", resolveFillOrPattern(mark.fill, mark.pattern, ctx));
|
|
345
310
|
if (mark.fillOpacity !== void 0) {
|
|
346
311
|
shapeEl.setAttribute("fill-opacity", String(mark.fillOpacity));
|
|
347
312
|
}
|
|
@@ -357,22 +322,22 @@ function renderRectMark(mark, index) {
|
|
|
357
322
|
g.appendChild(shapeEl);
|
|
358
323
|
return g;
|
|
359
324
|
}
|
|
360
|
-
function renderArcMark(mark, index) {
|
|
361
|
-
const g = createSVGElement("g");
|
|
325
|
+
function renderArcMark(mark, index, ctx = createRenderContext()) {
|
|
326
|
+
const g = createSVGElement("g", ctx.factory);
|
|
362
327
|
g.setAttribute("data-mark-id", `arc-${index}`);
|
|
363
328
|
g.setAttribute("class", "oc-mark oc-mark-arc");
|
|
364
329
|
g.setAttribute("transform", `translate(${mark.center.x},${mark.center.y})`);
|
|
365
|
-
stampAnimationAttrs(g, mark, index);
|
|
366
|
-
const path = createSVGElement("path");
|
|
330
|
+
stampAnimationAttrs(g, mark, index, ctx);
|
|
331
|
+
const path = createSVGElement("path", ctx.factory);
|
|
367
332
|
setAttrs(path, {
|
|
368
333
|
d: mark.path,
|
|
369
|
-
fill: resolveFillOrPattern(mark.fill, mark.pattern),
|
|
334
|
+
fill: resolveFillOrPattern(mark.fill, mark.pattern, ctx),
|
|
370
335
|
stroke: mark.stroke,
|
|
371
336
|
"stroke-width": mark.strokeWidth
|
|
372
337
|
});
|
|
373
338
|
g.appendChild(path);
|
|
374
339
|
if (mark.label?.visible) {
|
|
375
|
-
const label = createSVGElement("text");
|
|
340
|
+
const label = createSVGElement("text", ctx.factory);
|
|
376
341
|
label.setAttribute("class", "oc-mark-label");
|
|
377
342
|
if (mark.key) label.setAttribute("data-label-key", mark.key);
|
|
378
343
|
setAttrs(label, {
|
|
@@ -380,22 +345,22 @@ function renderArcMark(mark, index) {
|
|
|
380
345
|
y: mark.label.y - mark.center.y
|
|
381
346
|
});
|
|
382
347
|
applyTextStyle(label, mark.label.style);
|
|
383
|
-
applyLabelHalo(label, mark.label);
|
|
348
|
+
applyLabelHalo(label, mark.label, ctx);
|
|
384
349
|
label.textContent = mark.label.text;
|
|
385
350
|
g.appendChild(label);
|
|
386
351
|
}
|
|
387
352
|
return g;
|
|
388
353
|
}
|
|
389
|
-
function renderPointMark(mark, index) {
|
|
390
|
-
const circle = createSVGElement("circle");
|
|
354
|
+
function renderPointMark(mark, index, ctx = createRenderContext()) {
|
|
355
|
+
const circle = createSVGElement("circle", ctx.factory);
|
|
391
356
|
circle.setAttribute("data-mark-id", `point-${index}`);
|
|
392
357
|
circle.setAttribute("class", "oc-mark oc-mark-point");
|
|
393
|
-
stampAnimationAttrs(circle, mark, index);
|
|
358
|
+
stampAnimationAttrs(circle, mark, index, ctx);
|
|
394
359
|
setAttrs(circle, {
|
|
395
360
|
cx: mark.cx,
|
|
396
361
|
cy: mark.cy,
|
|
397
362
|
r: mark.r,
|
|
398
|
-
fill: resolveMarkFill(mark.fill,
|
|
363
|
+
fill: resolveMarkFill(mark.fill, ctx.marks.gradientMap),
|
|
399
364
|
stroke: mark.stroke,
|
|
400
365
|
"stroke-width": mark.strokeWidth
|
|
401
366
|
});
|
|
@@ -404,11 +369,11 @@ function renderPointMark(mark, index) {
|
|
|
404
369
|
}
|
|
405
370
|
return circle;
|
|
406
371
|
}
|
|
407
|
-
function renderTextMark(mark, index) {
|
|
408
|
-
const text2 = createSVGElement("text");
|
|
372
|
+
function renderTextMark(mark, index, ctx = createRenderContext()) {
|
|
373
|
+
const text2 = createSVGElement("text", ctx.factory);
|
|
409
374
|
text2.setAttribute("data-mark-id", `textMark-${index}`);
|
|
410
375
|
text2.setAttribute("class", "oc-mark oc-mark-text");
|
|
411
|
-
stampAnimationAttrs(text2, mark, index);
|
|
376
|
+
stampAnimationAttrs(text2, mark, index, ctx);
|
|
412
377
|
setAttrs(text2, {
|
|
413
378
|
x: mark.x,
|
|
414
379
|
y: mark.y,
|
|
@@ -431,11 +396,11 @@ function renderTextMark(mark, index) {
|
|
|
431
396
|
text2.textContent = mark.text;
|
|
432
397
|
return text2;
|
|
433
398
|
}
|
|
434
|
-
function renderRuleMark(mark, index) {
|
|
435
|
-
const line = createSVGElement("line");
|
|
399
|
+
function renderRuleMark(mark, index, ctx = createRenderContext()) {
|
|
400
|
+
const line = createSVGElement("line", ctx.factory);
|
|
436
401
|
line.setAttribute("data-mark-id", `rule-${index}`);
|
|
437
402
|
line.setAttribute("class", "oc-mark oc-mark-rule");
|
|
438
|
-
stampAnimationAttrs(line, mark, index);
|
|
403
|
+
stampAnimationAttrs(line, mark, index, ctx);
|
|
439
404
|
setAttrs(line, {
|
|
440
405
|
x1: mark.x1,
|
|
441
406
|
y1: mark.y1,
|
|
@@ -455,11 +420,11 @@ function renderRuleMark(mark, index) {
|
|
|
455
420
|
}
|
|
456
421
|
return line;
|
|
457
422
|
}
|
|
458
|
-
function renderTickMark(mark, index) {
|
|
459
|
-
const line = createSVGElement("line");
|
|
423
|
+
function renderTickMark(mark, index, ctx = createRenderContext()) {
|
|
424
|
+
const line = createSVGElement("line", ctx.factory);
|
|
460
425
|
line.setAttribute("data-mark-id", `tick-${index}`);
|
|
461
426
|
line.setAttribute("class", "oc-mark oc-mark-tick");
|
|
462
|
-
stampAnimationAttrs(line, mark, index);
|
|
427
|
+
stampAnimationAttrs(line, mark, index, ctx);
|
|
463
428
|
const half = mark.length / 2;
|
|
464
429
|
if (mark.orient === "vertical") {
|
|
465
430
|
setAttrs(line, {
|
|
@@ -493,10 +458,26 @@ registerMarkRenderer("point", renderPointMark);
|
|
|
493
458
|
registerMarkRenderer("textMark", renderTextMark);
|
|
494
459
|
registerMarkRenderer("rule", renderRuleMark);
|
|
495
460
|
registerMarkRenderer("tick", renderTickMark);
|
|
496
|
-
function
|
|
461
|
+
function stampMarkMetadata(mark, el, ctx) {
|
|
462
|
+
if (mark.aria?.decorative || !mark.markType) return;
|
|
463
|
+
const shape = el.tagName.toLowerCase() === "g" ? el.firstElementChild : el;
|
|
464
|
+
if (!shape || (mark.type === "line" || mark.type === "area") && shape.tagName.toLowerCase() !== "path")
|
|
465
|
+
return;
|
|
466
|
+
shape.setAttribute("data-mark", mark.markType);
|
|
467
|
+
for (const [field, value] of Object.entries(mark.identity ?? {}))
|
|
468
|
+
shape.setAttribute(`data-${field}`, value);
|
|
469
|
+
if (!ctx.interactive && mark.authoredDescription !== void 0) {
|
|
470
|
+
const title = createSVGElement("title", ctx.factory);
|
|
471
|
+
title.textContent = mark.authoredDescription;
|
|
472
|
+
shape.insertBefore(title, shape.firstChild);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function renderSingleMark(mark, index, ctx = createRenderContext()) {
|
|
497
476
|
const renderer = markRenderers[mark.type];
|
|
498
477
|
if (!renderer) return void 0;
|
|
499
|
-
|
|
478
|
+
const element3 = renderer(mark, index, ctx);
|
|
479
|
+
stampMarkMetadata(mark, element3, ctx);
|
|
480
|
+
return element3;
|
|
500
481
|
}
|
|
501
482
|
function getMarkSeries(mark) {
|
|
502
483
|
if (mark.type === "line" || mark.type === "area") {
|
|
@@ -506,6 +487,7 @@ function getMarkSeries(mark) {
|
|
|
506
487
|
if (explicitSeries) {
|
|
507
488
|
return explicitSeries;
|
|
508
489
|
}
|
|
490
|
+
if (mark.authoredDescription !== void 0) return void 0;
|
|
509
491
|
if (mark.type === "arc") {
|
|
510
492
|
const label = mark.aria.label;
|
|
511
493
|
if (!label) return void 0;
|
|
@@ -520,25 +502,26 @@ function getMarkSeries(mark) {
|
|
|
520
502
|
}
|
|
521
503
|
return void 0;
|
|
522
504
|
}
|
|
523
|
-
function renderMarks(parent, layout, opts) {
|
|
524
|
-
const g = createSVGElement("g");
|
|
505
|
+
function renderMarks(parent, layout, opts, ctx = createRenderContext()) {
|
|
506
|
+
const g = createSVGElement("g", ctx.factory);
|
|
525
507
|
g.setAttribute("class", "oc-marks");
|
|
526
508
|
for (let i = 0; i < layout.marks.length; i++) {
|
|
527
509
|
const mark = layout.marks[i];
|
|
528
510
|
if (opts?.skipPoints && mark.type === "point") continue;
|
|
529
511
|
const renderer = markRenderers[mark.type];
|
|
530
512
|
if (!renderer) continue;
|
|
531
|
-
const el = renderer(mark, i);
|
|
513
|
+
const el = renderer(mark, i + (opts?.markIndexOffset ?? 0), ctx);
|
|
532
514
|
if (mark.aria?.decorative) {
|
|
533
515
|
el.setAttribute("aria-hidden", "true");
|
|
534
|
-
} else if (mark.aria?.label) {
|
|
516
|
+
} else if (ctx.interactive && mark.aria?.label !== void 0) {
|
|
535
517
|
el.setAttribute("aria-label", mark.aria.label);
|
|
536
518
|
}
|
|
519
|
+
stampMarkMetadata(mark, el, ctx);
|
|
537
520
|
const series = getMarkSeries(mark);
|
|
538
521
|
if (series) {
|
|
539
522
|
el.setAttribute("data-series", series);
|
|
540
523
|
}
|
|
541
|
-
if (
|
|
524
|
+
if (ctx.marks.animation?.enter && mark.type === "rect") {
|
|
542
525
|
const rect = mark;
|
|
543
526
|
if (rect.stackGroup && rect.stackPos !== void 0) {
|
|
544
527
|
el.setAttribute("data-stack-pos", String(rect.stackPos));
|
|
@@ -558,17 +541,17 @@ function renderMarks(parent, layout, opts) {
|
|
|
558
541
|
const rect = mark;
|
|
559
542
|
if (!rect.label?.visible) continue;
|
|
560
543
|
if (!labelsGroup) {
|
|
561
|
-
labelsGroup = createSVGElement("g");
|
|
544
|
+
labelsGroup = createSVGElement("g", ctx.factory);
|
|
562
545
|
labelsGroup.setAttribute("class", "oc-mark-labels");
|
|
563
546
|
}
|
|
564
|
-
const label = createSVGElement("text");
|
|
547
|
+
const label = createSVGElement("text", ctx.factory);
|
|
565
548
|
label.setAttribute("class", "oc-mark-label");
|
|
566
549
|
if (mark.key) label.setAttribute("data-label-key", mark.key);
|
|
567
550
|
setAttrs(label, { x: rect.label.x, y: rect.label.y });
|
|
568
551
|
applyTextStyle(label, rect.label.style);
|
|
569
|
-
applyLabelHalo(label, rect.label);
|
|
552
|
+
applyLabelHalo(label, rect.label, ctx);
|
|
570
553
|
label.textContent = rect.label.text;
|
|
571
|
-
if (
|
|
554
|
+
if (ctx.marks.animation?.enter) {
|
|
572
555
|
const idx = rect.animationIndex ?? i;
|
|
573
556
|
label.setAttribute("data-animation-index", String(idx));
|
|
574
557
|
label.style.setProperty(
|
|
@@ -665,9 +648,9 @@ import {
|
|
|
665
648
|
parseAnnotationSpans
|
|
666
649
|
} from "@opendata-ai/openchart-engine";
|
|
667
650
|
var CONNECTOR_STROKE_WIDTH = 1.25;
|
|
668
|
-
function renderArrowhead(parent, tipX, tipY, tangentX, tangentY, stroke) {
|
|
651
|
+
function renderArrowhead(parent, tipX, tipY, tangentX, tangentY, stroke, ctx = createRenderContext()) {
|
|
669
652
|
const head = computeArrowheadPoints(tipX, tipY, tangentX, tangentY);
|
|
670
|
-
const arrow = createSVGElement("polyline");
|
|
653
|
+
const arrow = createSVGElement("polyline", ctx.factory);
|
|
671
654
|
arrow.setAttribute("class", "oc-annotation-connector oc-annotation-arrowhead");
|
|
672
655
|
setAttrs(arrow, {
|
|
673
656
|
points: [
|
|
@@ -683,14 +666,14 @@ function renderArrowhead(parent, tipX, tipY, tangentX, tangentY, stroke) {
|
|
|
683
666
|
});
|
|
684
667
|
parent.appendChild(arrow);
|
|
685
668
|
}
|
|
686
|
-
function renderCurvedConnector(parent, from, to, stroke, showArrow, exit, control) {
|
|
669
|
+
function renderCurvedConnector(parent, from, to, stroke, showArrow, exit, control, ctx = createRenderContext()) {
|
|
687
670
|
const { x: cpx, y: cpy } = control ?? automaticControlPoint(from, to, exit);
|
|
688
671
|
const tx = to.x - cpx;
|
|
689
672
|
const ty = to.y - cpy;
|
|
690
673
|
const tLen = Math.sqrt(tx * tx + ty * ty) || 1;
|
|
691
674
|
const endX = showArrow ? to.x - tx / tLen * ARROWHEAD_LENGTH : to.x;
|
|
692
675
|
const endY = showArrow ? to.y - ty / tLen * ARROWHEAD_LENGTH : to.y;
|
|
693
|
-
const path = createSVGElement("path");
|
|
676
|
+
const path = createSVGElement("path", ctx.factory);
|
|
694
677
|
path.setAttribute("class", "oc-annotation-connector");
|
|
695
678
|
setAttrs(path, {
|
|
696
679
|
d: `M ${from.x} ${from.y} Q ${cpx} ${cpy} ${endX} ${endY}`,
|
|
@@ -701,15 +684,15 @@ function renderCurvedConnector(parent, from, to, stroke, showArrow, exit, contro
|
|
|
701
684
|
});
|
|
702
685
|
parent.appendChild(path);
|
|
703
686
|
if (showArrow) {
|
|
704
|
-
renderArrowhead(parent, to.x, to.y, tx, ty, stroke);
|
|
687
|
+
renderArrowhead(parent, to.x, to.y, tx, ty, stroke, ctx);
|
|
705
688
|
}
|
|
706
689
|
}
|
|
707
|
-
function fillRichText(text2, content, x, lineHeight) {
|
|
690
|
+
function fillRichText(text2, content, x, lineHeight, ctx = createRenderContext()) {
|
|
708
691
|
const lines = content.split("\n");
|
|
709
692
|
for (let i = 0; i < lines.length; i++) {
|
|
710
693
|
const spans = parseAnnotationSpans(lines[i]);
|
|
711
694
|
for (let s = 0; s < spans.length; s++) {
|
|
712
|
-
const tspan = createSVGElement("tspan");
|
|
695
|
+
const tspan = createSVGElement("tspan", ctx.factory);
|
|
713
696
|
if (s === 0) {
|
|
714
697
|
setAttrs(tspan, { x, dy: i === 0 ? 0 : lineHeight });
|
|
715
698
|
}
|
|
@@ -721,8 +704,8 @@ function fillRichText(text2, content, x, lineHeight) {
|
|
|
721
704
|
}
|
|
722
705
|
}
|
|
723
706
|
}
|
|
724
|
-
function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
725
|
-
const g = createSVGElement("g");
|
|
707
|
+
function renderAnnotation(parent, annotation, index, bgColor, hidden = false, interactive = true, ctx = createRenderContext()) {
|
|
708
|
+
const g = createSVGElement("g", ctx.factory);
|
|
726
709
|
g.setAttribute("class", `oc-annotation oc-annotation-${annotation.type}`);
|
|
727
710
|
g.setAttribute("data-annotation-index", String(annotation.specIndex ?? index));
|
|
728
711
|
const facet = parent.closest("[data-facet]")?.getAttribute("data-facet");
|
|
@@ -731,7 +714,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
731
714
|
g.setAttribute("data-annotation-id", annotation.id);
|
|
732
715
|
}
|
|
733
716
|
if (annotation.rect) {
|
|
734
|
-
const rect = createSVGElement("rect");
|
|
717
|
+
const rect = createSVGElement("rect", ctx.factory);
|
|
735
718
|
rect.setAttribute("class", "oc-annotation-range");
|
|
736
719
|
rect.setAttribute("pointer-events", "none");
|
|
737
720
|
setAttrs(rect, {
|
|
@@ -747,7 +730,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
747
730
|
g.appendChild(rect);
|
|
748
731
|
}
|
|
749
732
|
if (annotation.line) {
|
|
750
|
-
const line = createSVGElement("line");
|
|
733
|
+
const line = createSVGElement("line", ctx.factory);
|
|
751
734
|
line.setAttribute("class", "oc-annotation-line");
|
|
752
735
|
setAttrs(line, {
|
|
753
736
|
x1: annotation.line.start.x,
|
|
@@ -765,16 +748,18 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
765
748
|
if (annotation.footnoteIndex != null && annotation.label) {
|
|
766
749
|
if (annotation.specIndex !== void 0)
|
|
767
750
|
g.setAttribute("data-note-marker-index", String(annotation.specIndex));
|
|
768
|
-
if (
|
|
769
|
-
|
|
751
|
+
if (interactive) {
|
|
752
|
+
if (!hidden) g.setAttribute("tabindex", "0");
|
|
753
|
+
g.setAttribute("role", "button");
|
|
754
|
+
}
|
|
770
755
|
g.setAttribute(
|
|
771
756
|
"aria-label",
|
|
772
|
-
`Annotation ${annotation.footnoteIndex}: ${annotation.label.text.replaceAll("**", "")}. Activate to read the note
|
|
757
|
+
`Annotation ${annotation.footnoteIndex}: ${annotation.label.text.replaceAll("**", "")}${interactive ? ". Activate to read the note." : ""}`
|
|
773
758
|
);
|
|
774
759
|
const cx = annotation.label.connector?.endpoint?.x ?? annotation.label.connector?.to.x ?? annotation.dot?.x ?? annotation.label.x;
|
|
775
760
|
const cy = annotation.label.connector?.endpoint?.y ?? annotation.label.connector?.to.y ?? annotation.dot?.y ?? annotation.label.y;
|
|
776
761
|
const r = 8;
|
|
777
|
-
const circle = createSVGElement("circle");
|
|
762
|
+
const circle = createSVGElement("circle", ctx.factory);
|
|
778
763
|
circle.setAttribute("class", "oc-annotation-footnote-marker");
|
|
779
764
|
setAttrs(circle, {
|
|
780
765
|
cx,
|
|
@@ -785,7 +770,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
785
770
|
"stroke-width": 1.5
|
|
786
771
|
});
|
|
787
772
|
g.appendChild(circle);
|
|
788
|
-
const num = createSVGElement("text");
|
|
773
|
+
const num = createSVGElement("text", ctx.factory);
|
|
789
774
|
num.setAttribute("class", "oc-annotation-footnote-number");
|
|
790
775
|
setAttrs(num, {
|
|
791
776
|
x: cx,
|
|
@@ -809,9 +794,9 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
809
794
|
if (annotation.label.connector) {
|
|
810
795
|
const c = annotation.label.connector;
|
|
811
796
|
if (c.style === "curve") {
|
|
812
|
-
renderCurvedConnector(g, c.from, c.to, c.stroke, c.arrow, c.exit, c.control);
|
|
797
|
+
renderCurvedConnector(g, c.from, c.to, c.stroke, c.arrow, c.exit, c.control, ctx);
|
|
813
798
|
} else if (c.style === "drop-line") {
|
|
814
|
-
const connector = createSVGElement("line");
|
|
799
|
+
const connector = createSVGElement("line", ctx.factory);
|
|
815
800
|
connector.setAttribute("class", "oc-annotation-connector oc-annotation-drop-line");
|
|
816
801
|
setAttrs(connector, {
|
|
817
802
|
x1: c.from.x,
|
|
@@ -832,7 +817,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
832
817
|
const uy = dy / dist;
|
|
833
818
|
const lineEndX = c.to.x - ux * ARROWHEAD_LENGTH;
|
|
834
819
|
const lineEndY = c.to.y - uy * ARROWHEAD_LENGTH;
|
|
835
|
-
const connector = createSVGElement("line");
|
|
820
|
+
const connector = createSVGElement("line", ctx.factory);
|
|
836
821
|
connector.setAttribute("class", "oc-annotation-connector");
|
|
837
822
|
setAttrs(connector, {
|
|
838
823
|
x1: c.from.x,
|
|
@@ -844,9 +829,9 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
844
829
|
"stroke-linecap": "round"
|
|
845
830
|
});
|
|
846
831
|
g.appendChild(connector);
|
|
847
|
-
renderArrowhead(g, c.to.x, c.to.y, dx, dy, c.stroke);
|
|
832
|
+
renderArrowhead(g, c.to.x, c.to.y, dx, dy, c.stroke, ctx);
|
|
848
833
|
} else {
|
|
849
|
-
const connector = createSVGElement("line");
|
|
834
|
+
const connector = createSVGElement("line", ctx.factory);
|
|
850
835
|
connector.setAttribute("class", "oc-annotation-connector");
|
|
851
836
|
setAttrs(connector, {
|
|
852
837
|
x1: c.from.x,
|
|
@@ -861,7 +846,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
861
846
|
}
|
|
862
847
|
}
|
|
863
848
|
if (annotation.dot) {
|
|
864
|
-
const dot = createSVGElement("circle");
|
|
849
|
+
const dot = createSVGElement("circle", ctx.factory);
|
|
865
850
|
dot.setAttribute("class", "oc-annotation-dot");
|
|
866
851
|
setAttrs(dot, {
|
|
867
852
|
cx: annotation.dot.x,
|
|
@@ -873,7 +858,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
873
858
|
});
|
|
874
859
|
g.appendChild(dot);
|
|
875
860
|
}
|
|
876
|
-
const text2 = createSVGElement("text");
|
|
861
|
+
const text2 = createSVGElement("text", ctx.factory);
|
|
877
862
|
text2.setAttribute("class", "oc-annotation-label");
|
|
878
863
|
setAttrs(text2, { x: annotation.label.x, y: annotation.label.y });
|
|
879
864
|
applyTextStyle(text2, annotation.label.style);
|
|
@@ -883,7 +868,8 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
883
868
|
text2,
|
|
884
869
|
annotation.label.lines?.join("\n") ?? annotation.label.text,
|
|
885
870
|
annotation.label.x,
|
|
886
|
-
lineHeight
|
|
871
|
+
lineHeight,
|
|
872
|
+
ctx
|
|
887
873
|
);
|
|
888
874
|
if (annotation.label.background && annotation.label.bounds) {
|
|
889
875
|
const pad = 3;
|
|
@@ -892,7 +878,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
892
878
|
const bgY = b.y - pad;
|
|
893
879
|
const bgW = b.width + pad * 2;
|
|
894
880
|
const bgH = b.height + pad * 2;
|
|
895
|
-
const bgRect = createSVGElement("rect");
|
|
881
|
+
const bgRect = createSVGElement("rect", ctx.factory);
|
|
896
882
|
bgRect.setAttribute("class", "oc-annotation-bg");
|
|
897
883
|
setAttrs(bgRect, {
|
|
898
884
|
x: bgX,
|
|
@@ -908,7 +894,7 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
908
894
|
}
|
|
909
895
|
g.appendChild(text2);
|
|
910
896
|
if (annotation.subtitle) {
|
|
911
|
-
const sub = createSVGElement("text");
|
|
897
|
+
const sub = createSVGElement("text", ctx.factory);
|
|
912
898
|
sub.setAttribute("class", "oc-annotation-subtitle");
|
|
913
899
|
setAttrs(sub, { x: annotation.subtitle.x, y: annotation.subtitle.y });
|
|
914
900
|
applyTextStyle(sub, annotation.subtitle.style);
|
|
@@ -918,26 +904,35 @@ function renderAnnotation(parent, annotation, index, bgColor, hidden = false) {
|
|
|
918
904
|
sub,
|
|
919
905
|
annotation.subtitle.lines?.join("\n") ?? annotation.subtitle.text,
|
|
920
906
|
annotation.subtitle.x,
|
|
921
|
-
subLineHeight
|
|
907
|
+
subLineHeight,
|
|
908
|
+
ctx
|
|
922
909
|
);
|
|
923
910
|
g.appendChild(sub);
|
|
924
911
|
}
|
|
925
912
|
}
|
|
926
913
|
parent.appendChild(g);
|
|
927
914
|
}
|
|
928
|
-
function renderAnnotations(parent, layout) {
|
|
915
|
+
function renderAnnotations(parent, layout, interactive = true, ctx = createRenderContext()) {
|
|
929
916
|
if (layout.annotations.length === 0) return;
|
|
930
|
-
const g = createSVGElement("g");
|
|
917
|
+
const g = createSVGElement("g", ctx.factory);
|
|
931
918
|
g.setAttribute("class", "oc-annotations");
|
|
932
919
|
parent.appendChild(g);
|
|
933
920
|
const bgColor = resolvedSurface(layout.theme);
|
|
934
921
|
for (let i = 0; i < layout.annotations.length; i++) {
|
|
935
|
-
renderAnnotation(g, layout.annotations[i], i, bgColor, layout.a11y.hidden);
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
function updateAnnotationGeometry(group, annotation, bgColor) {
|
|
939
|
-
const scratch = createSVGElement("g");
|
|
940
|
-
renderAnnotation(
|
|
922
|
+
renderAnnotation(g, layout.annotations[i], i, bgColor, layout.a11y.hidden, interactive, ctx);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
function updateAnnotationGeometry(group, annotation, bgColor, ctx = createRenderContext()) {
|
|
926
|
+
const scratch = createSVGElement("g", ctx.factory);
|
|
927
|
+
renderAnnotation(
|
|
928
|
+
scratch,
|
|
929
|
+
annotation,
|
|
930
|
+
annotation.specIndex ?? 0,
|
|
931
|
+
bgColor,
|
|
932
|
+
void 0,
|
|
933
|
+
void 0,
|
|
934
|
+
ctx
|
|
935
|
+
);
|
|
941
936
|
const fresh = scratch.firstElementChild;
|
|
942
937
|
const previous = [...group.children].filter(
|
|
943
938
|
(child) => [...child.classList].some((name) => name.startsWith("oc-annotation-"))
|
|
@@ -969,20 +964,20 @@ import {
|
|
|
969
964
|
textAscent
|
|
970
965
|
} from "@opendata-ai/openchart-core";
|
|
971
966
|
import { serializeKeyValue } from "@opendata-ai/openchart-engine";
|
|
972
|
-
function appendCompoundLabel(parent, primaryText, subtitle, fontWeight) {
|
|
973
|
-
const primarySpan = createSVGElement("tspan");
|
|
967
|
+
function appendCompoundLabel(parent, primaryText, subtitle, fontWeight, ctx = createRenderContext()) {
|
|
968
|
+
const primarySpan = createSVGElement("tspan", ctx.factory);
|
|
974
969
|
primarySpan.setAttribute("font-weight", String(fontWeight));
|
|
975
970
|
primarySpan.textContent = primaryText;
|
|
976
971
|
parent.appendChild(primarySpan);
|
|
977
|
-
const subtitleSpan = createSVGElement("tspan");
|
|
972
|
+
const subtitleSpan = createSVGElement("tspan", ctx.factory);
|
|
978
973
|
subtitleSpan.setAttribute("dx", "0.5em");
|
|
979
974
|
subtitleSpan.textContent = subtitle;
|
|
980
975
|
subtitleSpan.setAttribute("font-weight", "400");
|
|
981
976
|
subtitleSpan.setAttribute("fill-opacity", "0.6");
|
|
982
977
|
parent.appendChild(subtitleSpan);
|
|
983
978
|
}
|
|
984
|
-
function renderAxis(parent, axis, orientation, layout, opts) {
|
|
985
|
-
const g = createSVGElement("g");
|
|
979
|
+
function renderAxis(parent, axis, orientation, layout, opts, ctx = createRenderContext()) {
|
|
980
|
+
const g = createSVGElement("g", ctx.factory);
|
|
986
981
|
const isRight = orientation === "y" && axis.orient === "right";
|
|
987
982
|
const isInlineY = orientation === "y" && axis.tickPosition === "inline" && !isRight;
|
|
988
983
|
g.setAttribute(
|
|
@@ -991,7 +986,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
991
986
|
);
|
|
992
987
|
const { area } = layout;
|
|
993
988
|
if (orientation === "x" && axis.domainLine !== false) {
|
|
994
|
-
const line = createSVGElement("line");
|
|
989
|
+
const line = createSVGElement("line", ctx.factory);
|
|
995
990
|
line.setAttribute("class", "oc-axis-line");
|
|
996
991
|
setAttrs(line, {
|
|
997
992
|
x1: axis.start.x,
|
|
@@ -1006,7 +1001,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1006
1001
|
for (const tick of axis.ticks) {
|
|
1007
1002
|
const tickKey = serializeKeyValue(tick.value);
|
|
1008
1003
|
if (orientation === "x") {
|
|
1009
|
-
const label = createSVGElement("text");
|
|
1004
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1010
1005
|
label.setAttribute("class", "oc-axis-tick");
|
|
1011
1006
|
label.setAttribute("data-tick-key", tickKey);
|
|
1012
1007
|
if (axis.tickAngle && Math.abs(axis.tickAngle) > 10) {
|
|
@@ -1031,13 +1026,13 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1031
1026
|
applyTextStyle(label, axis.tickLabelStyle);
|
|
1032
1027
|
label.textContent = tick.label;
|
|
1033
1028
|
if (tick.fullLabel) {
|
|
1034
|
-
const title = createSVGElement("title");
|
|
1029
|
+
const title = createSVGElement("title", ctx.factory);
|
|
1035
1030
|
title.textContent = tick.fullLabel;
|
|
1036
1031
|
label.appendChild(title);
|
|
1037
1032
|
}
|
|
1038
1033
|
g.appendChild(label);
|
|
1039
1034
|
} else if (isInlineY) {
|
|
1040
|
-
const label = createSVGElement("text");
|
|
1035
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1041
1036
|
label.setAttribute("class", "oc-axis-tick oc-axis-tick-inline");
|
|
1042
1037
|
label.setAttribute("data-tick-key", tickKey);
|
|
1043
1038
|
setAttrs(label, {
|
|
@@ -1049,7 +1044,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1049
1044
|
label.textContent = tick.label;
|
|
1050
1045
|
g.appendChild(label);
|
|
1051
1046
|
} else {
|
|
1052
|
-
const label = createSVGElement("text");
|
|
1047
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1053
1048
|
label.setAttribute("class", "oc-axis-tick");
|
|
1054
1049
|
label.setAttribute("data-tick-key", tickKey);
|
|
1055
1050
|
setAttrs(label, {
|
|
@@ -1089,12 +1084,12 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1089
1084
|
} else {
|
|
1090
1085
|
primaryText = ellipsis;
|
|
1091
1086
|
}
|
|
1092
|
-
appendCompoundLabel(label, primaryText, tick.subtitle, fontWeight);
|
|
1093
|
-
const titleEl = createSVGElement("title");
|
|
1087
|
+
appendCompoundLabel(label, primaryText, tick.subtitle, fontWeight, ctx);
|
|
1088
|
+
const titleEl = createSVGElement("title", ctx.factory);
|
|
1094
1089
|
titleEl.textContent = `${tick.label} ${tick.subtitle}`;
|
|
1095
1090
|
label.appendChild(titleEl);
|
|
1096
1091
|
} else {
|
|
1097
|
-
appendCompoundLabel(label, tick.label, tick.subtitle, fontWeight);
|
|
1092
|
+
appendCompoundLabel(label, tick.label, tick.subtitle, fontWeight, ctx);
|
|
1098
1093
|
}
|
|
1099
1094
|
} else {
|
|
1100
1095
|
const fullWidth = estimateTextWidth(tick.label, fontSize, fontWeight);
|
|
@@ -1113,7 +1108,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1113
1108
|
}
|
|
1114
1109
|
}
|
|
1115
1110
|
label.textContent = lo > 0 ? tick.label.slice(0, lo).trimEnd() + ellipsis : ellipsis;
|
|
1116
|
-
const titleEl = createSVGElement("title");
|
|
1111
|
+
const titleEl = createSVGElement("title", ctx.factory);
|
|
1117
1112
|
titleEl.textContent = tick.label;
|
|
1118
1113
|
label.appendChild(titleEl);
|
|
1119
1114
|
} else {
|
|
@@ -1123,6 +1118,11 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1123
1118
|
} else {
|
|
1124
1119
|
label.textContent = tick.label;
|
|
1125
1120
|
}
|
|
1121
|
+
if (tick.fullLabel) {
|
|
1122
|
+
const title = label.querySelector("title") ?? createSVGElement("title", ctx.factory);
|
|
1123
|
+
title.textContent = tick.subtitle ? `${tick.fullLabel} ${tick.subtitle}` : tick.fullLabel;
|
|
1124
|
+
if (!title.parentNode) label.appendChild(title);
|
|
1125
|
+
}
|
|
1126
1126
|
g.appendChild(label);
|
|
1127
1127
|
}
|
|
1128
1128
|
}
|
|
@@ -1132,7 +1132,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1132
1132
|
posToTickKey.set(tick.position, serializeKeyValue(tick.value));
|
|
1133
1133
|
}
|
|
1134
1134
|
for (const gridline of axis.gridlines) {
|
|
1135
|
-
const gl = createSVGElement("line");
|
|
1135
|
+
const gl = createSVGElement("line", ctx.factory);
|
|
1136
1136
|
gl.setAttribute("class", "oc-gridline");
|
|
1137
1137
|
const glKey = posToTickKey.get(gridline.position);
|
|
1138
1138
|
if (glKey) {
|
|
@@ -1163,7 +1163,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1163
1163
|
}
|
|
1164
1164
|
}
|
|
1165
1165
|
if (axis.label && axis.labelStyle) {
|
|
1166
|
-
const axisLabel = createSVGElement("text");
|
|
1166
|
+
const axisLabel = createSVGElement("text", ctx.factory);
|
|
1167
1167
|
axisLabel.setAttribute("class", "oc-axis-title");
|
|
1168
1168
|
applyTextStyle(axisLabel, axis.labelStyle);
|
|
1169
1169
|
axisLabel.textContent = axis.label;
|
|
@@ -1181,7 +1181,7 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1181
1181
|
if (axis.titleLines && axis.titleLines.length > 1) {
|
|
1182
1182
|
axisLabel.textContent = "";
|
|
1183
1183
|
for (const [index, line] of axis.titleLines.entries()) {
|
|
1184
|
-
const span = createSVGElement("tspan");
|
|
1184
|
+
const span = createSVGElement("tspan", ctx.factory);
|
|
1185
1185
|
setAttrs(span, {
|
|
1186
1186
|
x: tp.x,
|
|
1187
1187
|
dy: index === 0 ? 0 : axis.labelStyle.fontSize * (axis.labelStyle.lineHeight ?? 1.3)
|
|
@@ -1256,22 +1256,22 @@ function renderAxis(parent, axis, orientation, layout, opts) {
|
|
|
1256
1256
|
}
|
|
1257
1257
|
parent.appendChild(g);
|
|
1258
1258
|
}
|
|
1259
|
-
function renderAxes(parent, layout, opts) {
|
|
1259
|
+
function renderAxes(parent, layout, opts, ctx = createRenderContext()) {
|
|
1260
1260
|
if (layout.axes.x) {
|
|
1261
|
-
renderAxis(parent, layout.axes.x, "x", layout, opts);
|
|
1261
|
+
renderAxis(parent, layout.axes.x, "x", layout, opts, ctx);
|
|
1262
1262
|
}
|
|
1263
1263
|
if (layout.axes.y) {
|
|
1264
|
-
renderAxis(parent, layout.axes.y, "y", layout, opts);
|
|
1264
|
+
renderAxis(parent, layout.axes.y, "y", layout, opts, ctx);
|
|
1265
1265
|
}
|
|
1266
1266
|
if (layout.axes.y2) {
|
|
1267
|
-
renderAxis(parent, layout.axes.y2, "y", layout, opts);
|
|
1267
|
+
renderAxis(parent, layout.axes.y2, "y", layout, opts, ctx);
|
|
1268
1268
|
}
|
|
1269
1269
|
}
|
|
1270
1270
|
|
|
1271
1271
|
// src/renderers/endpoint-labels.ts
|
|
1272
1272
|
var LEADER_STROKE_WIDTH = 1;
|
|
1273
1273
|
var LEADER_OPACITY = 0.45;
|
|
1274
|
-
function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
1274
|
+
function renderColumn(root, entries, bounds, ep, leaderAnchorX, side, ctx = createRenderContext()) {
|
|
1275
1275
|
const labelFontSize = ep.labelStyle.fontSize ?? 11;
|
|
1276
1276
|
const labelLineHeight = labelFontSize * (ep.labelStyle.lineHeight ?? 1.25);
|
|
1277
1277
|
const valueFontSize = ep.valueStyle.fontSize ?? 11;
|
|
@@ -1280,7 +1280,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1280
1280
|
const textX = chipX + chipWidth + ep.gap;
|
|
1281
1281
|
for (let i = 0; i < entries.length; i++) {
|
|
1282
1282
|
const entry = entries[i];
|
|
1283
|
-
const entryG = createSVGElement("g");
|
|
1283
|
+
const entryG = createSVGElement("g", ctx.factory);
|
|
1284
1284
|
entryG.setAttribute("class", "oc-endpoint-label-entry");
|
|
1285
1285
|
entryG.setAttribute("role", "listitem");
|
|
1286
1286
|
entryG.setAttribute("data-endpoint-index", String(i));
|
|
@@ -1291,7 +1291,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1291
1291
|
`${entry.seriesKey}: ${entry.value}${entry.date ? ` (${entry.date})` : ""}`
|
|
1292
1292
|
);
|
|
1293
1293
|
if (entry.showLeader) {
|
|
1294
|
-
const leader = createSVGElement("line");
|
|
1294
|
+
const leader = createSVGElement("line", ctx.factory);
|
|
1295
1295
|
leader.setAttribute("class", "oc-endpoint-leader");
|
|
1296
1296
|
setAttrs(leader, {
|
|
1297
1297
|
x1: chipX,
|
|
@@ -1305,7 +1305,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1305
1305
|
entryG.appendChild(leader);
|
|
1306
1306
|
}
|
|
1307
1307
|
const rowY = entry.labelY + labelFontSize / 2;
|
|
1308
|
-
const line = createSVGElement("line");
|
|
1308
|
+
const line = createSVGElement("line", ctx.factory);
|
|
1309
1309
|
line.setAttribute("class", "oc-endpoint-swatch-line");
|
|
1310
1310
|
setAttrs(line, {
|
|
1311
1311
|
x1: chipX,
|
|
@@ -1318,7 +1318,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1318
1318
|
});
|
|
1319
1319
|
if (entry.strokeDasharray) line.setAttribute("stroke-dasharray", entry.strokeDasharray);
|
|
1320
1320
|
entryG.appendChild(line);
|
|
1321
|
-
const label = createSVGElement("text");
|
|
1321
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1322
1322
|
label.setAttribute("class", "oc-endpoint-label");
|
|
1323
1323
|
setAttrs(label, { x: textX, y: entry.labelY + labelFontSize });
|
|
1324
1324
|
applyTextStyle(label, ep.labelStyle);
|
|
@@ -1327,7 +1327,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1327
1327
|
label.textContent = entry.labelLines[0] ?? entry.seriesKey;
|
|
1328
1328
|
} else {
|
|
1329
1329
|
for (let li = 0; li < entry.labelLines.length; li++) {
|
|
1330
|
-
const tspan = createSVGElement("tspan");
|
|
1330
|
+
const tspan = createSVGElement("tspan", ctx.factory);
|
|
1331
1331
|
setAttrs(tspan, { x: textX, dy: li === 0 ? 0 : labelLineHeight });
|
|
1332
1332
|
tspan.textContent = entry.labelLines[li];
|
|
1333
1333
|
label.appendChild(tspan);
|
|
@@ -1336,14 +1336,14 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1336
1336
|
entryG.appendChild(label);
|
|
1337
1337
|
const lineCount = Math.max(entry.labelLines.length, 1);
|
|
1338
1338
|
const valueY = entry.labelY + labelFontSize + (lineCount - 1) * labelLineHeight + ep.valueGap + valueFontSize;
|
|
1339
|
-
const value = createSVGElement("text");
|
|
1339
|
+
const value = createSVGElement("text", ctx.factory);
|
|
1340
1340
|
value.setAttribute("class", "oc-endpoint-value");
|
|
1341
1341
|
setAttrs(value, { x: textX, y: valueY });
|
|
1342
1342
|
applyTextStyle(value, ep.valueStyle);
|
|
1343
1343
|
value.textContent = entry.value;
|
|
1344
1344
|
entryG.appendChild(value);
|
|
1345
1345
|
if (entry.date) {
|
|
1346
|
-
const date = createSVGElement("text");
|
|
1346
|
+
const date = createSVGElement("text", ctx.factory);
|
|
1347
1347
|
date.setAttribute("class", "oc-endpoint-date");
|
|
1348
1348
|
const dateY = valueY + (entry.value ? valueFontSize * (ep.valueStyle.lineHeight ?? 1.25) + ep.valueGap : 0);
|
|
1349
1349
|
setAttrs(date, { x: textX, y: dateY });
|
|
@@ -1352,7 +1352,7 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1352
1352
|
entryG.appendChild(date);
|
|
1353
1353
|
}
|
|
1354
1354
|
if (entry.marker) {
|
|
1355
|
-
const marker = createSVGElement("circle");
|
|
1355
|
+
const marker = createSVGElement("circle", ctx.factory);
|
|
1356
1356
|
marker.setAttribute("class", "oc-endpoint-marker");
|
|
1357
1357
|
setAttrs(marker, {
|
|
1358
1358
|
cx: entry.marker.x,
|
|
@@ -1367,22 +1367,22 @@ function renderColumn(root, entries, bounds, ep, leaderAnchorX, side) {
|
|
|
1367
1367
|
root.appendChild(entryG);
|
|
1368
1368
|
}
|
|
1369
1369
|
}
|
|
1370
|
-
function renderEndpointLabels(parent, layout) {
|
|
1370
|
+
function renderEndpointLabels(parent, layout, ctx = createRenderContext()) {
|
|
1371
1371
|
const ep = layout.endpointLabels;
|
|
1372
1372
|
if (!ep || ep.entries.length === 0 && !ep.interior?.length) return;
|
|
1373
1373
|
const chartArea = layout.area;
|
|
1374
|
-
const root = createSVGElement("g");
|
|
1374
|
+
const root = createSVGElement("g", ctx.factory);
|
|
1375
1375
|
root.setAttribute("class", "oc-endpoint-labels");
|
|
1376
1376
|
root.setAttribute("role", "list");
|
|
1377
1377
|
root.setAttribute("aria-label", "Endpoint labels");
|
|
1378
1378
|
const chartRightX = chartArea.x + chartArea.width;
|
|
1379
|
-
renderColumn(root, ep.entries, ep.bounds, ep, chartRightX, "trailing");
|
|
1379
|
+
renderColumn(root, ep.entries, ep.bounds, ep, chartRightX, "trailing", ctx);
|
|
1380
1380
|
if (ep.leading && ep.leading.length > 0 && ep.leadingBounds) {
|
|
1381
1381
|
const chartLeftX = chartArea.x;
|
|
1382
|
-
renderColumn(root, ep.leading, ep.leadingBounds, ep, chartLeftX, "leading");
|
|
1382
|
+
renderColumn(root, ep.leading, ep.leadingBounds, ep, chartLeftX, "leading", ctx);
|
|
1383
1383
|
}
|
|
1384
1384
|
for (const entry of ep.interior ?? []) {
|
|
1385
|
-
const label = createSVGElement("text");
|
|
1385
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1386
1386
|
label.setAttribute("class", "oc-area-interior-label");
|
|
1387
1387
|
label.setAttribute("data-endpoint-key", entry.seriesKey);
|
|
1388
1388
|
label.setAttribute("aria-label", entry.text);
|
|
@@ -1397,9 +1397,9 @@ function renderEndpointLabels(parent, layout) {
|
|
|
1397
1397
|
|
|
1398
1398
|
// src/renderers/legend.ts
|
|
1399
1399
|
import { estimateTextWidth as estimateTextWidth2 } from "@opendata-ai/openchart-core";
|
|
1400
|
-
function renderKeyText(parent, legend) {
|
|
1400
|
+
function renderKeyText(parent, legend, ctx = createRenderContext()) {
|
|
1401
1401
|
for (const row of legend.textRows ?? []) {
|
|
1402
|
-
const text2 = createSVGElement("text");
|
|
1402
|
+
const text2 = createSVGElement("text", ctx.factory);
|
|
1403
1403
|
text2.setAttribute("class", `oc-legend-${row.role}`);
|
|
1404
1404
|
setAttrs(text2, { x: row.x, y: row.y, "text-anchor": row.anchor ?? "start" });
|
|
1405
1405
|
applyTextStyle(text2, row.style);
|
|
@@ -1412,8 +1412,8 @@ var LEGEND_HIT_PAD = 4;
|
|
|
1412
1412
|
function isCategorical(legend) {
|
|
1413
1413
|
return !legend.type || legend.type === "categorical";
|
|
1414
1414
|
}
|
|
1415
|
-
function renderNoDataSwatch(parent, noData, labelStyle, chip) {
|
|
1416
|
-
const swatch = createSVGElement("rect");
|
|
1415
|
+
function renderNoDataSwatch(parent, noData, labelStyle, chip, ctx = createRenderContext()) {
|
|
1416
|
+
const swatch = createSVGElement("rect", ctx.factory);
|
|
1417
1417
|
swatch.setAttribute("class", "oc-legend-nodata");
|
|
1418
1418
|
setAttrs(swatch, {
|
|
1419
1419
|
x: noData.x,
|
|
@@ -1424,7 +1424,7 @@ function renderNoDataSwatch(parent, noData, labelStyle, chip) {
|
|
|
1424
1424
|
...chip ? { rx: chip.rx, ry: chip.rx } : { "shape-rendering": "crispEdges" }
|
|
1425
1425
|
});
|
|
1426
1426
|
parent.appendChild(swatch);
|
|
1427
|
-
const label = createSVGElement("text");
|
|
1427
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1428
1428
|
setAttrs(label, {
|
|
1429
1429
|
x: noData.labelX,
|
|
1430
1430
|
y: noData.labelY,
|
|
@@ -1435,9 +1435,9 @@ function renderNoDataSwatch(parent, noData, labelStyle, chip) {
|
|
|
1435
1435
|
label.textContent = noData.label;
|
|
1436
1436
|
parent.appendChild(label);
|
|
1437
1437
|
}
|
|
1438
|
-
function renderContinuousLegend(parent, legend) {
|
|
1438
|
+
function renderContinuousLegend(parent, legend, ctx = createRenderContext()) {
|
|
1439
1439
|
if (legend.bounds.width <= 0 || legend.bounds.height <= 0) return;
|
|
1440
|
-
const g = createSVGElement("g");
|
|
1440
|
+
const g = createSVGElement("g", ctx.factory);
|
|
1441
1441
|
g.setAttribute("class", "oc-legend oc-legend--continuous");
|
|
1442
1442
|
g.setAttribute("role", "img");
|
|
1443
1443
|
const first = legend.ticks[0];
|
|
@@ -1459,15 +1459,15 @@ function renderContinuousLegend(parent, legend) {
|
|
|
1459
1459
|
if (legend.mode === "gradient") {
|
|
1460
1460
|
let defs = parent.querySelector("defs");
|
|
1461
1461
|
if (!defs) {
|
|
1462
|
-
defs = createSVGElement("defs");
|
|
1462
|
+
defs = createSVGElement("defs", ctx.factory);
|
|
1463
1463
|
parent.insertBefore(defs, parent.firstChild);
|
|
1464
1464
|
}
|
|
1465
|
-
const gradientId =
|
|
1466
|
-
const grad = createSVGElement("linearGradient");
|
|
1465
|
+
const gradientId = ctx.ids.next("oc-legend-gradient");
|
|
1466
|
+
const grad = createSVGElement("linearGradient", ctx.factory);
|
|
1467
1467
|
grad.setAttribute("id", gradientId);
|
|
1468
1468
|
setAttrs(grad, { x1: "0%", y1: "0%", x2: "100%", y2: "0%" });
|
|
1469
1469
|
for (const stop of legend.colorStops) {
|
|
1470
|
-
const s = createSVGElement("stop");
|
|
1470
|
+
const s = createSVGElement("stop", ctx.factory);
|
|
1471
1471
|
const attrs = {
|
|
1472
1472
|
offset: `${stop.offset * 100}%`,
|
|
1473
1473
|
"stop-color": stop.color
|
|
@@ -1477,7 +1477,7 @@ function renderContinuousLegend(parent, legend) {
|
|
|
1477
1477
|
grad.appendChild(s);
|
|
1478
1478
|
}
|
|
1479
1479
|
defs.appendChild(grad);
|
|
1480
|
-
const bar = createSVGElement("rect");
|
|
1480
|
+
const bar = createSVGElement("rect", ctx.factory);
|
|
1481
1481
|
bar.setAttribute("class", "oc-legend-gradient-bar");
|
|
1482
1482
|
setAttrs(bar, {
|
|
1483
1483
|
x: legend.bar.x,
|
|
@@ -1492,7 +1492,7 @@ function renderContinuousLegend(parent, legend) {
|
|
|
1492
1492
|
} else {
|
|
1493
1493
|
for (let i = 0; i < legend.bins.length; i++) {
|
|
1494
1494
|
const bin = legend.bins[i];
|
|
1495
|
-
const rect = createSVGElement("rect");
|
|
1495
|
+
const rect = createSVGElement("rect", ctx.factory);
|
|
1496
1496
|
rect.setAttribute("class", "oc-legend-bin");
|
|
1497
1497
|
setAttrs(rect, {
|
|
1498
1498
|
x: legend.rangeEntries?.[i]?.bounds.x ?? bin.x,
|
|
@@ -1507,7 +1507,7 @@ function renderContinuousLegend(parent, legend) {
|
|
|
1507
1507
|
}
|
|
1508
1508
|
}
|
|
1509
1509
|
if (!legend.textRows?.some((row) => row.role === "title") && legend.title && legend.titleY !== void 0) {
|
|
1510
|
-
const title = createSVGElement("text");
|
|
1510
|
+
const title = createSVGElement("text", ctx.factory);
|
|
1511
1511
|
title.setAttribute("class", "oc-legend-title");
|
|
1512
1512
|
setAttrs(title, { x: legend.bar.x, y: legend.titleY, "text-anchor": "start" });
|
|
1513
1513
|
applyTextStyle(title, legend.titleStyle ?? legend.labelStyle);
|
|
@@ -1515,7 +1515,7 @@ function renderContinuousLegend(parent, legend) {
|
|
|
1515
1515
|
g.appendChild(title);
|
|
1516
1516
|
}
|
|
1517
1517
|
for (const tick of legend.ticks) {
|
|
1518
|
-
const label = createSVGElement("text");
|
|
1518
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1519
1519
|
setAttrs(label, {
|
|
1520
1520
|
x: tick.x,
|
|
1521
1521
|
y: legend.labelY + (tick.offsetY ?? 0),
|
|
@@ -1526,14 +1526,14 @@ function renderContinuousLegend(parent, legend) {
|
|
|
1526
1526
|
g.appendChild(label);
|
|
1527
1527
|
}
|
|
1528
1528
|
if (legend.noData) {
|
|
1529
|
-
renderNoDataSwatch(g, legend.noData, legend.labelStyle);
|
|
1529
|
+
renderNoDataSwatch(g, legend.noData, legend.labelStyle, void 0, ctx);
|
|
1530
1530
|
}
|
|
1531
|
-
renderKeyText(g, legend);
|
|
1531
|
+
renderKeyText(g, legend, ctx);
|
|
1532
1532
|
parent.appendChild(g);
|
|
1533
1533
|
}
|
|
1534
|
-
function renderSizeLegend(parent, legend) {
|
|
1534
|
+
function renderSizeLegend(parent, legend, ctx = createRenderContext()) {
|
|
1535
1535
|
if (legend.circles.length === 0) return;
|
|
1536
|
-
const g = createSVGElement("g");
|
|
1536
|
+
const g = createSVGElement("g", ctx.factory);
|
|
1537
1537
|
g.setAttribute("class", "oc-legend oc-legend--size");
|
|
1538
1538
|
g.setAttribute("aria-hidden", "true");
|
|
1539
1539
|
const ox = legend.bounds.x;
|
|
@@ -1541,7 +1541,7 @@ function renderSizeLegend(parent, legend) {
|
|
|
1541
1541
|
const labelX = ox + legend.circles[0].cx + legend.circles[0].radius + 8;
|
|
1542
1542
|
const leaderX = ox + legend.circles[0].cx + legend.circles[0].radius + 4;
|
|
1543
1543
|
if (!legend.textRows?.some((row) => row.role === "title") && legend.title && legend.titleY !== void 0) {
|
|
1544
|
-
const title = createSVGElement("text");
|
|
1544
|
+
const title = createSVGElement("text", ctx.factory);
|
|
1545
1545
|
title.setAttribute("class", "oc-legend-title");
|
|
1546
1546
|
setAttrs(title, { x: ox, y: oy + legend.titleY, "text-anchor": "start" });
|
|
1547
1547
|
applyTextStyle(title, legend.titleStyle ?? legend.labelStyle);
|
|
@@ -1549,7 +1549,7 @@ function renderSizeLegend(parent, legend) {
|
|
|
1549
1549
|
g.appendChild(title);
|
|
1550
1550
|
}
|
|
1551
1551
|
for (const circle of legend.circles) {
|
|
1552
|
-
const c = createSVGElement("circle");
|
|
1552
|
+
const c = createSVGElement("circle", ctx.factory);
|
|
1553
1553
|
setAttrs(c, {
|
|
1554
1554
|
cx: ox + circle.cx,
|
|
1555
1555
|
cy: oy + circle.cy,
|
|
@@ -1559,7 +1559,7 @@ function renderSizeLegend(parent, legend) {
|
|
|
1559
1559
|
"stroke-width": 1
|
|
1560
1560
|
});
|
|
1561
1561
|
g.appendChild(c);
|
|
1562
|
-
const line = createSVGElement("line");
|
|
1562
|
+
const line = createSVGElement("line", ctx.factory);
|
|
1563
1563
|
setAttrs(line, {
|
|
1564
1564
|
x1: ox + circle.cx,
|
|
1565
1565
|
y1: oy + circle.cy - circle.radius,
|
|
@@ -1570,7 +1570,7 @@ function renderSizeLegend(parent, legend) {
|
|
|
1570
1570
|
"stroke-dasharray": "2 2"
|
|
1571
1571
|
});
|
|
1572
1572
|
g.appendChild(line);
|
|
1573
|
-
const label = createSVGElement("text");
|
|
1573
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1574
1574
|
setAttrs(label, {
|
|
1575
1575
|
x: labelX,
|
|
1576
1576
|
y: oy + circle.labelY
|
|
@@ -1579,20 +1579,21 @@ function renderSizeLegend(parent, legend) {
|
|
|
1579
1579
|
label.textContent = circle.label;
|
|
1580
1580
|
g.appendChild(label);
|
|
1581
1581
|
}
|
|
1582
|
-
renderKeyText(g, legend);
|
|
1582
|
+
renderKeyText(g, legend, ctx);
|
|
1583
1583
|
parent.appendChild(g);
|
|
1584
1584
|
}
|
|
1585
|
-
function renderLegend(parent, legend) {
|
|
1585
|
+
function renderLegend(parent, legend, interactive = true, ctx = createRenderContext()) {
|
|
1586
|
+
interactive = interactive && ctx.interactive;
|
|
1586
1587
|
if (legend.type === "continuous") {
|
|
1587
|
-
renderContinuousLegend(parent, legend);
|
|
1588
|
+
renderContinuousLegend(parent, legend, ctx);
|
|
1588
1589
|
return;
|
|
1589
1590
|
}
|
|
1590
1591
|
if (legend.type === "size") {
|
|
1591
|
-
renderSizeLegend(parent, legend);
|
|
1592
|
+
renderSizeLegend(parent, legend, ctx);
|
|
1592
1593
|
return;
|
|
1593
1594
|
}
|
|
1594
1595
|
if (!isCategorical(legend) || legend.entries.length === 0) return;
|
|
1595
|
-
const g = createSVGElement("g");
|
|
1596
|
+
const g = createSVGElement("g", ctx.factory);
|
|
1596
1597
|
g.setAttribute("class", "oc-legend");
|
|
1597
1598
|
g.setAttribute("role", "group");
|
|
1598
1599
|
g.setAttribute("aria-label", "Chart legend");
|
|
@@ -1618,7 +1619,7 @@ function renderLegend(parent, legend) {
|
|
|
1618
1619
|
offsetY += legend.swatchSize + 6;
|
|
1619
1620
|
}
|
|
1620
1621
|
}
|
|
1621
|
-
const entryG = createSVGElement("g");
|
|
1622
|
+
const entryG = createSVGElement("g", ctx.factory);
|
|
1622
1623
|
entryG.setAttribute("class", "oc-legend-entry");
|
|
1623
1624
|
entryG.setAttribute("data-legend-index", String(i));
|
|
1624
1625
|
entryG.setAttribute("data-legend-label", entry.label);
|
|
@@ -1628,12 +1629,14 @@ function renderLegend(parent, legend) {
|
|
|
1628
1629
|
entryG.setAttribute("opacity", "0.5");
|
|
1629
1630
|
} else {
|
|
1630
1631
|
const visible = entry.active !== false;
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1632
|
+
if (interactive) {
|
|
1633
|
+
entryG.setAttribute("role", "button");
|
|
1634
|
+
entryG.setAttribute("tabindex", "0");
|
|
1635
|
+
entryG.setAttribute("aria-pressed", String(visible));
|
|
1636
|
+
}
|
|
1634
1637
|
entryG.setAttribute("data-legend-active", String(visible));
|
|
1635
1638
|
entryG.setAttribute("aria-label", `${entry.label}: ${visible ? "visible" : "hidden"}`);
|
|
1636
|
-
entryG.setAttribute("style", "cursor: pointer");
|
|
1639
|
+
if (interactive) entryG.setAttribute("style", "cursor: pointer");
|
|
1637
1640
|
if (!visible) {
|
|
1638
1641
|
entryG.setAttribute("opacity", "0.3");
|
|
1639
1642
|
}
|
|
@@ -1642,7 +1645,7 @@ function renderLegend(parent, legend) {
|
|
|
1642
1645
|
legend.labelStyle.fontSize,
|
|
1643
1646
|
legend.labelStyle.fontWeight
|
|
1644
1647
|
);
|
|
1645
|
-
const hit = createSVGElement("rect");
|
|
1648
|
+
const hit = createSVGElement("rect", ctx.factory);
|
|
1646
1649
|
hit.setAttribute("class", "oc-legend-hit");
|
|
1647
1650
|
setAttrs(hit, {
|
|
1648
1651
|
x: offsetX - LEGEND_HIT_PAD,
|
|
@@ -1657,7 +1660,7 @@ function renderLegend(parent, legend) {
|
|
|
1657
1660
|
const midX = offsetX + legend.swatchSize / 2;
|
|
1658
1661
|
const midY = offsetY + legend.swatchSize / 2;
|
|
1659
1662
|
if (entry.shape === "circle") {
|
|
1660
|
-
const circle = createSVGElement("circle");
|
|
1663
|
+
const circle = createSVGElement("circle", ctx.factory);
|
|
1661
1664
|
setAttrs(circle, {
|
|
1662
1665
|
cx: midX,
|
|
1663
1666
|
cy: midY,
|
|
@@ -1667,7 +1670,7 @@ function renderLegend(parent, legend) {
|
|
|
1667
1670
|
entryG.appendChild(circle);
|
|
1668
1671
|
} else if (entry.shape === "line") {
|
|
1669
1672
|
const lineWidth = legend.swatchSize;
|
|
1670
|
-
const line = createSVGElement("line");
|
|
1673
|
+
const line = createSVGElement("line", ctx.factory);
|
|
1671
1674
|
line.setAttribute("class", "oc-legend-swatch-line");
|
|
1672
1675
|
setAttrs(line, {
|
|
1673
1676
|
x1: offsetX,
|
|
@@ -1682,7 +1685,7 @@ function renderLegend(parent, legend) {
|
|
|
1682
1685
|
entryG.appendChild(line);
|
|
1683
1686
|
} else {
|
|
1684
1687
|
const rectSize = Math.round(legend.swatchSize * 0.6);
|
|
1685
|
-
const rect = createSVGElement("rect");
|
|
1688
|
+
const rect = createSVGElement("rect", ctx.factory);
|
|
1686
1689
|
rect.setAttribute("class", "oc-legend-swatch-rect");
|
|
1687
1690
|
setAttrs(rect, {
|
|
1688
1691
|
x: offsetX + (legend.swatchSize - rectSize) / 2,
|
|
@@ -1695,7 +1698,7 @@ function renderLegend(parent, legend) {
|
|
|
1695
1698
|
});
|
|
1696
1699
|
entryG.appendChild(rect);
|
|
1697
1700
|
}
|
|
1698
|
-
const label = createSVGElement("text");
|
|
1701
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1699
1702
|
setAttrs(label, {
|
|
1700
1703
|
x: offsetX + legend.swatchSize + legend.swatchGap,
|
|
1701
1704
|
y: offsetY + legend.swatchSize / 2,
|
|
@@ -1720,34 +1723,34 @@ function renderLegend(parent, legend) {
|
|
|
1720
1723
|
}
|
|
1721
1724
|
}
|
|
1722
1725
|
if (legend.noData) {
|
|
1723
|
-
renderNoDataSwatch(g, legend.noData, legend.labelStyle, { rx: 2, baseline: "central" });
|
|
1726
|
+
renderNoDataSwatch(g, legend.noData, legend.labelStyle, { rx: 2, baseline: "central" }, ctx);
|
|
1724
1727
|
}
|
|
1725
|
-
renderKeyText(g, legend);
|
|
1728
|
+
renderKeyText(g, legend, ctx);
|
|
1726
1729
|
parent.appendChild(g);
|
|
1727
1730
|
}
|
|
1728
1731
|
|
|
1729
1732
|
// src/renderers/metrics.ts
|
|
1730
1733
|
var DELTA_SIZE_RATIO = 12 / 22;
|
|
1731
|
-
function renderMetrics(parent, layout) {
|
|
1734
|
+
function renderMetrics(parent, layout, ctx = createRenderContext()) {
|
|
1732
1735
|
const bar = layout.metrics;
|
|
1733
1736
|
if (!bar || bar.cells.length === 0) return;
|
|
1734
1737
|
const labelSize = layout.theme.fonts.sizes.metricLabel;
|
|
1735
1738
|
const valueSize = layout.theme.fonts.sizes.metricValue;
|
|
1736
1739
|
const deltaSize = Math.round(valueSize * DELTA_SIZE_RATIO);
|
|
1737
|
-
const g = createSVGElement("g");
|
|
1740
|
+
const g = createSVGElement("g", ctx.factory);
|
|
1738
1741
|
g.setAttribute("class", "oc-metrics");
|
|
1739
1742
|
for (const cell of bar.cells) {
|
|
1740
|
-
const label = createSVGElement("text");
|
|
1743
|
+
const label = createSVGElement("text", ctx.factory);
|
|
1741
1744
|
label.setAttribute("class", "oc-metric-label");
|
|
1742
1745
|
setAttrs(label, { x: cell.x, y: cell.labelY, "font-size": labelSize });
|
|
1743
1746
|
label.textContent = cell.metric.label.toUpperCase();
|
|
1744
1747
|
g.appendChild(label);
|
|
1745
|
-
const value = createSVGElement("text");
|
|
1748
|
+
const value = createSVGElement("text", ctx.factory);
|
|
1746
1749
|
value.setAttribute("class", "oc-metric-value");
|
|
1747
1750
|
setAttrs(value, { x: cell.x, y: cell.valueY, "font-size": valueSize });
|
|
1748
1751
|
value.textContent = cell.metric.value;
|
|
1749
1752
|
if (cell.metric.delta) {
|
|
1750
|
-
const delta = createSVGElement("tspan");
|
|
1753
|
+
const delta = createSVGElement("tspan", ctx.factory);
|
|
1751
1754
|
const tone = cell.metric.deltaTone ?? "up";
|
|
1752
1755
|
delta.setAttribute("class", tone === "down" ? "oc-metric-delta-down" : "oc-metric-delta-up");
|
|
1753
1756
|
delta.setAttribute("dx", "8");
|
|
@@ -1756,7 +1759,7 @@ function renderMetrics(parent, layout) {
|
|
|
1756
1759
|
value.appendChild(delta);
|
|
1757
1760
|
}
|
|
1758
1761
|
if (cell.metric.secondary) {
|
|
1759
|
-
const secondary = createSVGElement("tspan");
|
|
1762
|
+
const secondary = createSVGElement("tspan", ctx.factory);
|
|
1760
1763
|
secondary.setAttribute("class", "oc-metric-secondary");
|
|
1761
1764
|
secondary.setAttribute("dx", "6");
|
|
1762
1765
|
secondary.setAttribute("font-size", String(deltaSize));
|
|
@@ -1770,9 +1773,11 @@ function renderMetrics(parent, layout) {
|
|
|
1770
1773
|
|
|
1771
1774
|
// src/svg-renderer.ts
|
|
1772
1775
|
function renderChartSVG(layout, container, opts) {
|
|
1776
|
+
const ctx = opts?.context ?? createRenderContext();
|
|
1773
1777
|
const { width, height } = layout.dimensions;
|
|
1774
|
-
const
|
|
1775
|
-
const
|
|
1778
|
+
const interactive = ctx.interactive && opts?.interactive !== false;
|
|
1779
|
+
const animation = interactive ? layout.animation : void 0;
|
|
1780
|
+
const svg = createSVGElement("svg", ctx.factory);
|
|
1776
1781
|
setAttrs(svg, {
|
|
1777
1782
|
viewBox: `0 0 ${width} ${height}`,
|
|
1778
1783
|
xmlns: SVG_NS,
|
|
@@ -1799,6 +1804,7 @@ function renderChartSVG(layout, container, opts) {
|
|
|
1799
1804
|
}
|
|
1800
1805
|
const classes = opts?.animate ? "oc-chart oc-animate" : "oc-chart";
|
|
1801
1806
|
svg.setAttribute("class", classes);
|
|
1807
|
+
svg.setAttribute("data-theme", layout.theme.isDark ? "dark" : "light");
|
|
1802
1808
|
const enterPhase = animation?.enter;
|
|
1803
1809
|
if (enterPhase) {
|
|
1804
1810
|
const markCount = layout.marks.length;
|
|
@@ -1824,7 +1830,7 @@ function renderChartSVG(layout, container, opts) {
|
|
|
1824
1830
|
}
|
|
1825
1831
|
const canvasMarks = opts?.canvasMarks === true;
|
|
1826
1832
|
if (layout.display !== "sparkline" && !canvasMarks) {
|
|
1827
|
-
const bg = createSVGElement("rect");
|
|
1833
|
+
const bg = createSVGElement("rect", ctx.factory);
|
|
1828
1834
|
setAttrs(bg, {
|
|
1829
1835
|
x: 0,
|
|
1830
1836
|
y: 0,
|
|
@@ -1834,16 +1840,16 @@ function renderChartSVG(layout, container, opts) {
|
|
|
1834
1840
|
});
|
|
1835
1841
|
svg.appendChild(bg);
|
|
1836
1842
|
}
|
|
1837
|
-
const clipId =
|
|
1838
|
-
const defs = createSVGElement("defs");
|
|
1839
|
-
const clipPath = createSVGElement("clipPath");
|
|
1843
|
+
const clipId = ctx.ids.next("oc-clip");
|
|
1844
|
+
const defs = createSVGElement("defs", ctx.factory);
|
|
1845
|
+
const clipPath = createSVGElement("clipPath", ctx.factory);
|
|
1840
1846
|
clipPath.setAttribute("id", clipId);
|
|
1841
1847
|
const maxPointR = layout.marks.reduce(
|
|
1842
1848
|
(max, m) => m.type === "point" && m.r ? Math.max(max, m.r) : max,
|
|
1843
1849
|
0
|
|
1844
1850
|
);
|
|
1845
1851
|
const clipPad = Math.max(maxPointR, 2);
|
|
1846
|
-
const clipRect = createSVGElement("rect");
|
|
1852
|
+
const clipRect = createSVGElement("rect", ctx.factory);
|
|
1847
1853
|
setAttrs(clipRect, {
|
|
1848
1854
|
x: 0,
|
|
1849
1855
|
y: layout.area.y - clipPad,
|
|
@@ -1852,148 +1858,145 @@ function renderChartSVG(layout, container, opts) {
|
|
|
1852
1858
|
});
|
|
1853
1859
|
clipPath.appendChild(clipRect);
|
|
1854
1860
|
defs.appendChild(clipPath);
|
|
1855
|
-
const gradientMap = buildGradientDefs(layout.marks, defs);
|
|
1861
|
+
const gradientMap = buildGradientDefs(layout.marks, defs, ctx);
|
|
1856
1862
|
const patternMap = buildPatternDefs(
|
|
1857
1863
|
layout.marks,
|
|
1858
|
-
defs
|
|
1864
|
+
defs,
|
|
1865
|
+
ctx
|
|
1859
1866
|
);
|
|
1860
1867
|
svg.appendChild(defs);
|
|
1861
|
-
|
|
1868
|
+
Object.assign(ctx.marks, {
|
|
1862
1869
|
animation,
|
|
1863
1870
|
gradientMap,
|
|
1864
1871
|
patternMap,
|
|
1865
1872
|
surface: resolvedSurface(layout.theme)
|
|
1866
1873
|
});
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
"data-animation-index": 0
|
|
1896
|
-
});
|
|
1897
|
-
clippedGroup.insertBefore(stack, element3);
|
|
1898
|
-
stacks.set(key, stack);
|
|
1899
|
-
}
|
|
1900
|
-
stack.appendChild(element3);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
let pointCircles = null;
|
|
1904
|
-
let pointCircleCoords = null;
|
|
1905
|
-
const getPointCircles = () => {
|
|
1906
|
-
if (pointCircles === null) {
|
|
1907
|
-
pointCircles = Array.from(
|
|
1908
|
-
clippedGroup.querySelectorAll("circle.oc-mark-point")
|
|
1909
|
-
);
|
|
1910
|
-
}
|
|
1911
|
-
return pointCircles;
|
|
1912
|
-
};
|
|
1913
|
-
const getPointCircleCoords = () => {
|
|
1914
|
-
if (pointCircleCoords === null) {
|
|
1915
|
-
pointCircleCoords = getPointCircles().map((el) => ({
|
|
1916
|
-
cx: Number(el.getAttribute("cx")),
|
|
1917
|
-
cy: Number(el.getAttribute("cy"))
|
|
1918
|
-
}));
|
|
1919
|
-
}
|
|
1920
|
-
return pointCircleCoords;
|
|
1921
|
-
};
|
|
1922
|
-
const hasLineOrAreaWithDataPoints = layout.marks.some(
|
|
1923
|
-
(m) => (m.type === "line" || m.type === "area") && m.dataPoints && m.dataPoints.length > 0
|
|
1924
|
-
);
|
|
1925
|
-
if (hasLineOrAreaWithDataPoints) {
|
|
1926
|
-
for (const el of getPointCircles()) {
|
|
1927
|
-
el.setAttribute("pointer-events", "none");
|
|
1928
|
-
}
|
|
1929
|
-
const overlay = createSVGElement("rect");
|
|
1930
|
-
setAttrs(overlay, {
|
|
1931
|
-
x: layout.area.x,
|
|
1932
|
-
y: layout.area.y,
|
|
1933
|
-
width: layout.area.width,
|
|
1934
|
-
height: layout.area.height,
|
|
1935
|
-
fill: "transparent"
|
|
1936
|
-
});
|
|
1937
|
-
overlay.setAttribute("class", "oc-voronoi-overlay");
|
|
1938
|
-
overlay.setAttribute("data-voronoi-overlay", "true");
|
|
1939
|
-
clippedGroup.appendChild(overlay);
|
|
1940
|
-
if (opts?.crosshair) {
|
|
1941
|
-
const crosshairLine = createSVGElement("line");
|
|
1942
|
-
crosshairLine.setAttribute("data-crosshair", "true");
|
|
1943
|
-
crosshairLine.setAttribute("class", "oc-crosshair");
|
|
1944
|
-
setAttrs(crosshairLine, {
|
|
1945
|
-
x1: 0,
|
|
1946
|
-
y1: layout.area.y,
|
|
1947
|
-
x2: 0,
|
|
1948
|
-
y2: layout.area.y + layout.area.height,
|
|
1949
|
-
stroke: layout.theme.colors.axis,
|
|
1950
|
-
"stroke-opacity": "0.4",
|
|
1951
|
-
"stroke-dasharray": "3,3",
|
|
1952
|
-
"stroke-width": "1",
|
|
1953
|
-
"pointer-events": "none"
|
|
1874
|
+
if (layout.facet) {
|
|
1875
|
+
renderFacetedPanels(svg, layout, layout.facet.panels, defs, interactive, ctx);
|
|
1876
|
+
} else {
|
|
1877
|
+
renderAxes(svg, layout, { skipGridlines: canvasMarks }, ctx);
|
|
1878
|
+
const clipGroup = createSVGElement("g", ctx.factory);
|
|
1879
|
+
clipGroup.setAttribute("clip-path", `url(#${clipId})`);
|
|
1880
|
+
const clippedGroup = createSVGElement("g", ctx.factory);
|
|
1881
|
+
clippedGroup.setAttribute("data-oc-marks-group", "true");
|
|
1882
|
+
clipGroup.appendChild(clippedGroup);
|
|
1883
|
+
const markLabelsOverlay = renderMarks(clippedGroup, layout, { skipPoints: canvasMarks }, ctx);
|
|
1884
|
+
if (enterPhase?.spring && layout.marks.some((mark) => mark.type === "rect" && mark.stackPos !== void 0)) {
|
|
1885
|
+
const stacks = /* @__PURE__ */ new Map();
|
|
1886
|
+
for (const mark of layout.marks) {
|
|
1887
|
+
if (mark.type !== "rect" || mark.stackPos === void 0 || !mark.key) continue;
|
|
1888
|
+
const element3 = Array.from(clippedGroup.children).find(
|
|
1889
|
+
(child) => child.getAttribute("data-key") === mark.key
|
|
1890
|
+
);
|
|
1891
|
+
if (!element3) continue;
|
|
1892
|
+
const horizontal = element3.getAttribute("data-orient") === "horizontal";
|
|
1893
|
+
const key = `${horizontal ? "h" : "v"}:${horizontal ? mark.y : mark.x}`;
|
|
1894
|
+
let stack = stacks.get(key);
|
|
1895
|
+
if (!stack) {
|
|
1896
|
+
stack = createSVGElement("g", ctx.factory);
|
|
1897
|
+
setAttrs(stack, {
|
|
1898
|
+
class: "oc-stack-reveal",
|
|
1899
|
+
"data-key": `stack:${key}`,
|
|
1900
|
+
"data-orient": horizontal ? "horizontal" : "vertical",
|
|
1901
|
+
"data-animation-index": 0
|
|
1954
1902
|
});
|
|
1955
|
-
|
|
1956
|
-
|
|
1903
|
+
clippedGroup.insertBefore(stack, element3);
|
|
1904
|
+
stacks.set(key, stack);
|
|
1957
1905
|
}
|
|
1958
|
-
|
|
1959
|
-
dotsGroup.setAttribute("data-snap-dots", "true");
|
|
1960
|
-
dotsGroup.setAttribute("class", "oc-snap-dots");
|
|
1961
|
-
dotsGroup.setAttribute("pointer-events", "none");
|
|
1962
|
-
clippedGroup.appendChild(dotsGroup);
|
|
1906
|
+
stack.appendChild(element3);
|
|
1963
1907
|
}
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1908
|
+
}
|
|
1909
|
+
let pointCircles = null;
|
|
1910
|
+
let pointCircleCoords = null;
|
|
1911
|
+
const getPointCircles = () => {
|
|
1912
|
+
if (pointCircles === null) {
|
|
1913
|
+
pointCircles = Array.from(
|
|
1914
|
+
clippedGroup.querySelectorAll("circle.oc-mark-point")
|
|
1915
|
+
);
|
|
1968
1916
|
}
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1917
|
+
return pointCircles;
|
|
1918
|
+
};
|
|
1919
|
+
const getPointCircleCoords = () => {
|
|
1920
|
+
if (pointCircleCoords === null) {
|
|
1921
|
+
pointCircleCoords = getPointCircles().map((el) => ({
|
|
1922
|
+
cx: Number(el.getAttribute("cx")),
|
|
1923
|
+
cy: Number(el.getAttribute("cy"))
|
|
1924
|
+
}));
|
|
1925
|
+
}
|
|
1926
|
+
return pointCircleCoords;
|
|
1927
|
+
};
|
|
1928
|
+
const hasLineOrAreaWithDataPoints = layout.marks.some(
|
|
1929
|
+
(m) => (m.type === "line" || m.type === "area") && m.dataPoints && m.dataPoints.length > 0
|
|
1930
|
+
);
|
|
1931
|
+
if (interactive && hasLineOrAreaWithDataPoints) {
|
|
1932
|
+
for (const el of getPointCircles()) {
|
|
1933
|
+
el.setAttribute("pointer-events", "none");
|
|
1934
|
+
}
|
|
1935
|
+
const overlay = createSVGElement("rect", ctx.factory);
|
|
1936
|
+
setAttrs(overlay, {
|
|
1937
|
+
x: layout.area.x,
|
|
1938
|
+
y: layout.area.y,
|
|
1939
|
+
width: layout.area.width,
|
|
1940
|
+
height: layout.area.height,
|
|
1941
|
+
fill: "transparent"
|
|
1942
|
+
});
|
|
1943
|
+
overlay.setAttribute("class", "oc-voronoi-overlay");
|
|
1944
|
+
overlay.setAttribute("data-voronoi-overlay", "true");
|
|
1945
|
+
clippedGroup.appendChild(overlay);
|
|
1946
|
+
if (opts?.crosshair) {
|
|
1947
|
+
const crosshairLine = createSVGElement("line", ctx.factory);
|
|
1948
|
+
crosshairLine.setAttribute("data-crosshair", "true");
|
|
1949
|
+
crosshairLine.setAttribute("class", "oc-crosshair");
|
|
1950
|
+
setAttrs(crosshairLine, {
|
|
1951
|
+
x1: 0,
|
|
1952
|
+
y1: layout.area.y,
|
|
1953
|
+
x2: 0,
|
|
1954
|
+
y2: layout.area.y + layout.area.height,
|
|
1955
|
+
stroke: layout.theme.colors.axis,
|
|
1956
|
+
"stroke-opacity": "0.4",
|
|
1957
|
+
"stroke-dasharray": "3,3",
|
|
1958
|
+
"stroke-width": "1",
|
|
1959
|
+
"pointer-events": "none"
|
|
1960
|
+
});
|
|
1961
|
+
crosshairLine.style.display = "none";
|
|
1962
|
+
clippedGroup.appendChild(crosshairLine);
|
|
1963
|
+
}
|
|
1964
|
+
const dotsGroup = createSVGElement("g", ctx.factory);
|
|
1965
|
+
dotsGroup.setAttribute("data-snap-dots", "true");
|
|
1966
|
+
dotsGroup.setAttribute("class", "oc-snap-dots");
|
|
1967
|
+
dotsGroup.setAttribute("pointer-events", "none");
|
|
1968
|
+
clippedGroup.appendChild(dotsGroup);
|
|
1969
|
+
}
|
|
1970
|
+
svg.appendChild(clipGroup);
|
|
1971
|
+
renderAnnotations(svg, layout, interactive, ctx);
|
|
1972
|
+
if (markLabelsOverlay) {
|
|
1973
|
+
svg.appendChild(markLabelsOverlay);
|
|
1974
|
+
}
|
|
1975
|
+
renderEndpointLabels(svg, layout, ctx);
|
|
1976
|
+
const epEntries = layout.endpointLabels?.entries ?? [];
|
|
1977
|
+
if (epEntries.length > 0) {
|
|
1978
|
+
const pointEls = getPointCircles();
|
|
1979
|
+
const coords = getPointCircleCoords();
|
|
1980
|
+
for (const entry of epEntries) {
|
|
1981
|
+
if (!entry.marker) continue;
|
|
1982
|
+
const mx = entry.marker.dataX;
|
|
1983
|
+
const my = entry.marker.y;
|
|
1984
|
+
for (let i = 0; i < pointEls.length; i++) {
|
|
1985
|
+
const { cx, cy } = coords[i];
|
|
1986
|
+
if (Math.abs(cx - mx) < 0.5 && Math.abs(cy - my) < 0.5) {
|
|
1987
|
+
pointEls[i].setAttribute("opacity", "0");
|
|
1983
1988
|
}
|
|
1984
1989
|
}
|
|
1985
1990
|
}
|
|
1986
1991
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
} finally {
|
|
1996
|
-
resetMarkRenderState();
|
|
1992
|
+
}
|
|
1993
|
+
for (const legend of layout.legends ?? [layout.legend]) {
|
|
1994
|
+
renderLegend(svg, legend, interactive, ctx);
|
|
1995
|
+
}
|
|
1996
|
+
renderChrome(svg, layout, interactive, ctx);
|
|
1997
|
+
renderMetrics(svg, layout, ctx);
|
|
1998
|
+
if (layout.watermark && !layout.chrome.brand) {
|
|
1999
|
+
renderBrand(svg, layout, ctx);
|
|
1997
2000
|
}
|
|
1998
2001
|
if (canvasMarks) {
|
|
1999
2002
|
svg.style.pointerEvents = "none";
|
|
@@ -2002,16 +2005,17 @@ function renderChartSVG(layout, container, opts) {
|
|
|
2002
2005
|
}
|
|
2003
2006
|
svg.style.position = "relative";
|
|
2004
2007
|
}
|
|
2005
|
-
wireAnnotationNotes(svg);
|
|
2008
|
+
if (interactive) wireAnnotationNotes(svg);
|
|
2006
2009
|
container.appendChild(svg);
|
|
2007
2010
|
return svg;
|
|
2008
2011
|
}
|
|
2009
|
-
function renderFacetedPanels(svg, layout, panels, defs) {
|
|
2012
|
+
function renderFacetedPanels(svg, layout, panels, defs, interactive = true, ctx = createRenderContext()) {
|
|
2013
|
+
let markIndexOffset = 0;
|
|
2010
2014
|
for (const panel of panels) {
|
|
2011
|
-
const g = createSVGElement("g");
|
|
2015
|
+
const g = createSVGElement("g", ctx.factory);
|
|
2012
2016
|
g.setAttribute("class", "oc-facet-panel");
|
|
2013
2017
|
g.setAttribute("data-facet", panel.key);
|
|
2014
|
-
const bg = createSVGElement("rect");
|
|
2018
|
+
const bg = createSVGElement("rect", ctx.factory);
|
|
2015
2019
|
setAttrs(bg, {
|
|
2016
2020
|
x: panel.area.x,
|
|
2017
2021
|
y: panel.area.y,
|
|
@@ -2021,7 +2025,7 @@ function renderFacetedPanels(svg, layout, panels, defs) {
|
|
|
2021
2025
|
fill: layout.theme.isDark ? "rgba(255,255,255,0.03)" : "rgba(0,0,0,0.02)"
|
|
2022
2026
|
});
|
|
2023
2027
|
g.appendChild(bg);
|
|
2024
|
-
const headerText = createSVGElement("text");
|
|
2028
|
+
const headerText = createSVGElement("text", ctx.factory);
|
|
2025
2029
|
setAttrs(headerText, {
|
|
2026
2030
|
x: panel.header.x,
|
|
2027
2031
|
y: panel.header.y,
|
|
@@ -2040,11 +2044,11 @@ function renderFacetedPanels(svg, layout, panels, defs) {
|
|
|
2040
2044
|
marks: panel.marks,
|
|
2041
2045
|
annotations: panel.annotations
|
|
2042
2046
|
};
|
|
2043
|
-
renderAxes(g, panelLayout);
|
|
2044
|
-
const panelClipId =
|
|
2045
|
-
const clipPath = createSVGElement("clipPath");
|
|
2047
|
+
renderAxes(g, panelLayout, void 0, ctx);
|
|
2048
|
+
const panelClipId = ctx.ids.next("oc-facet-clip");
|
|
2049
|
+
const clipPath = createSVGElement("clipPath", ctx.factory);
|
|
2046
2050
|
clipPath.setAttribute("id", panelClipId);
|
|
2047
|
-
const clipRect = createSVGElement("rect");
|
|
2051
|
+
const clipRect = createSVGElement("rect", ctx.factory);
|
|
2048
2052
|
setAttrs(clipRect, {
|
|
2049
2053
|
x: panel.area.x,
|
|
2050
2054
|
y: panel.area.y,
|
|
@@ -2053,11 +2057,12 @@ function renderFacetedPanels(svg, layout, panels, defs) {
|
|
|
2053
2057
|
});
|
|
2054
2058
|
clipPath.appendChild(clipRect);
|
|
2055
2059
|
defs.appendChild(clipPath);
|
|
2056
|
-
const clippedGroup = createSVGElement("g");
|
|
2060
|
+
const clippedGroup = createSVGElement("g", ctx.factory);
|
|
2057
2061
|
clippedGroup.setAttribute("clip-path", `url(#${panelClipId})`);
|
|
2058
|
-
const panelLabelsOverlay = renderMarks(clippedGroup, panelLayout);
|
|
2062
|
+
const panelLabelsOverlay = renderMarks(clippedGroup, panelLayout, { markIndexOffset }, ctx);
|
|
2063
|
+
markIndexOffset += panel.marks.length;
|
|
2059
2064
|
g.appendChild(clippedGroup);
|
|
2060
|
-
renderAnnotations(g, panelLayout);
|
|
2065
|
+
renderAnnotations(g, panelLayout, interactive, ctx);
|
|
2061
2066
|
if (panelLabelsOverlay) {
|
|
2062
2067
|
g.appendChild(panelLabelsOverlay);
|
|
2063
2068
|
}
|
|
@@ -2182,441 +2187,188 @@ function scrubCamera(step, stepProgress, fitted, holdUntil, ease) {
|
|
|
2182
2187
|
return interpolateCamera(current, next, ease(t));
|
|
2183
2188
|
}
|
|
2184
2189
|
|
|
2185
|
-
// src/
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
minY = Math.min(minY, f.bounds.y);
|
|
2199
|
-
maxX = Math.max(maxX, f.bounds.x + f.bounds.width);
|
|
2200
|
-
maxY = Math.max(maxY, f.bounds.y + f.bounds.height);
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
if (!found) return null;
|
|
2204
|
-
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY, padding };
|
|
2190
|
+
// src/dom-helpers.ts
|
|
2191
|
+
function applySrOnlyStyles(el) {
|
|
2192
|
+
el.style.position = "absolute";
|
|
2193
|
+
el.style.top = "0";
|
|
2194
|
+
el.style.left = "0";
|
|
2195
|
+
el.style.width = "1px";
|
|
2196
|
+
el.style.height = "1px";
|
|
2197
|
+
el.style.padding = "0";
|
|
2198
|
+
el.style.margin = "-1px";
|
|
2199
|
+
el.style.overflow = "clip";
|
|
2200
|
+
el.style.clipPath = "inset(50%)";
|
|
2201
|
+
el.style.whiteSpace = "nowrap";
|
|
2202
|
+
el.style.borderWidth = "0";
|
|
2205
2203
|
}
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2204
|
+
|
|
2205
|
+
// src/map-label-inventory.ts
|
|
2206
|
+
var explanations = {
|
|
2207
|
+
visible: "Visible on map",
|
|
2208
|
+
collision: "Omitted to avoid overlapping labels",
|
|
2209
|
+
"zoom-range": "Visible at another zoom level",
|
|
2210
|
+
offscreen: "Outside the current map view",
|
|
2211
|
+
unresolved: "Anchor could not be resolved",
|
|
2212
|
+
"geometry-budget": "Limited geographic label geometry"
|
|
2213
|
+
};
|
|
2214
|
+
var limitations = {
|
|
2215
|
+
"candidate-limit": "Visual label candidate limit reached",
|
|
2216
|
+
"vertex-limit": "Canonical anchor used because the projected geometry budget was reached",
|
|
2217
|
+
"search-limit": "Interior anchor search limit reached"
|
|
2218
|
+
};
|
|
2219
|
+
function geographicInventoryText(entry) {
|
|
2220
|
+
const anchor = entry.anchor.kind === "coordinate" ? `${entry.anchor.space} coordinate ${entry.anchor.x}, ${entry.anchor.y}` : `${entry.anchor.kind} ${entry.anchor.id}`;
|
|
2221
|
+
return `${entry.id}: ${entry.text}${entry.subtitle ? `. ${entry.subtitle}` : ""}. ${anchor}. ${explanations[entry.visibility]}${entry.presentation === "note" ? "; available in map notes" : ""}${entry.limitation ? `. ${limitations[entry.limitation]}` : ""}.`;
|
|
2211
2222
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
};
|
|
2223
|
+
function mergeGeoLabelInventory(entries) {
|
|
2224
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2225
|
+
for (const entry of entries) {
|
|
2226
|
+
const prior = merged.get(entry.id);
|
|
2227
|
+
if (!prior || entry.visibility === "visible" && prior.visibility !== "visible")
|
|
2228
|
+
merged.set(entry.id, entry);
|
|
2229
|
+
}
|
|
2230
|
+
return [...merged.values()];
|
|
2221
2231
|
}
|
|
2222
|
-
function
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2232
|
+
function createMapLabelInventory(container, initial, ctx = createRenderContext()) {
|
|
2233
|
+
let id;
|
|
2234
|
+
let hidden = null;
|
|
2235
|
+
let disclosure = null;
|
|
2236
|
+
let options = initial;
|
|
2237
|
+
let entries = [];
|
|
2238
|
+
let svg = null;
|
|
2239
|
+
let theme;
|
|
2240
|
+
const fill = (target) => {
|
|
2241
|
+
const list = document.createElement("ul");
|
|
2242
|
+
for (const entry of entries) {
|
|
2243
|
+
const item = document.createElement("li");
|
|
2244
|
+
item.textContent = geographicInventoryText(entry);
|
|
2245
|
+
list.appendChild(item);
|
|
2246
|
+
}
|
|
2247
|
+
target.appendChild(list);
|
|
2248
|
+
};
|
|
2249
|
+
const detachAssociation = () => {
|
|
2250
|
+
if (!svg) return;
|
|
2251
|
+
const ids = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((value) => value && value !== id);
|
|
2252
|
+
if (ids.length) svg.setAttribute("aria-describedby", ids.join(" "));
|
|
2253
|
+
else svg.removeAttribute("aria-describedby");
|
|
2254
|
+
};
|
|
2255
|
+
const refresh = () => {
|
|
2256
|
+
detachAssociation();
|
|
2257
|
+
if (!entries.length) {
|
|
2258
|
+
hidden?.remove();
|
|
2259
|
+
hidden = null;
|
|
2260
|
+
disclosure?.remove();
|
|
2261
|
+
disclosure = null;
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
if (!hidden) {
|
|
2265
|
+
id ??= ctx.ids.next("oc-map-label-inventory");
|
|
2266
|
+
hidden = document.createElement("div");
|
|
2267
|
+
hidden.id = id;
|
|
2268
|
+
hidden.className = "oc-map-label-inventory oc-sr-only";
|
|
2269
|
+
applySrOnlyStyles(hidden);
|
|
2270
|
+
container.appendChild(hidden);
|
|
2271
|
+
}
|
|
2272
|
+
hidden.replaceChildren();
|
|
2273
|
+
fill(hidden);
|
|
2274
|
+
if (svg)
|
|
2275
|
+
svg.setAttribute(
|
|
2276
|
+
"aria-describedby",
|
|
2277
|
+
[svg.getAttribute("aria-describedby"), id].filter(Boolean).join(" ")
|
|
2278
|
+
);
|
|
2279
|
+
if (options) {
|
|
2280
|
+
if (!disclosure) {
|
|
2281
|
+
disclosure = document.createElement("details");
|
|
2282
|
+
const summary = document.createElement("summary");
|
|
2283
|
+
summary.textContent = "Map places and notes";
|
|
2284
|
+
disclosure.appendChild(summary);
|
|
2285
|
+
}
|
|
2286
|
+
if (theme) {
|
|
2287
|
+
Object.assign(disclosure.style, {
|
|
2288
|
+
fontFamily: theme.fonts.family,
|
|
2289
|
+
fontSize: `${theme.fonts.sizes.body}px`,
|
|
2290
|
+
lineHeight: "1.5",
|
|
2291
|
+
color: theme.colors.text,
|
|
2292
|
+
padding: "12px 0"
|
|
2293
|
+
});
|
|
2294
|
+
Object.assign(disclosure.firstElementChild.style, {
|
|
2295
|
+
cursor: "pointer",
|
|
2296
|
+
fontWeight: "600",
|
|
2297
|
+
padding: "4px 0"
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
const open = disclosure.open;
|
|
2301
|
+
while (disclosure.children.length > 1) disclosure.lastElementChild?.remove();
|
|
2302
|
+
fill(disclosure);
|
|
2303
|
+
disclosure.open = open;
|
|
2304
|
+
options.container.appendChild(disclosure);
|
|
2305
|
+
} else {
|
|
2306
|
+
disclosure?.remove();
|
|
2307
|
+
disclosure = null;
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2226
2310
|
return {
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2311
|
+
update(nextSvg, next, nextTheme) {
|
|
2312
|
+
theme = nextTheme;
|
|
2313
|
+
detachAssociation();
|
|
2314
|
+
svg = nextSvg;
|
|
2315
|
+
entries = next;
|
|
2316
|
+
refresh();
|
|
2317
|
+
},
|
|
2318
|
+
setOptions(next) {
|
|
2319
|
+
options = next;
|
|
2320
|
+
refresh();
|
|
2321
|
+
},
|
|
2322
|
+
destroy() {
|
|
2323
|
+
detachAssociation();
|
|
2324
|
+
hidden?.remove();
|
|
2325
|
+
disclosure?.remove();
|
|
2326
|
+
hidden = null;
|
|
2327
|
+
disclosure = null;
|
|
2328
|
+
svg = null;
|
|
2329
|
+
entries = [];
|
|
2330
|
+
}
|
|
2230
2331
|
};
|
|
2231
2332
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
const
|
|
2237
|
-
|
|
2333
|
+
|
|
2334
|
+
// src/map-labels.ts
|
|
2335
|
+
import { resolveGeoOverlay } from "@opendata-ai/openchart-engine";
|
|
2336
|
+
function element(tag, attrs = {}, ctx = createRenderContext()) {
|
|
2337
|
+
const el = ctx.factory.svg(tag);
|
|
2338
|
+
for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
|
|
2339
|
+
return el;
|
|
2238
2340
|
}
|
|
2239
|
-
function
|
|
2240
|
-
return {
|
|
2341
|
+
function mapLabelAffine(camera, layout) {
|
|
2342
|
+
return {
|
|
2343
|
+
k: camera.k,
|
|
2344
|
+
tx: layout.mapSize.width / 2 - camera.cx * camera.k,
|
|
2345
|
+
ty: layout.mapSize.height / 2 - camera.cy * camera.k
|
|
2346
|
+
};
|
|
2241
2347
|
}
|
|
2242
|
-
function
|
|
2243
|
-
const
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
}
|
|
2267
|
-
} else {
|
|
2268
|
-
cameraGroup.removeAttribute("transform");
|
|
2269
|
-
const paths = scope.querySelectorAll(".oc-map-feature, .oc-map-borders path");
|
|
2270
|
-
for (const p of paths) {
|
|
2271
|
-
p.removeAttribute("vector-effect");
|
|
2272
|
-
}
|
|
2273
|
-
const points = scope.querySelectorAll(".oc-map-point");
|
|
2274
|
-
for (const p of points) {
|
|
2275
|
-
const baseR = Number(p.getAttribute("data-base-r") ?? 5);
|
|
2276
|
-
const baseSW = Number(p.getAttribute("data-base-stroke-width") ?? 1);
|
|
2277
|
-
p.setAttribute("r", String(baseR));
|
|
2278
|
-
p.setAttribute("stroke-width", String(baseSW));
|
|
2279
|
-
p.removeAttribute("vector-effect");
|
|
2280
|
-
}
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
function ensureMapClip(svg, layout, clipId) {
|
|
2284
|
-
if (svg.querySelector(`#${clipId}`)) return;
|
|
2285
|
-
let defs = svg.querySelector("defs");
|
|
2286
|
-
if (!defs) {
|
|
2287
|
-
defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
2288
|
-
svg.insertBefore(defs, svg.firstChild);
|
|
2289
|
-
}
|
|
2290
|
-
const clip = document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
|
|
2291
|
-
clip.setAttribute("id", clipId);
|
|
2292
|
-
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
2293
|
-
rect.setAttribute("width", String(layout.area.width));
|
|
2294
|
-
rect.setAttribute("height", String(layout.area.height));
|
|
2295
|
-
clip.appendChild(rect);
|
|
2296
|
-
defs.appendChild(clip);
|
|
2297
|
-
}
|
|
2298
|
-
|
|
2299
|
-
// src/map-color-key.ts
|
|
2300
|
-
import { buildD3Formatter, formatNumber } from "@opendata-ai/openchart-core";
|
|
2301
|
-
import { geoColorKeyPosition } from "@opendata-ai/openchart-engine";
|
|
2302
|
-
var NS = "http://www.w3.org/2000/svg";
|
|
2303
|
-
var node = (tag, attrs, content) => {
|
|
2304
|
-
const el = document.createElementNS(NS, tag);
|
|
2305
|
-
for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
|
|
2306
|
-
if (content !== void 0) el.textContent = content;
|
|
2307
|
-
return el;
|
|
2308
|
-
};
|
|
2309
|
-
var text = (layout, x, y, value) => node(
|
|
2310
|
-
"text",
|
|
2311
|
-
{
|
|
2312
|
-
x,
|
|
2313
|
-
y,
|
|
2314
|
-
fill: layout.theme.colors.text,
|
|
2315
|
-
"font-family": layout.theme.fonts.family,
|
|
2316
|
-
"font-size": layout.theme.fonts.sizes.small
|
|
2317
|
-
},
|
|
2318
|
-
value
|
|
2319
|
-
);
|
|
2320
|
-
function renderStaticGeoColorKeys(svg, layout) {
|
|
2321
|
-
if (!layout.colorKeys) return;
|
|
2322
|
-
for (const [scope, key] of Object.entries(layout.colorKeys)) {
|
|
2323
|
-
const bounds = key?.distributionBounds;
|
|
2324
|
-
if (!key?.distribution || !bounds) continue;
|
|
2325
|
-
const group = node("g", { "data-geo-distribution": scope, role: "img" });
|
|
2326
|
-
const line = Math.ceil(layout.theme.fonts.sizes.small * 1.4);
|
|
2327
|
-
const noun = scope === "features" ? "Regions" : "Points";
|
|
2328
|
-
group.append(
|
|
2329
|
-
text(layout, bounds.x, bounds.y + layout.theme.fonts.sizes.small, `${noun} per range`)
|
|
2330
|
-
);
|
|
2331
|
-
group.append(
|
|
2332
|
-
text(
|
|
2333
|
-
layout,
|
|
2334
|
-
bounds.x,
|
|
2335
|
-
bounds.y + line + layout.theme.fonts.sizes.small,
|
|
2336
|
-
`No data: ${key.missing}`
|
|
2337
|
-
)
|
|
2338
|
-
);
|
|
2339
|
-
const bars = key.kind === "categorical" ? key.categories.map((category, index) => ({
|
|
2340
|
-
count: category.count,
|
|
2341
|
-
color: category.color,
|
|
2342
|
-
label: category.value,
|
|
2343
|
-
x: bounds.x + index * bounds.width / Math.max(1, key.categories.length),
|
|
2344
|
-
width: bounds.width / Math.max(1, key.categories.length)
|
|
2345
|
-
})) : key.classes.map((bin, index) => ({
|
|
2346
|
-
...bin,
|
|
2347
|
-
x: bounds.x + index * bounds.width / Math.max(1, key.classes.length),
|
|
2348
|
-
width: bounds.width / Math.max(1, key.classes.length),
|
|
2349
|
-
label: `${bin.lower ?? "\u2212\u221E"} to ${bin.upper ?? "\u221E"}`
|
|
2350
|
-
}));
|
|
2351
|
-
const max = Math.max(1, ...bars.map((bar) => bar.count));
|
|
2352
|
-
const chartY = bounds.y + line * 2 + 4;
|
|
2353
|
-
for (const bar of bars) {
|
|
2354
|
-
const height = 20 * bar.count / max;
|
|
2355
|
-
const rectangle = node("rect", {
|
|
2356
|
-
x: bar.x,
|
|
2357
|
-
y: chartY + 20 - height,
|
|
2358
|
-
width: Math.max(1, bar.width - 2),
|
|
2359
|
-
height,
|
|
2360
|
-
fill: bar.color
|
|
2361
|
-
});
|
|
2362
|
-
rectangle.append(node("title", {}, `${bar.label}: ${bar.count} ${noun.toLowerCase()}`));
|
|
2363
|
-
group.append(rectangle);
|
|
2364
|
-
const label = text(
|
|
2365
|
-
layout,
|
|
2366
|
-
bar.x + bar.width / 2,
|
|
2367
|
-
chartY + 20 + layout.theme.fonts.sizes.small,
|
|
2368
|
-
String(bar.count)
|
|
2369
|
-
);
|
|
2370
|
-
label.setAttribute("text-anchor", "middle");
|
|
2371
|
-
group.append(label);
|
|
2372
|
-
}
|
|
2373
|
-
group.setAttribute(
|
|
2374
|
-
"aria-label",
|
|
2375
|
-
`${noun} per range. ${bars.map((bar) => `${bar.label}: ${bar.count}`).join("; ")}. No data: ${key.missing}.`
|
|
2376
|
-
);
|
|
2377
|
-
svg.append(group);
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
function renderActiveGeoColorKeys(parent, layout, index, selection) {
|
|
2381
|
-
if (!layout.colorKeys) return;
|
|
2382
|
-
const active = selection.pinned.length ? selection.pinned : selection.preview ? [selection.preview] : [];
|
|
2383
|
-
for (const [scope, key] of Object.entries(layout.colorKeys)) {
|
|
2384
|
-
if (!key?.activeValue) continue;
|
|
2385
|
-
for (const [slot, observation] of active.entries()) {
|
|
2386
|
-
if (scope === "features" !== (observation.entity.kind === "feature")) continue;
|
|
2387
|
-
const record = index.byObservation.get(observation.observation);
|
|
2388
|
-
const row = key.activeRows[slot];
|
|
2389
|
-
if (!record || !row) continue;
|
|
2390
|
-
const value = record.color?.value;
|
|
2391
|
-
const position = geoColorKeyPosition(key, value);
|
|
2392
|
-
const format = key.format ? buildD3Formatter(key.format) : void 0;
|
|
2393
|
-
const exact = typeof value === "number" ? format ? format(value) : formatNumber(value) : value === "" ? "(empty)" : String(value ?? "No data");
|
|
2394
|
-
const suffix = position.missing ? "No data" : `${exact}${position.outside ? " \xB7 outside displayed range" : ""}`;
|
|
2395
|
-
const lines = key.activeLabels?.[`${typeof value}:${String(value)}`] ?? [`A: ${suffix}`];
|
|
2396
|
-
const advance = Math.ceil(layout.theme.fonts.sizes.small * 1.4);
|
|
2397
|
-
for (const [lineIndex, line] of lines.entries()) {
|
|
2398
|
-
const label = text(
|
|
2399
|
-
layout,
|
|
2400
|
-
row.x,
|
|
2401
|
-
row.y + layout.theme.fonts.sizes.small + lineIndex * advance,
|
|
2402
|
-
lineIndex === 0 ? line.replace(/^A:/, `${slot === 0 ? "A" : "B"}:`) : line
|
|
2403
|
-
);
|
|
2404
|
-
label.setAttribute("data-geo-active-value", scope);
|
|
2405
|
-
if (key.kind === "binned") {
|
|
2406
|
-
const title = node(
|
|
2407
|
-
"title",
|
|
2408
|
-
{},
|
|
2409
|
-
`${suffix}; marker identifies the range containing this value`
|
|
2410
|
-
);
|
|
2411
|
-
label.append(title);
|
|
2412
|
-
}
|
|
2413
|
-
parent.append(label);
|
|
2414
|
-
}
|
|
2415
|
-
if (position.category !== void 0) {
|
|
2416
|
-
const category = key.categories.find((category2) => category2.value === position.category);
|
|
2417
|
-
if (category)
|
|
2418
|
-
parent.append(
|
|
2419
|
-
node("rect", {
|
|
2420
|
-
...category.bounds,
|
|
2421
|
-
fill: "none",
|
|
2422
|
-
stroke: layout.theme.colors.text,
|
|
2423
|
-
"stroke-width": 2
|
|
2424
|
-
})
|
|
2425
|
-
);
|
|
2426
|
-
} else if (position.x !== void 0 && key.bar)
|
|
2427
|
-
parent.append(
|
|
2428
|
-
node("path", {
|
|
2429
|
-
d: position.y === void 0 ? `M${position.x - 3},${key.bar.y - 4} L${position.x},${key.bar.y} L${position.x + 3},${key.bar.y - 4}` : `M${position.x - 14},${position.y - 3} L${position.x - 10},${position.y} L${position.x - 14},${position.y + 3}`,
|
|
2430
|
-
stroke: layout.theme.colors.text,
|
|
2431
|
-
"stroke-width": 2,
|
|
2432
|
-
fill: "none"
|
|
2433
|
-
})
|
|
2434
|
-
);
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
|
|
2439
|
-
// src/map-labels.ts
|
|
2440
|
-
import { resolveGeoOverlay } from "@opendata-ai/openchart-engine";
|
|
2441
|
-
|
|
2442
|
-
// src/dom-helpers.ts
|
|
2443
|
-
function applySrOnlyStyles(el) {
|
|
2444
|
-
el.style.position = "absolute";
|
|
2445
|
-
el.style.top = "0";
|
|
2446
|
-
el.style.left = "0";
|
|
2447
|
-
el.style.width = "1px";
|
|
2448
|
-
el.style.height = "1px";
|
|
2449
|
-
el.style.padding = "0";
|
|
2450
|
-
el.style.margin = "-1px";
|
|
2451
|
-
el.style.overflow = "clip";
|
|
2452
|
-
el.style.clipPath = "inset(50%)";
|
|
2453
|
-
el.style.whiteSpace = "nowrap";
|
|
2454
|
-
el.style.borderWidth = "0";
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
// src/map-label-inventory.ts
|
|
2458
|
-
var explanations = {
|
|
2459
|
-
visible: "Visible on map",
|
|
2460
|
-
collision: "Omitted to avoid overlapping labels",
|
|
2461
|
-
"zoom-range": "Visible at another zoom level",
|
|
2462
|
-
offscreen: "Outside the current map view",
|
|
2463
|
-
unresolved: "Anchor could not be resolved",
|
|
2464
|
-
"geometry-budget": "Limited geographic label geometry"
|
|
2465
|
-
};
|
|
2466
|
-
var limitations = {
|
|
2467
|
-
"candidate-limit": "Visual label candidate limit reached",
|
|
2468
|
-
"vertex-limit": "Canonical anchor used because the projected geometry budget was reached",
|
|
2469
|
-
"search-limit": "Interior anchor search limit reached"
|
|
2470
|
-
};
|
|
2471
|
-
function geographicInventoryText(entry) {
|
|
2472
|
-
const anchor = entry.anchor.kind === "coordinate" ? `${entry.anchor.space} coordinate ${entry.anchor.x}, ${entry.anchor.y}` : `${entry.anchor.kind} ${entry.anchor.id}`;
|
|
2473
|
-
return `${entry.id}: ${entry.text}${entry.subtitle ? `. ${entry.subtitle}` : ""}. ${anchor}. ${explanations[entry.visibility]}${entry.presentation === "note" ? "; available in map notes" : ""}${entry.limitation ? `. ${limitations[entry.limitation]}` : ""}.`;
|
|
2474
|
-
}
|
|
2475
|
-
function mergeGeoLabelInventory(entries) {
|
|
2476
|
-
const merged = /* @__PURE__ */ new Map();
|
|
2477
|
-
for (const entry of entries) {
|
|
2478
|
-
const prior = merged.get(entry.id);
|
|
2479
|
-
if (!prior || entry.visibility === "visible" && prior.visibility !== "visible")
|
|
2480
|
-
merged.set(entry.id, entry);
|
|
2481
|
-
}
|
|
2482
|
-
return [...merged.values()];
|
|
2483
|
-
}
|
|
2484
|
-
function createMapLabelInventory(container, initial) {
|
|
2485
|
-
let id;
|
|
2486
|
-
let hidden = null;
|
|
2487
|
-
let disclosure = null;
|
|
2488
|
-
let options = initial;
|
|
2489
|
-
let entries = [];
|
|
2490
|
-
let svg = null;
|
|
2491
|
-
let theme;
|
|
2492
|
-
const fill = (target) => {
|
|
2493
|
-
const list = document.createElement("ul");
|
|
2494
|
-
for (const entry of entries) {
|
|
2495
|
-
const item = document.createElement("li");
|
|
2496
|
-
item.textContent = geographicInventoryText(entry);
|
|
2497
|
-
list.appendChild(item);
|
|
2498
|
-
}
|
|
2499
|
-
target.appendChild(list);
|
|
2500
|
-
};
|
|
2501
|
-
const detachAssociation = () => {
|
|
2502
|
-
if (!svg) return;
|
|
2503
|
-
const ids = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((value) => value && value !== id);
|
|
2504
|
-
if (ids.length) svg.setAttribute("aria-describedby", ids.join(" "));
|
|
2505
|
-
else svg.removeAttribute("aria-describedby");
|
|
2506
|
-
};
|
|
2507
|
-
const refresh = () => {
|
|
2508
|
-
detachAssociation();
|
|
2509
|
-
if (!entries.length) {
|
|
2510
|
-
hidden?.remove();
|
|
2511
|
-
hidden = null;
|
|
2512
|
-
disclosure?.remove();
|
|
2513
|
-
disclosure = null;
|
|
2514
|
-
return;
|
|
2515
|
-
}
|
|
2516
|
-
if (!hidden) {
|
|
2517
|
-
id ??= nextSvgId("oc-map-label-inventory");
|
|
2518
|
-
hidden = document.createElement("div");
|
|
2519
|
-
hidden.id = id;
|
|
2520
|
-
hidden.className = "oc-map-label-inventory oc-sr-only";
|
|
2521
|
-
applySrOnlyStyles(hidden);
|
|
2522
|
-
container.appendChild(hidden);
|
|
2523
|
-
}
|
|
2524
|
-
hidden.replaceChildren();
|
|
2525
|
-
fill(hidden);
|
|
2526
|
-
if (svg)
|
|
2527
|
-
svg.setAttribute(
|
|
2528
|
-
"aria-describedby",
|
|
2529
|
-
[svg.getAttribute("aria-describedby"), id].filter(Boolean).join(" ")
|
|
2530
|
-
);
|
|
2531
|
-
if (options) {
|
|
2532
|
-
if (!disclosure) {
|
|
2533
|
-
disclosure = document.createElement("details");
|
|
2534
|
-
const summary = document.createElement("summary");
|
|
2535
|
-
summary.textContent = "Map places and notes";
|
|
2536
|
-
disclosure.appendChild(summary);
|
|
2537
|
-
}
|
|
2538
|
-
if (theme) {
|
|
2539
|
-
Object.assign(disclosure.style, {
|
|
2540
|
-
fontFamily: theme.fonts.family,
|
|
2541
|
-
fontSize: `${theme.fonts.sizes.body}px`,
|
|
2542
|
-
lineHeight: "1.5",
|
|
2543
|
-
color: theme.colors.text,
|
|
2544
|
-
padding: "12px 0"
|
|
2545
|
-
});
|
|
2546
|
-
Object.assign(disclosure.firstElementChild.style, {
|
|
2547
|
-
cursor: "pointer",
|
|
2548
|
-
fontWeight: "600",
|
|
2549
|
-
padding: "4px 0"
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2552
|
-
const open = disclosure.open;
|
|
2553
|
-
while (disclosure.children.length > 1) disclosure.lastElementChild?.remove();
|
|
2554
|
-
fill(disclosure);
|
|
2555
|
-
disclosure.open = open;
|
|
2556
|
-
options.container.appendChild(disclosure);
|
|
2557
|
-
} else {
|
|
2558
|
-
disclosure?.remove();
|
|
2559
|
-
disclosure = null;
|
|
2560
|
-
}
|
|
2561
|
-
};
|
|
2562
|
-
return {
|
|
2563
|
-
update(nextSvg, next, nextTheme) {
|
|
2564
|
-
theme = nextTheme;
|
|
2565
|
-
detachAssociation();
|
|
2566
|
-
svg = nextSvg;
|
|
2567
|
-
entries = next;
|
|
2568
|
-
refresh();
|
|
2569
|
-
},
|
|
2570
|
-
setOptions(next) {
|
|
2571
|
-
options = next;
|
|
2572
|
-
refresh();
|
|
2573
|
-
},
|
|
2574
|
-
destroy() {
|
|
2575
|
-
detachAssociation();
|
|
2576
|
-
hidden?.remove();
|
|
2577
|
-
disclosure?.remove();
|
|
2578
|
-
hidden = null;
|
|
2579
|
-
disclosure = null;
|
|
2580
|
-
svg = null;
|
|
2581
|
-
entries = [];
|
|
2582
|
-
}
|
|
2583
|
-
};
|
|
2584
|
-
}
|
|
2585
|
-
|
|
2586
|
-
// src/map-labels.ts
|
|
2587
|
-
var NS2 = "http://www.w3.org/2000/svg";
|
|
2588
|
-
function element(tag, attrs = {}) {
|
|
2589
|
-
const el = document.createElementNS(NS2, tag);
|
|
2590
|
-
for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
|
|
2591
|
-
return el;
|
|
2592
|
-
}
|
|
2593
|
-
function mapLabelAffine(camera, layout) {
|
|
2594
|
-
return {
|
|
2595
|
-
k: camera.k,
|
|
2596
|
-
tx: layout.mapSize.width / 2 - camera.cx * camera.k,
|
|
2597
|
-
ty: layout.mapSize.height / 2 - camera.cy * camera.k
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2600
|
-
function textBlock(parent, block, x, y, halo) {
|
|
2601
|
-
for (const line of block.lines) {
|
|
2602
|
-
const text2 = element("text", {
|
|
2603
|
-
x: x + line.x,
|
|
2604
|
-
y: y + line.y,
|
|
2605
|
-
"font-family": line.style.fontFamily,
|
|
2606
|
-
"font-size": line.style.fontSize,
|
|
2607
|
-
"font-weight": line.style.fontWeight,
|
|
2608
|
-
fill: line.style.fill,
|
|
2609
|
-
"text-anchor": line.style.textAnchor ?? "start",
|
|
2610
|
-
stroke: halo,
|
|
2611
|
-
"stroke-width": 2,
|
|
2612
|
-
"stroke-opacity": 0.85,
|
|
2613
|
-
"paint-order": "stroke fill",
|
|
2614
|
-
"stroke-linejoin": "round"
|
|
2615
|
-
});
|
|
2616
|
-
if (line.style.fontVariant) text2.setAttribute("font-variant", line.style.fontVariant);
|
|
2617
|
-
text2.textContent = line.text;
|
|
2618
|
-
parent.appendChild(text2);
|
|
2619
|
-
}
|
|
2348
|
+
function textBlock(parent, block, x, y, halo, ctx = createRenderContext()) {
|
|
2349
|
+
for (const line of block.lines) {
|
|
2350
|
+
const text2 = element(
|
|
2351
|
+
"text",
|
|
2352
|
+
{
|
|
2353
|
+
x: x + line.x,
|
|
2354
|
+
y: y + line.y,
|
|
2355
|
+
"font-family": line.style.fontFamily,
|
|
2356
|
+
"font-size": line.style.fontSize,
|
|
2357
|
+
"font-weight": line.style.fontWeight,
|
|
2358
|
+
fill: line.style.fill,
|
|
2359
|
+
"text-anchor": line.style.textAnchor ?? "start",
|
|
2360
|
+
stroke: halo,
|
|
2361
|
+
"stroke-width": 2,
|
|
2362
|
+
"stroke-opacity": 0.85,
|
|
2363
|
+
"paint-order": "stroke fill",
|
|
2364
|
+
"stroke-linejoin": "round"
|
|
2365
|
+
},
|
|
2366
|
+
ctx
|
|
2367
|
+
);
|
|
2368
|
+
if (line.style.fontVariant) text2.setAttribute("font-variant", line.style.fontVariant);
|
|
2369
|
+
text2.textContent = line.text;
|
|
2370
|
+
parent.appendChild(text2);
|
|
2371
|
+
}
|
|
2620
2372
|
}
|
|
2621
2373
|
function projectAcceptedGeoOverlay(accepted, from, to, layout) {
|
|
2622
2374
|
const move = (p) => ({
|
|
@@ -2671,40 +2423,48 @@ function projectAcceptedGeoOverlay(accepted, from, to, layout) {
|
|
|
2671
2423
|
)
|
|
2672
2424
|
};
|
|
2673
2425
|
}
|
|
2674
|
-
function renderGeoLabelOverlay(svg, layout, overlay) {
|
|
2426
|
+
function renderGeoLabelOverlay(svg, layout, overlay, ctx = createRenderContext()) {
|
|
2675
2427
|
svg.querySelector(".oc-map-labels")?.remove();
|
|
2676
2428
|
svg.querySelector(".oc-map-label-notes")?.remove();
|
|
2677
2429
|
if (!layout.labels) return;
|
|
2678
|
-
const group = element(
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2430
|
+
const group = element(
|
|
2431
|
+
"g",
|
|
2432
|
+
{
|
|
2433
|
+
class: "oc-map-labels",
|
|
2434
|
+
"pointer-events": "none",
|
|
2435
|
+
"aria-hidden": "true",
|
|
2436
|
+
transform: `translate(${layout.area.x},${layout.area.y})`
|
|
2437
|
+
},
|
|
2438
|
+
ctx
|
|
2439
|
+
);
|
|
2440
|
+
const clipId = ctx.ids.next("oc-map-label-clip");
|
|
2441
|
+
const defs = element("defs", void 0, ctx);
|
|
2442
|
+
const clip = element("clipPath", { id: clipId }, ctx);
|
|
2443
|
+
clip.appendChild(element("rect", { ...layout.labels.viewport }, ctx));
|
|
2688
2444
|
defs.appendChild(clip);
|
|
2689
2445
|
group.appendChild(defs);
|
|
2690
|
-
const viewport = element("g", { "clip-path": `url(#${clipId})` });
|
|
2446
|
+
const viewport = element("g", { "clip-path": `url(#${clipId})` }, ctx);
|
|
2691
2447
|
group.appendChild(viewport);
|
|
2692
2448
|
const halo = layout.theme.colors.background === "transparent" ? "var(--oc-bg, #fff)" : layout.theme.colors.background;
|
|
2693
2449
|
for (const leader of overlay.leaders)
|
|
2694
2450
|
viewport.appendChild(
|
|
2695
|
-
element(
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2451
|
+
element(
|
|
2452
|
+
"line",
|
|
2453
|
+
{
|
|
2454
|
+
x1: leader.from.x,
|
|
2455
|
+
y1: leader.from.y,
|
|
2456
|
+
x2: leader.to.x,
|
|
2457
|
+
y2: leader.to.y,
|
|
2458
|
+
stroke: layout.theme.colors.text,
|
|
2459
|
+
"stroke-opacity": 0.6,
|
|
2460
|
+
"stroke-width": 1
|
|
2461
|
+
},
|
|
2462
|
+
ctx
|
|
2463
|
+
)
|
|
2704
2464
|
);
|
|
2705
2465
|
for (const label of overlay.labels) {
|
|
2706
|
-
const item = element("g", { "data-geo-label-id": label.id });
|
|
2707
|
-
textBlock(item, label.block, label.bounds.x, label.bounds.y, halo);
|
|
2466
|
+
const item = element("g", { "data-geo-label-id": label.id }, ctx);
|
|
2467
|
+
textBlock(item, label.block, label.bounds.x, label.bounds.y, halo, ctx);
|
|
2708
2468
|
viewport.appendChild(item);
|
|
2709
2469
|
}
|
|
2710
2470
|
const markerRadius = layout.labels.markerRadius ?? 7 * layout.theme.fonts.sizes.small / 12;
|
|
@@ -2713,48 +2473,60 @@ function renderGeoLabelOverlay(svg, layout, overlay) {
|
|
|
2713
2473
|
const markerViewport = layout.labels.viewport;
|
|
2714
2474
|
if (marker.anchor.x - markerRadius < markerViewport.x || marker.anchor.y - markerRadius < markerViewport.y || marker.anchor.x + markerRadius > markerViewport.x + markerViewport.width || marker.anchor.y + markerRadius > markerViewport.y + markerViewport.height)
|
|
2715
2475
|
continue;
|
|
2716
|
-
const item = element("g", { "data-geo-note-id": marker.id });
|
|
2476
|
+
const item = element("g", { "data-geo-note-id": marker.id }, ctx);
|
|
2717
2477
|
item.appendChild(
|
|
2718
|
-
element(
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2478
|
+
element(
|
|
2479
|
+
"circle",
|
|
2480
|
+
{
|
|
2481
|
+
cx: marker.anchor.x,
|
|
2482
|
+
cy: marker.anchor.y,
|
|
2483
|
+
r: markerRadius,
|
|
2484
|
+
fill: halo,
|
|
2485
|
+
stroke: layout.theme.colors.text
|
|
2486
|
+
},
|
|
2487
|
+
ctx
|
|
2488
|
+
)
|
|
2489
|
+
);
|
|
2490
|
+
const number = element(
|
|
2491
|
+
"text",
|
|
2492
|
+
{
|
|
2493
|
+
x: marker.anchor.x,
|
|
2494
|
+
y: marker.anchor.y + 3 * markerScale,
|
|
2495
|
+
"font-size": 9 * markerScale,
|
|
2496
|
+
"font-family": layout.theme.fonts.family,
|
|
2497
|
+
"text-anchor": "middle",
|
|
2498
|
+
fill: layout.theme.colors.text
|
|
2499
|
+
},
|
|
2500
|
+
ctx
|
|
2725
2501
|
);
|
|
2726
|
-
const number = element("text", {
|
|
2727
|
-
x: marker.anchor.x,
|
|
2728
|
-
y: marker.anchor.y + 3 * markerScale,
|
|
2729
|
-
"font-size": 9 * markerScale,
|
|
2730
|
-
"font-family": layout.theme.fonts.family,
|
|
2731
|
-
"text-anchor": "middle",
|
|
2732
|
-
fill: layout.theme.colors.text
|
|
2733
|
-
});
|
|
2734
2502
|
number.textContent = String(marker.number);
|
|
2735
2503
|
item.appendChild(number);
|
|
2736
2504
|
viewport.appendChild(item);
|
|
2737
2505
|
}
|
|
2738
2506
|
const mapGroup = svg.querySelector(".oc-map-group");
|
|
2739
2507
|
mapGroup?.insertAdjacentElement("afterend", group);
|
|
2740
|
-
renderGeoLabelNotes(svg, layout, overlay.notes, group);
|
|
2508
|
+
renderGeoLabelNotes(svg, layout, overlay.notes, group, ctx);
|
|
2741
2509
|
}
|
|
2742
|
-
function renderGeoLabelNotes(svg, layout, entries, after) {
|
|
2510
|
+
function renderGeoLabelNotes(svg, layout, entries, after, ctx = createRenderContext()) {
|
|
2743
2511
|
const halo = layout.theme.colors.background === "transparent" ? "var(--oc-bg, #fff)" : layout.theme.colors.background;
|
|
2744
|
-
const notes = element(
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2512
|
+
const notes = element(
|
|
2513
|
+
"g",
|
|
2514
|
+
{
|
|
2515
|
+
class: "oc-map-label-notes",
|
|
2516
|
+
"aria-hidden": "true",
|
|
2517
|
+
transform: `translate(${layout.area.x},${layout.area.y})`
|
|
2518
|
+
},
|
|
2519
|
+
ctx
|
|
2520
|
+
);
|
|
2749
2521
|
for (const { id, slot } of entries) {
|
|
2750
|
-
const item = element("g", { "data-geo-note-id": id });
|
|
2751
|
-
textBlock(item, slot.block, slot.bounds.x, slot.bounds.y, halo);
|
|
2522
|
+
const item = element("g", { "data-geo-note-id": id }, ctx);
|
|
2523
|
+
textBlock(item, slot.block, slot.bounds.x, slot.bounds.y, halo, ctx);
|
|
2752
2524
|
notes.appendChild(item);
|
|
2753
2525
|
}
|
|
2754
2526
|
if (after) after.insertAdjacentElement("afterend", notes);
|
|
2755
2527
|
else svg.appendChild(notes);
|
|
2756
2528
|
}
|
|
2757
|
-
function describeGeoLabelInventory(svg, overlay) {
|
|
2529
|
+
function describeGeoLabelInventory(svg, overlay, ctx = createRenderContext()) {
|
|
2758
2530
|
const previous = svg.querySelector("desc[data-geo-label-inventory]");
|
|
2759
2531
|
if (previous) {
|
|
2760
2532
|
const ids2 = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((id) => id && id !== previous.id);
|
|
@@ -2763,10 +2535,14 @@ function describeGeoLabelInventory(svg, overlay) {
|
|
|
2763
2535
|
previous.remove();
|
|
2764
2536
|
}
|
|
2765
2537
|
if (!overlay.inventory.length) return;
|
|
2766
|
-
const desc = element(
|
|
2767
|
-
"
|
|
2768
|
-
|
|
2769
|
-
|
|
2538
|
+
const desc = element(
|
|
2539
|
+
"desc",
|
|
2540
|
+
{
|
|
2541
|
+
"data-geo-label-inventory": "",
|
|
2542
|
+
id: ctx.ids.next("oc-map-label-description")
|
|
2543
|
+
},
|
|
2544
|
+
ctx
|
|
2545
|
+
);
|
|
2770
2546
|
desc.textContent = `Map places and notes. ${overlay.inventory.map(geographicInventoryText).join(" ")}`;
|
|
2771
2547
|
svg.appendChild(desc);
|
|
2772
2548
|
const ids = (svg.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
|
|
@@ -2895,10 +2671,123 @@ function createMapViewCameras(onFrame, onSettle) {
|
|
|
2895
2671
|
};
|
|
2896
2672
|
}
|
|
2897
2673
|
|
|
2674
|
+
// src/map-camera.ts
|
|
2675
|
+
var FOCUS_DIM_OPACITY = 0.25;
|
|
2676
|
+
function focusTargetForFeatures(layout, ids, padding = 16) {
|
|
2677
|
+
const idSet = new Set(ids.map(String));
|
|
2678
|
+
let minX = Infinity;
|
|
2679
|
+
let minY = Infinity;
|
|
2680
|
+
let maxX = -Infinity;
|
|
2681
|
+
let maxY = -Infinity;
|
|
2682
|
+
let found = false;
|
|
2683
|
+
for (const f of layout.features) {
|
|
2684
|
+
if (idSet.has(String(f.id))) {
|
|
2685
|
+
found = true;
|
|
2686
|
+
minX = Math.min(minX, f.bounds.x);
|
|
2687
|
+
minY = Math.min(minY, f.bounds.y);
|
|
2688
|
+
maxX = Math.max(maxX, f.bounds.x + f.bounds.width);
|
|
2689
|
+
maxY = Math.max(maxY, f.bounds.y + f.bounds.height);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
if (!found) return null;
|
|
2693
|
+
return { x: minX, y: minY, width: maxX - minX, height: maxY - minY, padding };
|
|
2694
|
+
}
|
|
2695
|
+
function cameraForTarget(layout, target) {
|
|
2696
|
+
const vb = layout.mapSize;
|
|
2697
|
+
if (!target) return fitTarget(FULL_VIEW(vb), vb);
|
|
2698
|
+
const cam = fitTarget(target, vb);
|
|
2699
|
+
return { ...cam, k: Math.max(1, Math.min(40, cam.k)) };
|
|
2700
|
+
}
|
|
2701
|
+
var DEFAULT_MAX_ZOOM = 12;
|
|
2702
|
+
function resolveMapZoom(zoom) {
|
|
2703
|
+
if (!zoom) return null;
|
|
2704
|
+
const cfg = zoom === true ? {} : zoom;
|
|
2705
|
+
const max = cfg.maxZoom;
|
|
2706
|
+
return {
|
|
2707
|
+
maxZoom: typeof max === "number" && Number.isFinite(max) ? Math.max(1, max) : DEFAULT_MAX_ZOOM,
|
|
2708
|
+
controls: cfg.controls !== false
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
function clampMapCamera(camera, vb, maxZoom) {
|
|
2712
|
+
const k = Math.min(Math.max(camera.k, 1), Math.max(1, maxZoom));
|
|
2713
|
+
const halfW = vb.width / (2 * k);
|
|
2714
|
+
const halfH = vb.height / (2 * k);
|
|
2715
|
+
return {
|
|
2716
|
+
cx: Math.min(Math.max(camera.cx, halfW), vb.width - halfW),
|
|
2717
|
+
cy: Math.min(Math.max(camera.cy, halfH), vb.height - halfH),
|
|
2718
|
+
k
|
|
2719
|
+
};
|
|
2720
|
+
}
|
|
2721
|
+
function zoomCameraAt(camera, vb, k, pivotX, pivotY) {
|
|
2722
|
+
const ox = pivotX - vb.width / 2;
|
|
2723
|
+
const oy = pivotY - vb.height / 2;
|
|
2724
|
+
const px = camera.cx + ox / camera.k;
|
|
2725
|
+
const py = camera.cy + oy / camera.k;
|
|
2726
|
+
return { cx: px - ox / k, cy: py - oy / k, k };
|
|
2727
|
+
}
|
|
2728
|
+
function panCamera(camera, dx, dy) {
|
|
2729
|
+
return { cx: camera.cx - dx / camera.k, cy: camera.cy - dy / camera.k, k: camera.k };
|
|
2730
|
+
}
|
|
2731
|
+
function wheelZoomFactor(e) {
|
|
2732
|
+
const perUnit = e.deltaMode === 1 ? 0.05 : e.deltaMode === 2 ? 1 : 2e-3;
|
|
2733
|
+
let exp = -e.deltaY * perUnit;
|
|
2734
|
+
if (e.ctrlKey && e.deltaMode === 0 && Math.abs(e.deltaY) < 50) exp *= 5;
|
|
2735
|
+
return 2 ** Math.max(-1, Math.min(1, exp));
|
|
2736
|
+
}
|
|
2737
|
+
function applyMapCamera(svg, camera, layout) {
|
|
2738
|
+
const scope = svg.querySelector('[data-geo-view-id="root"]') ?? svg;
|
|
2739
|
+
const cameraGroup = scope.querySelector("[data-oc-map-camera]");
|
|
2740
|
+
if (!cameraGroup) return;
|
|
2741
|
+
const vb = layout.mapSize;
|
|
2742
|
+
const isZoomed = Math.abs(camera.k - 1) > 1e-3;
|
|
2743
|
+
if (isZoomed) {
|
|
2744
|
+
cameraGroup.setAttribute("transform", cameraTransform(camera, vb));
|
|
2745
|
+
const paths = scope.querySelectorAll(".oc-map-feature, .oc-map-borders path");
|
|
2746
|
+
for (const p of paths) {
|
|
2747
|
+
p.setAttribute("vector-effect", "non-scaling-stroke");
|
|
2748
|
+
}
|
|
2749
|
+
const points = scope.querySelectorAll(".oc-map-point");
|
|
2750
|
+
for (const p of points) {
|
|
2751
|
+
const baseR = Number(p.getAttribute("data-base-r") ?? 5);
|
|
2752
|
+
const baseSW = Number(p.getAttribute("data-base-stroke-width") ?? 1);
|
|
2753
|
+
p.setAttribute("r", String(baseR / camera.k));
|
|
2754
|
+
p.setAttribute("stroke-width", String(baseSW / camera.k));
|
|
2755
|
+
}
|
|
2756
|
+
} else {
|
|
2757
|
+
cameraGroup.removeAttribute("transform");
|
|
2758
|
+
const paths = scope.querySelectorAll(".oc-map-feature, .oc-map-borders path");
|
|
2759
|
+
for (const p of paths) {
|
|
2760
|
+
p.removeAttribute("vector-effect");
|
|
2761
|
+
}
|
|
2762
|
+
const points = scope.querySelectorAll(".oc-map-point");
|
|
2763
|
+
for (const p of points) {
|
|
2764
|
+
const baseR = Number(p.getAttribute("data-base-r") ?? 5);
|
|
2765
|
+
const baseSW = Number(p.getAttribute("data-base-stroke-width") ?? 1);
|
|
2766
|
+
p.setAttribute("r", String(baseR));
|
|
2767
|
+
p.setAttribute("stroke-width", String(baseSW));
|
|
2768
|
+
p.removeAttribute("vector-effect");
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
function ensureMapClip(svg, layout, clipId, ctx = createRenderContext()) {
|
|
2773
|
+
if (svg.querySelector(`#${clipId}`)) return;
|
|
2774
|
+
let defs = svg.querySelector("defs");
|
|
2775
|
+
if (!defs) {
|
|
2776
|
+
defs = ctx.factory.svg("defs");
|
|
2777
|
+
svg.insertBefore(defs, svg.firstChild);
|
|
2778
|
+
}
|
|
2779
|
+
const clip = ctx.factory.svg("clipPath");
|
|
2780
|
+
clip.setAttribute("id", clipId);
|
|
2781
|
+
const rect = ctx.factory.svg("rect");
|
|
2782
|
+
rect.setAttribute("width", String(layout.area.width));
|
|
2783
|
+
rect.setAttribute("height", String(layout.area.height));
|
|
2784
|
+
clip.appendChild(rect);
|
|
2785
|
+
defs.appendChild(clip);
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2898
2788
|
// src/map-view-renderer.ts
|
|
2899
|
-
var
|
|
2900
|
-
|
|
2901
|
-
const el = document.createElementNS(NS3, tag);
|
|
2789
|
+
var element2 = (tag, attrs = {}, ctx = createRenderContext()) => {
|
|
2790
|
+
const el = ctx.factory.svg(tag);
|
|
2902
2791
|
for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
|
|
2903
2792
|
return el;
|
|
2904
2793
|
};
|
|
@@ -2920,69 +2809,93 @@ function geoViewMapLayout(layout, view) {
|
|
|
2920
2809
|
focus: view.focus
|
|
2921
2810
|
};
|
|
2922
2811
|
}
|
|
2923
|
-
function renderGeoMapViews(svg, layout, patterns, paint) {
|
|
2812
|
+
function renderGeoMapViews(svg, layout, patterns, paint, ctx = createRenderContext()) {
|
|
2924
2813
|
const overlays = /* @__PURE__ */ new Map();
|
|
2925
2814
|
const inventory = [];
|
|
2926
2815
|
for (const view of layout.views ?? []) {
|
|
2927
2816
|
const frame = geoViewMapLayout(layout, view);
|
|
2928
|
-
const scene = element2(
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2817
|
+
const scene = element2(
|
|
2818
|
+
"g",
|
|
2819
|
+
{
|
|
2820
|
+
class: "oc-map-view",
|
|
2821
|
+
"data-geo-view-id": view.viewId,
|
|
2822
|
+
role: "group",
|
|
2823
|
+
"aria-label": view.coverage ?? view.viewId
|
|
2824
|
+
},
|
|
2825
|
+
ctx
|
|
2826
|
+
);
|
|
2934
2827
|
if (view.viewId !== "root") {
|
|
2935
2828
|
scene.appendChild(
|
|
2936
|
-
element2(
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2829
|
+
element2(
|
|
2830
|
+
"rect",
|
|
2831
|
+
{
|
|
2832
|
+
x: layout.area.x + view.frame.x,
|
|
2833
|
+
y: layout.area.y + view.frame.y,
|
|
2834
|
+
width: view.frame.width,
|
|
2835
|
+
height: view.frame.height,
|
|
2836
|
+
fill: resolvedSurface(layout.theme),
|
|
2837
|
+
stroke: layout.theme.colors.text,
|
|
2838
|
+
"stroke-opacity": 0.35,
|
|
2839
|
+
"stroke-width": 1
|
|
2840
|
+
},
|
|
2841
|
+
ctx
|
|
2842
|
+
)
|
|
2946
2843
|
);
|
|
2947
2844
|
if (view.label && view.labelBounds)
|
|
2948
2845
|
for (const line of view.label.lines) {
|
|
2949
|
-
const label = element2(
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2846
|
+
const label = element2(
|
|
2847
|
+
"text",
|
|
2848
|
+
{
|
|
2849
|
+
x: layout.area.x + view.labelBounds.x + line.x,
|
|
2850
|
+
y: layout.area.y + view.labelBounds.y + line.y,
|
|
2851
|
+
fill: line.style.fill,
|
|
2852
|
+
"font-family": line.style.fontFamily,
|
|
2853
|
+
"font-size": line.style.fontSize,
|
|
2854
|
+
"font-weight": line.style.fontWeight
|
|
2855
|
+
},
|
|
2856
|
+
ctx
|
|
2857
|
+
);
|
|
2957
2858
|
label.textContent = line.text;
|
|
2958
2859
|
scene.appendChild(label);
|
|
2959
2860
|
}
|
|
2960
2861
|
}
|
|
2961
|
-
const mapGroup = element2(
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2862
|
+
const mapGroup = element2(
|
|
2863
|
+
"g",
|
|
2864
|
+
{
|
|
2865
|
+
class: "oc-map-group",
|
|
2866
|
+
transform: `translate(${frame.area.x},${frame.area.y})`
|
|
2867
|
+
},
|
|
2868
|
+
ctx
|
|
2869
|
+
);
|
|
2870
|
+
const defs = element2("defs", void 0, ctx), clip = element2("clipPath", { id: ctx.ids.next("oc-map-view-clip") }, ctx);
|
|
2871
|
+
clip.appendChild(
|
|
2872
|
+
element2("rect", { width: view.viewport.width, height: view.viewport.height }, ctx)
|
|
2873
|
+
);
|
|
2967
2874
|
defs.appendChild(clip);
|
|
2968
2875
|
scene.appendChild(defs);
|
|
2969
2876
|
mapGroup.setAttribute("clip-path", `url(#${clip.id})`);
|
|
2970
2877
|
mapGroup.setAttribute("data-geo-view-clip", `url(#${clip.id})`);
|
|
2971
|
-
const camera = element2("g", { class: "oc-map-camera", "data-oc-map-camera": "" });
|
|
2878
|
+
const camera = element2("g", { class: "oc-map-camera", "data-oc-map-camera": "" }, ctx);
|
|
2972
2879
|
paint.features(camera, view.features, patterns);
|
|
2973
2880
|
for (const layer of view.detailLayers) {
|
|
2974
|
-
const detail = element2(
|
|
2975
|
-
"
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2881
|
+
const detail = element2(
|
|
2882
|
+
"g",
|
|
2883
|
+
{
|
|
2884
|
+
"data-geo-layer-id": layer.id,
|
|
2885
|
+
"data-min-zoom": layer.minZoom,
|
|
2886
|
+
...layer.maxZoom !== void 0 ? { "data-max-zoom": layer.maxZoom } : {},
|
|
2887
|
+
"pointer-events": "none",
|
|
2888
|
+
"aria-hidden": "true",
|
|
2889
|
+
fill: "none",
|
|
2890
|
+
stroke: view.borders.interiorStroke,
|
|
2891
|
+
"stroke-width": view.borders.interiorWidth
|
|
2892
|
+
},
|
|
2893
|
+
ctx
|
|
2894
|
+
);
|
|
2984
2895
|
for (const path of layer.paths)
|
|
2985
|
-
detail.appendChild(
|
|
2896
|
+
detail.appendChild(
|
|
2897
|
+
element2("path", { d: path, "vector-effect": "non-scaling-stroke" }, ctx)
|
|
2898
|
+
);
|
|
2986
2899
|
camera.appendChild(detail);
|
|
2987
2900
|
}
|
|
2988
2901
|
paint.borders(camera, view.borders);
|
|
@@ -2995,22 +2908,26 @@ function renderGeoMapViews(svg, layout, patterns, paint) {
|
|
|
2995
2908
|
applyGeoDetailVisibility(scene, current.k);
|
|
2996
2909
|
const overlay = resolveMapLabelOverlay(frame, current);
|
|
2997
2910
|
if (overlay) {
|
|
2998
|
-
renderGeoLabelOverlay(scene, frame, { ...overlay, notes: [] });
|
|
2911
|
+
renderGeoLabelOverlay(scene, frame, { ...overlay, notes: [] }, ctx);
|
|
2999
2912
|
overlays.set(view.viewId, overlay);
|
|
3000
2913
|
inventory.push(...overlay.inventory);
|
|
3001
2914
|
}
|
|
3002
2915
|
}
|
|
3003
|
-
renderGeoViewNotes(svg, layout, overlays);
|
|
2916
|
+
renderGeoViewNotes(svg, layout, overlays, ctx);
|
|
3004
2917
|
if (inventory.length)
|
|
3005
|
-
describeGeoLabelInventory(
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
2918
|
+
describeGeoLabelInventory(
|
|
2919
|
+
svg,
|
|
2920
|
+
{
|
|
2921
|
+
labels: [],
|
|
2922
|
+
leaders: [],
|
|
2923
|
+
markers: [],
|
|
2924
|
+
notes: [],
|
|
2925
|
+
inventory: mergeGeoLabelInventory(inventory)
|
|
2926
|
+
},
|
|
2927
|
+
ctx
|
|
2928
|
+
);
|
|
3012
2929
|
}
|
|
3013
|
-
function renderGeoViewNotes(svg, layout, overlays) {
|
|
2930
|
+
function renderGeoViewNotes(svg, layout, overlays, ctx = createRenderContext()) {
|
|
3014
2931
|
for (const node2 of svg.querySelectorAll(".oc-map-label-notes")) node2.remove();
|
|
3015
2932
|
const seen = /* @__PURE__ */ new Set();
|
|
3016
2933
|
for (const view of layout.views ?? []) {
|
|
@@ -3019,7 +2936,8 @@ function renderGeoViewNotes(svg, layout, overlays) {
|
|
|
3019
2936
|
seen.add(note.id);
|
|
3020
2937
|
return true;
|
|
3021
2938
|
});
|
|
3022
|
-
if (entries.length)
|
|
2939
|
+
if (entries.length)
|
|
2940
|
+
renderGeoLabelNotes(svg, geoViewMapLayout(layout, view), entries, void 0, ctx);
|
|
3023
2941
|
}
|
|
3024
2942
|
}
|
|
3025
2943
|
function applyGeoDetailVisibility(scene, k) {
|
|
@@ -3035,8 +2953,166 @@ function findGeoViewScene(svg, id) {
|
|
|
3035
2953
|
) ?? null;
|
|
3036
2954
|
}
|
|
3037
2955
|
|
|
2956
|
+
// src/map-color-key.ts
|
|
2957
|
+
import { buildD3Formatter, formatNumber } from "@opendata-ai/openchart-core";
|
|
2958
|
+
import { geoColorKeyPosition } from "@opendata-ai/openchart-engine";
|
|
2959
|
+
var node = (tag, attrs, content, ctx = createRenderContext()) => {
|
|
2960
|
+
const el = ctx.factory.svg(tag);
|
|
2961
|
+
for (const [key, value] of Object.entries(attrs)) el.setAttribute(key, String(value));
|
|
2962
|
+
if (content !== void 0) el.textContent = content;
|
|
2963
|
+
return el;
|
|
2964
|
+
};
|
|
2965
|
+
var text = (layout, x, y, value, ctx = createRenderContext()) => node(
|
|
2966
|
+
"text",
|
|
2967
|
+
{
|
|
2968
|
+
x,
|
|
2969
|
+
y,
|
|
2970
|
+
fill: layout.theme.colors.text,
|
|
2971
|
+
"font-family": layout.theme.fonts.family,
|
|
2972
|
+
"font-size": layout.theme.fonts.sizes.small
|
|
2973
|
+
},
|
|
2974
|
+
value,
|
|
2975
|
+
ctx
|
|
2976
|
+
);
|
|
2977
|
+
function renderStaticGeoColorKeys(svg, layout, ctx = createRenderContext()) {
|
|
2978
|
+
if (!layout.colorKeys) return;
|
|
2979
|
+
for (const [scope, key] of Object.entries(layout.colorKeys)) {
|
|
2980
|
+
const bounds = key?.distributionBounds;
|
|
2981
|
+
if (!key?.distribution || !bounds) continue;
|
|
2982
|
+
const group = node("g", { "data-geo-distribution": scope, role: "img" }, void 0, ctx);
|
|
2983
|
+
const line = Math.ceil(layout.theme.fonts.sizes.small * 1.4);
|
|
2984
|
+
const noun = scope === "features" ? "Regions" : "Points";
|
|
2985
|
+
group.append(
|
|
2986
|
+
text(layout, bounds.x, bounds.y + layout.theme.fonts.sizes.small, `${noun} per range`, ctx)
|
|
2987
|
+
);
|
|
2988
|
+
group.append(
|
|
2989
|
+
text(
|
|
2990
|
+
layout,
|
|
2991
|
+
bounds.x,
|
|
2992
|
+
bounds.y + line + layout.theme.fonts.sizes.small,
|
|
2993
|
+
`No data: ${key.missing}`,
|
|
2994
|
+
ctx
|
|
2995
|
+
)
|
|
2996
|
+
);
|
|
2997
|
+
const bars = key.kind === "categorical" ? key.categories.map((category, index) => ({
|
|
2998
|
+
count: category.count,
|
|
2999
|
+
color: category.color,
|
|
3000
|
+
label: category.value,
|
|
3001
|
+
x: bounds.x + index * bounds.width / Math.max(1, key.categories.length),
|
|
3002
|
+
width: bounds.width / Math.max(1, key.categories.length)
|
|
3003
|
+
})) : key.classes.map((bin, index) => ({
|
|
3004
|
+
...bin,
|
|
3005
|
+
x: bounds.x + index * bounds.width / Math.max(1, key.classes.length),
|
|
3006
|
+
width: bounds.width / Math.max(1, key.classes.length),
|
|
3007
|
+
label: `${bin.lower ?? "\u2212\u221E"} to ${bin.upper ?? "\u221E"}`
|
|
3008
|
+
}));
|
|
3009
|
+
const max = Math.max(1, ...bars.map((bar) => bar.count));
|
|
3010
|
+
const chartY = bounds.y + line * 2 + 4;
|
|
3011
|
+
for (const bar of bars) {
|
|
3012
|
+
const height = 20 * bar.count / max;
|
|
3013
|
+
const rectangle = node(
|
|
3014
|
+
"rect",
|
|
3015
|
+
{
|
|
3016
|
+
x: bar.x,
|
|
3017
|
+
y: chartY + 20 - height,
|
|
3018
|
+
width: Math.max(1, bar.width - 2),
|
|
3019
|
+
height,
|
|
3020
|
+
fill: bar.color
|
|
3021
|
+
},
|
|
3022
|
+
void 0,
|
|
3023
|
+
ctx
|
|
3024
|
+
);
|
|
3025
|
+
rectangle.append(node("title", {}, `${bar.label}: ${bar.count} ${noun.toLowerCase()}`, ctx));
|
|
3026
|
+
group.append(rectangle);
|
|
3027
|
+
const label = text(
|
|
3028
|
+
layout,
|
|
3029
|
+
bar.x + bar.width / 2,
|
|
3030
|
+
chartY + 20 + layout.theme.fonts.sizes.small,
|
|
3031
|
+
String(bar.count),
|
|
3032
|
+
ctx
|
|
3033
|
+
);
|
|
3034
|
+
label.setAttribute("text-anchor", "middle");
|
|
3035
|
+
group.append(label);
|
|
3036
|
+
}
|
|
3037
|
+
group.setAttribute(
|
|
3038
|
+
"aria-label",
|
|
3039
|
+
`${noun} per range. ${bars.map((bar) => `${bar.label}: ${bar.count}`).join("; ")}. No data: ${key.missing}.`
|
|
3040
|
+
);
|
|
3041
|
+
svg.append(group);
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
function renderActiveGeoColorKeys(parent, layout, index, selection, ctx = createRenderContext()) {
|
|
3045
|
+
if (!layout.colorKeys) return;
|
|
3046
|
+
const active = selection.pinned.length ? selection.pinned : selection.preview ? [selection.preview] : [];
|
|
3047
|
+
for (const [scope, key] of Object.entries(layout.colorKeys)) {
|
|
3048
|
+
if (!key?.activeValue) continue;
|
|
3049
|
+
for (const [slot, observation] of active.entries()) {
|
|
3050
|
+
if (scope === "features" !== (observation.entity.kind === "feature")) continue;
|
|
3051
|
+
const record = index.byObservation.get(observation.observation);
|
|
3052
|
+
const row = key.activeRows[slot];
|
|
3053
|
+
if (!record || !row) continue;
|
|
3054
|
+
const value = record.color?.value;
|
|
3055
|
+
const position = geoColorKeyPosition(key, value);
|
|
3056
|
+
const format = key.format ? buildD3Formatter(key.format) : void 0;
|
|
3057
|
+
const exact = typeof value === "number" ? format ? format(value) : formatNumber(value) : value === "" ? "(empty)" : String(value ?? "No data");
|
|
3058
|
+
const suffix = position.missing ? "No data" : `${exact}${position.outside ? " \xB7 outside displayed range" : ""}`;
|
|
3059
|
+
const lines = key.activeLabels?.[`${typeof value}:${String(value)}`] ?? [`A: ${suffix}`];
|
|
3060
|
+
const advance = Math.ceil(layout.theme.fonts.sizes.small * 1.4);
|
|
3061
|
+
for (const [lineIndex, line] of lines.entries()) {
|
|
3062
|
+
const label = text(
|
|
3063
|
+
layout,
|
|
3064
|
+
row.x,
|
|
3065
|
+
row.y + layout.theme.fonts.sizes.small + lineIndex * advance,
|
|
3066
|
+
lineIndex === 0 ? line.replace(/^A:/, `${slot === 0 ? "A" : "B"}:`) : line,
|
|
3067
|
+
ctx
|
|
3068
|
+
);
|
|
3069
|
+
label.setAttribute("data-geo-active-value", scope);
|
|
3070
|
+
if (key.kind === "binned") {
|
|
3071
|
+
const title = node(
|
|
3072
|
+
"title",
|
|
3073
|
+
{},
|
|
3074
|
+
`${suffix}; marker identifies the range containing this value`,
|
|
3075
|
+
ctx
|
|
3076
|
+
);
|
|
3077
|
+
label.append(title);
|
|
3078
|
+
}
|
|
3079
|
+
parent.append(label);
|
|
3080
|
+
}
|
|
3081
|
+
if (position.category !== void 0) {
|
|
3082
|
+
const category = key.categories.find((category2) => category2.value === position.category);
|
|
3083
|
+
if (category)
|
|
3084
|
+
parent.append(
|
|
3085
|
+
node(
|
|
3086
|
+
"rect",
|
|
3087
|
+
{
|
|
3088
|
+
...category.bounds,
|
|
3089
|
+
fill: "none",
|
|
3090
|
+
stroke: layout.theme.colors.text,
|
|
3091
|
+
"stroke-width": 2
|
|
3092
|
+
},
|
|
3093
|
+
void 0,
|
|
3094
|
+
ctx
|
|
3095
|
+
)
|
|
3096
|
+
);
|
|
3097
|
+
} else if (position.x !== void 0 && key.bar)
|
|
3098
|
+
parent.append(
|
|
3099
|
+
node(
|
|
3100
|
+
"path",
|
|
3101
|
+
{
|
|
3102
|
+
d: position.y === void 0 ? `M${position.x - 3},${key.bar.y - 4} L${position.x},${key.bar.y} L${position.x + 3},${key.bar.y - 4}` : `M${position.x - 14},${position.y - 3} L${position.x - 10},${position.y} L${position.x - 14},${position.y + 3}`,
|
|
3103
|
+
stroke: layout.theme.colors.text,
|
|
3104
|
+
"stroke-width": 2,
|
|
3105
|
+
fill: "none"
|
|
3106
|
+
},
|
|
3107
|
+
void 0,
|
|
3108
|
+
ctx
|
|
3109
|
+
)
|
|
3110
|
+
);
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3038
3115
|
// src/map-renderer.ts
|
|
3039
|
-
var SVG_NS4 = "http://www.w3.org/2000/svg";
|
|
3040
3116
|
var BULK_ANIMATION_THRESHOLD = 200;
|
|
3041
3117
|
var LEGEND_BACKDROP_ALPHA = 0.5;
|
|
3042
3118
|
function legendBackdrop(theme) {
|
|
@@ -3056,24 +3132,21 @@ function legendBackdrop(theme) {
|
|
|
3056
3132
|
}
|
|
3057
3133
|
return surface;
|
|
3058
3134
|
}
|
|
3059
|
-
function createSVGElement2(tag) {
|
|
3060
|
-
return document.createElementNS(SVG_NS4, tag);
|
|
3061
|
-
}
|
|
3062
3135
|
function setAttrs2(el, attrs) {
|
|
3063
3136
|
for (const [key, value] of Object.entries(attrs)) {
|
|
3064
3137
|
el.setAttribute(key, String(value));
|
|
3065
3138
|
}
|
|
3066
3139
|
}
|
|
3067
|
-
function renderChrome2(parent, layout) {
|
|
3068
|
-
const g =
|
|
3140
|
+
function renderChrome2(parent, layout, ctx = createRenderContext()) {
|
|
3141
|
+
const g = createSVGElement("g", ctx.factory);
|
|
3069
3142
|
g.setAttribute("class", "oc-chrome");
|
|
3070
3143
|
const { chrome, measureText } = layout;
|
|
3071
3144
|
const bottomOffset = chrome.bottomAnchorY ?? layout.area.y + layout.area.height;
|
|
3072
3145
|
if (chrome.title) {
|
|
3073
|
-
renderChromeElement(g, chrome.title, "oc-title", "title", measureText);
|
|
3146
|
+
renderChromeElement(g, chrome.title, "oc-title", "title", measureText, void 0, ctx);
|
|
3074
3147
|
}
|
|
3075
3148
|
if (chrome.subtitle) {
|
|
3076
|
-
renderChromeElement(g, chrome.subtitle, "oc-subtitle", "subtitle", measureText);
|
|
3149
|
+
renderChromeElement(g, chrome.subtitle, "oc-subtitle", "subtitle", measureText, void 0, ctx);
|
|
3077
3150
|
}
|
|
3078
3151
|
if (chrome.source) {
|
|
3079
3152
|
renderChromeElement(
|
|
@@ -3081,7 +3154,9 @@ function renderChrome2(parent, layout) {
|
|
|
3081
3154
|
{ ...chrome.source, y: bottomOffset + chrome.source.y },
|
|
3082
3155
|
"oc-source",
|
|
3083
3156
|
"source",
|
|
3084
|
-
measureText
|
|
3157
|
+
measureText,
|
|
3158
|
+
void 0,
|
|
3159
|
+
ctx
|
|
3085
3160
|
);
|
|
3086
3161
|
}
|
|
3087
3162
|
if (chrome.byline) {
|
|
@@ -3090,7 +3165,9 @@ function renderChrome2(parent, layout) {
|
|
|
3090
3165
|
{ ...chrome.byline, y: bottomOffset + chrome.byline.y },
|
|
3091
3166
|
"oc-byline",
|
|
3092
3167
|
"byline",
|
|
3093
|
-
measureText
|
|
3168
|
+
measureText,
|
|
3169
|
+
void 0,
|
|
3170
|
+
ctx
|
|
3094
3171
|
);
|
|
3095
3172
|
}
|
|
3096
3173
|
if (chrome.footer) {
|
|
@@ -3099,16 +3176,18 @@ function renderChrome2(parent, layout) {
|
|
|
3099
3176
|
{ ...chrome.footer, y: bottomOffset + chrome.footer.y },
|
|
3100
3177
|
"oc-footer",
|
|
3101
3178
|
"footer",
|
|
3102
|
-
measureText
|
|
3179
|
+
measureText,
|
|
3180
|
+
void 0,
|
|
3181
|
+
ctx
|
|
3103
3182
|
);
|
|
3104
3183
|
}
|
|
3105
3184
|
parent.appendChild(g);
|
|
3106
3185
|
}
|
|
3107
|
-
function renderBorders(parent, borders) {
|
|
3108
|
-
const g =
|
|
3186
|
+
function renderBorders(parent, borders, ctx = createRenderContext()) {
|
|
3187
|
+
const g = createSVGElement("g", ctx.factory);
|
|
3109
3188
|
g.setAttribute("class", "oc-map-borders");
|
|
3110
3189
|
if (borders.interiorPath) {
|
|
3111
|
-
const interior =
|
|
3190
|
+
const interior = createSVGElement("path", ctx.factory);
|
|
3112
3191
|
setAttrs2(interior, {
|
|
3113
3192
|
d: borders.interiorPath,
|
|
3114
3193
|
fill: "none",
|
|
@@ -3121,7 +3200,7 @@ function renderBorders(parent, borders) {
|
|
|
3121
3200
|
g.appendChild(interior);
|
|
3122
3201
|
}
|
|
3123
3202
|
if (borders.outlinePath) {
|
|
3124
|
-
const outline =
|
|
3203
|
+
const outline = createSVGElement("path", ctx.factory);
|
|
3125
3204
|
setAttrs2(outline, {
|
|
3126
3205
|
d: borders.outlinePath,
|
|
3127
3206
|
fill: "none",
|
|
@@ -3135,8 +3214,8 @@ function renderBorders(parent, borders) {
|
|
|
3135
3214
|
}
|
|
3136
3215
|
parent.appendChild(g);
|
|
3137
3216
|
}
|
|
3138
|
-
function renderFeatures(parent, features, animation, staggerBudget = 0, focusIds, patternMap) {
|
|
3139
|
-
const g =
|
|
3217
|
+
function renderFeatures(parent, features, animation, staggerBudget = 0, focusIds, patternMap, ctx = createRenderContext()) {
|
|
3218
|
+
const g = createSVGElement("g", ctx.factory);
|
|
3140
3219
|
g.setAttribute("class", "oc-map-features");
|
|
3141
3220
|
g.setAttribute("role", "list");
|
|
3142
3221
|
const bulk = features.length > BULK_ANIMATION_THRESHOLD;
|
|
@@ -3161,7 +3240,7 @@ function renderFeatures(parent, features, animation, staggerBudget = 0, focusIds
|
|
|
3161
3240
|
}
|
|
3162
3241
|
for (let i = 0; i < features.length; i++) {
|
|
3163
3242
|
const feature = features[i];
|
|
3164
|
-
const path =
|
|
3243
|
+
const path = createSVGElement("path", ctx.factory);
|
|
3165
3244
|
path.setAttribute("class", "oc-map-feature");
|
|
3166
3245
|
path.setAttribute("role", "listitem");
|
|
3167
3246
|
const fill = feature.pattern && patternMap ? resolvePatternFill(feature.pattern, patternMap) : feature.fill;
|
|
@@ -3206,12 +3285,12 @@ function renderFeatures(parent, features, animation, staggerBudget = 0, focusIds
|
|
|
3206
3285
|
}
|
|
3207
3286
|
parent.appendChild(g);
|
|
3208
3287
|
}
|
|
3209
|
-
function renderPointMarks(parent, points, animation) {
|
|
3288
|
+
function renderPointMarks(parent, points, animation, ctx = createRenderContext()) {
|
|
3210
3289
|
if (points.length === 0) return;
|
|
3211
|
-
const g =
|
|
3290
|
+
const g = createSVGElement("g", ctx.factory);
|
|
3212
3291
|
g.setAttribute("class", "oc-map-points");
|
|
3213
3292
|
for (const pt of points) {
|
|
3214
|
-
const circle =
|
|
3293
|
+
const circle = createSVGElement("circle", ctx.factory);
|
|
3215
3294
|
circle.setAttribute("class", "oc-map-point");
|
|
3216
3295
|
setAttrs2(circle, {
|
|
3217
3296
|
cx: pt.cx,
|
|
@@ -3238,9 +3317,10 @@ function renderPointMarks(parent, points, animation) {
|
|
|
3238
3317
|
parent.appendChild(g);
|
|
3239
3318
|
}
|
|
3240
3319
|
function renderMapSVG(layout, opts) {
|
|
3320
|
+
const ctx = opts?.context ?? createRenderContext();
|
|
3241
3321
|
const { width, height, features, borders, a11y, animation } = layout;
|
|
3242
3322
|
const animate = opts?.animate && !!animation?.enter;
|
|
3243
|
-
const svg =
|
|
3323
|
+
const svg = createSVGElement("svg", ctx.factory);
|
|
3244
3324
|
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
3245
3325
|
svg.setAttribute("role", "img");
|
|
3246
3326
|
if (a11y.altText) {
|
|
@@ -3249,7 +3329,7 @@ function renderMapSVG(layout, opts) {
|
|
|
3249
3329
|
const classes = animate ? "oc-map oc-animate" : "oc-map";
|
|
3250
3330
|
svg.setAttribute("class", classes);
|
|
3251
3331
|
stampThemeProperties(svg, layout.theme);
|
|
3252
|
-
const background =
|
|
3332
|
+
const background = createSVGElement("rect", ctx.factory);
|
|
3253
3333
|
setAttrs2(background, {
|
|
3254
3334
|
width,
|
|
3255
3335
|
height,
|
|
@@ -3275,18 +3355,28 @@ function renderMapSVG(layout, opts) {
|
|
|
3275
3355
|
ease: animation.enter.ease
|
|
3276
3356
|
});
|
|
3277
3357
|
}
|
|
3278
|
-
const defs =
|
|
3358
|
+
const defs = createSVGElement("defs", ctx.factory);
|
|
3279
3359
|
svg.appendChild(defs);
|
|
3280
3360
|
const noDataSwatch = layout.continuousLegend?.noData ?? layout.categoricalLegend?.noData;
|
|
3281
|
-
const patternMap = buildPatternDefs(
|
|
3361
|
+
const patternMap = buildPatternDefs(
|
|
3362
|
+
noDataSwatch ? [...features, noDataSwatch] : features,
|
|
3363
|
+
defs,
|
|
3364
|
+
ctx
|
|
3365
|
+
);
|
|
3282
3366
|
if (layout.views) {
|
|
3283
|
-
renderGeoMapViews(
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3367
|
+
renderGeoMapViews(
|
|
3368
|
+
svg,
|
|
3369
|
+
layout,
|
|
3370
|
+
patternMap,
|
|
3371
|
+
{
|
|
3372
|
+
features: (parent, marks, patterns) => renderFeatures(parent, marks, void 0, 0, void 0, patterns, ctx),
|
|
3373
|
+
borders: (parent, borders2) => renderBorders(parent, borders2, ctx),
|
|
3374
|
+
points: (parent, marks) => renderPointMarks(parent, marks, void 0, ctx)
|
|
3375
|
+
},
|
|
3376
|
+
ctx
|
|
3377
|
+
);
|
|
3288
3378
|
} else {
|
|
3289
|
-
const mapGroup =
|
|
3379
|
+
const mapGroup = createSVGElement("g", ctx.factory);
|
|
3290
3380
|
mapGroup.setAttribute("class", "oc-map-group");
|
|
3291
3381
|
mapGroup.setAttribute("transform", `translate(${layout.area.x},${layout.area.y})`);
|
|
3292
3382
|
const hasSideGutter = [
|
|
@@ -3299,16 +3389,16 @@ function renderMapSVG(layout, opts) {
|
|
|
3299
3389
|
(legend) => legend?.position === "right" || legend?.position === "bottom-right" && legend.bounds.x >= layout.area.x + layout.area.width
|
|
3300
3390
|
);
|
|
3301
3391
|
if (hasSideGutter) {
|
|
3302
|
-
const clipId =
|
|
3303
|
-
const clip =
|
|
3392
|
+
const clipId = ctx.ids.next("oc-map-viewport");
|
|
3393
|
+
const clip = createSVGElement("clipPath", ctx.factory);
|
|
3304
3394
|
clip.setAttribute("id", clipId);
|
|
3305
|
-
const rect =
|
|
3395
|
+
const rect = createSVGElement("rect", ctx.factory);
|
|
3306
3396
|
setAttrs2(rect, { x: 0, y: 0, width: layout.area.width, height: layout.area.height });
|
|
3307
3397
|
clip.appendChild(rect);
|
|
3308
3398
|
defs.appendChild(clip);
|
|
3309
3399
|
mapGroup.setAttribute("clip-path", `url(#${clipId})`);
|
|
3310
3400
|
}
|
|
3311
|
-
const cameraGroup =
|
|
3401
|
+
const cameraGroup = createSVGElement("g", ctx.factory);
|
|
3312
3402
|
cameraGroup.setAttribute("class", "oc-map-camera");
|
|
3313
3403
|
cameraGroup.setAttribute("data-oc-map-camera", "");
|
|
3314
3404
|
const focusIdSet = layout.focus && layout.focus.ids.length > 0 ? new Set(layout.focus.ids.map(String)) : void 0;
|
|
@@ -3318,19 +3408,20 @@ function renderMapSVG(layout, opts) {
|
|
|
3318
3408
|
animate ? animation : void 0,
|
|
3319
3409
|
mapStaggerBudget,
|
|
3320
3410
|
focusIdSet,
|
|
3321
|
-
patternMap
|
|
3411
|
+
patternMap,
|
|
3412
|
+
ctx
|
|
3322
3413
|
);
|
|
3323
|
-
renderBorders(cameraGroup, borders);
|
|
3414
|
+
renderBorders(cameraGroup, borders, ctx);
|
|
3324
3415
|
if (animate && animation?.enter && layout.pointMarks.length > 1) {
|
|
3325
3416
|
const pointStaggerBudget = animation.enter.duration * 0.5;
|
|
3326
3417
|
const perPoint = pointStaggerBudget / (layout.pointMarks.length - 1);
|
|
3327
3418
|
svg.style.setProperty("--oc-point-stagger", `${perPoint}ms`);
|
|
3328
3419
|
}
|
|
3329
|
-
renderPointMarks(cameraGroup, layout.pointMarks, animate ? animation : void 0);
|
|
3420
|
+
renderPointMarks(cameraGroup, layout.pointMarks, animate ? animation : void 0, ctx);
|
|
3330
3421
|
mapGroup.appendChild(cameraGroup);
|
|
3331
3422
|
svg.appendChild(mapGroup);
|
|
3332
3423
|
}
|
|
3333
|
-
renderChrome2(svg, layout);
|
|
3424
|
+
renderChrome2(svg, layout, ctx);
|
|
3334
3425
|
if (layout.continuousLegend) {
|
|
3335
3426
|
const contNoData = layout.continuousLegend.noData;
|
|
3336
3427
|
renderLegend(
|
|
@@ -3338,7 +3429,9 @@ function renderMapSVG(layout, opts) {
|
|
|
3338
3429
|
contNoData?.pattern ? {
|
|
3339
3430
|
...layout.continuousLegend,
|
|
3340
3431
|
noData: { ...contNoData, fill: resolvePatternFill(contNoData.pattern, patternMap) }
|
|
3341
|
-
} : layout.continuousLegend
|
|
3432
|
+
} : layout.continuousLegend,
|
|
3433
|
+
void 0,
|
|
3434
|
+
ctx
|
|
3342
3435
|
);
|
|
3343
3436
|
} else if (layout.categoricalLegend) {
|
|
3344
3437
|
const catNoData = layout.categoricalLegend.noData;
|
|
@@ -3347,13 +3440,15 @@ function renderMapSVG(layout, opts) {
|
|
|
3347
3440
|
catNoData?.pattern ? {
|
|
3348
3441
|
...layout.categoricalLegend,
|
|
3349
3442
|
noData: { ...catNoData, fill: resolvePatternFill(catNoData.pattern, patternMap) }
|
|
3350
|
-
} : layout.categoricalLegend
|
|
3443
|
+
} : layout.categoricalLegend,
|
|
3444
|
+
void 0,
|
|
3445
|
+
ctx
|
|
3351
3446
|
);
|
|
3352
3447
|
}
|
|
3353
3448
|
const ptLegend = layout.pointCategoricalLegend ?? layout.pointContinuousLegend;
|
|
3354
3449
|
if (ptLegend) {
|
|
3355
3450
|
if (ptLegend.position === "top-left") {
|
|
3356
|
-
const bg =
|
|
3451
|
+
const bg = createSVGElement("rect", ctx.factory);
|
|
3357
3452
|
setAttrs2(bg, {
|
|
3358
3453
|
x: ptLegend.bounds.x - 10,
|
|
3359
3454
|
y: ptLegend.bounds.y - 8,
|
|
@@ -3364,12 +3459,12 @@ function renderMapSVG(layout, opts) {
|
|
|
3364
3459
|
});
|
|
3365
3460
|
svg.appendChild(bg);
|
|
3366
3461
|
}
|
|
3367
|
-
renderLegend(svg, ptLegend);
|
|
3462
|
+
renderLegend(svg, ptLegend, void 0, ctx);
|
|
3368
3463
|
}
|
|
3369
3464
|
if (layout.pointSizeLegend) {
|
|
3370
3465
|
const sizeLegend = layout.pointSizeLegend;
|
|
3371
3466
|
const pad = 10;
|
|
3372
|
-
const bg =
|
|
3467
|
+
const bg = createSVGElement("rect", ctx.factory);
|
|
3373
3468
|
setAttrs2(bg, {
|
|
3374
3469
|
x: sizeLegend.bounds.x - pad,
|
|
3375
3470
|
y: sizeLegend.bounds.y - pad,
|
|
@@ -3380,31 +3475,29 @@ function renderMapSVG(layout, opts) {
|
|
|
3380
3475
|
});
|
|
3381
3476
|
if (sizeLegend.bounds.x < layout.area.x + layout.area.width && sizeLegend.bounds.y < layout.area.y + layout.area.height)
|
|
3382
3477
|
svg.appendChild(bg);
|
|
3383
|
-
renderLegend(svg, sizeLegend);
|
|
3478
|
+
renderLegend(svg, sizeLegend, void 0, ctx);
|
|
3384
3479
|
}
|
|
3385
3480
|
renderAttributionBrand(
|
|
3386
3481
|
svg,
|
|
3387
3482
|
layout.chrome,
|
|
3388
3483
|
layout.chrome.bottomAnchorY ?? layout.area.y + layout.area.height,
|
|
3389
|
-
layout.measureText
|
|
3484
|
+
layout.measureText,
|
|
3485
|
+
void 0,
|
|
3486
|
+
ctx
|
|
3390
3487
|
);
|
|
3391
3488
|
if (layout.labels && !layout.views) {
|
|
3392
3489
|
const overlay = resolveMapLabelOverlay(layout, cameraForTarget(layout, layout.focus?.target));
|
|
3393
3490
|
if (overlay) {
|
|
3394
|
-
renderGeoLabelOverlay(svg, layout, overlay);
|
|
3395
|
-
describeGeoLabelInventory(svg, overlay);
|
|
3491
|
+
renderGeoLabelOverlay(svg, layout, overlay, ctx);
|
|
3492
|
+
describeGeoLabelInventory(svg, overlay, ctx);
|
|
3396
3493
|
}
|
|
3397
3494
|
}
|
|
3398
|
-
renderStaticGeoColorKeys(svg, layout);
|
|
3495
|
+
renderStaticGeoColorKeys(svg, layout, ctx);
|
|
3399
3496
|
return svg;
|
|
3400
3497
|
}
|
|
3401
3498
|
|
|
3402
3499
|
export {
|
|
3403
3500
|
stampAnimationVars,
|
|
3404
|
-
captureSvgIdState,
|
|
3405
|
-
restoreSvgIdState,
|
|
3406
|
-
nextSvgId,
|
|
3407
|
-
resetSvgIdCounter,
|
|
3408
3501
|
buildGradientDefs,
|
|
3409
3502
|
resolveMarkFill,
|
|
3410
3503
|
updateAnnotationGeometry,
|
|
@@ -3451,4 +3544,4 @@ export {
|
|
|
3451
3544
|
renderActiveGeoColorKeys,
|
|
3452
3545
|
renderMapSVG
|
|
3453
3546
|
};
|
|
3454
|
-
//# sourceMappingURL=chunk-
|
|
3547
|
+
//# sourceMappingURL=chunk-NGNHQOXO.js.map
|