@opendata-ai/openchart-vanilla 9.0.0-rc.1 → 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-T6IPHUN4.js → chunk-42WVDS3V.js} +186 -38
- 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-ERPYVYFW.js → chunk-NGNHQOXO.js} +1065 -972
- 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/simulation-worker.js +26 -26
- 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-6YPRYQKD.js +0 -297
- package/dist/chunk-6YPRYQKD.js.map +0 -1
- package/dist/chunk-A5C4VCUO.js.map +0 -1
- package/dist/chunk-ERPYVYFW.js.map +0 -1
- package/dist/chunk-FFP5GXIP.js +0 -45
- package/dist/chunk-FFP5GXIP.js.map +0 -1
- package/dist/chunk-NLKQ5AOA.js.map +0 -1
- package/dist/chunk-T6IPHUN4.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
package/dist/index.js
CHANGED
|
@@ -3,16 +3,17 @@ import {
|
|
|
3
3
|
paletteFromCanvas,
|
|
4
4
|
readCanvasSRGB,
|
|
5
5
|
resolveRepeat
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RWP23N4D.js";
|
|
7
7
|
import {
|
|
8
|
+
renderBarListSVG,
|
|
8
9
|
renderTileMapSVG
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-SKQAAHHR.js";
|
|
10
11
|
import {
|
|
11
12
|
GRAPH_3D_NOT_REGISTERED_ERROR,
|
|
12
13
|
createAttributionFooter,
|
|
13
14
|
createGraph,
|
|
14
15
|
registerGraphRenderer
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-HQ5GADZ4.js";
|
|
16
17
|
import {
|
|
17
18
|
CANVAS_DEFAULT_UPDATE_MAX_MARKS,
|
|
18
19
|
DEFAULT_UPDATE_MAX_MARKS,
|
|
@@ -34,7 +35,7 @@ import {
|
|
|
34
35
|
setupAnimationCleanup,
|
|
35
36
|
setupTableAnimationCleanup,
|
|
36
37
|
wireMarkNavigation
|
|
37
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-42WVDS3V.js";
|
|
38
39
|
import {
|
|
39
40
|
embedFonts,
|
|
40
41
|
ensureSVGDimensions,
|
|
@@ -46,192 +47,40 @@ import {
|
|
|
46
47
|
getSVGBackgroundColor,
|
|
47
48
|
getSVGDimensions,
|
|
48
49
|
rasterizeSVGToCanvas
|
|
49
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-OEJHSKFZ.js";
|
|
50
51
|
import {
|
|
51
52
|
applySrOnlyStyles,
|
|
52
53
|
geoViewMapLayout,
|
|
53
54
|
mapLabelAffine,
|
|
54
|
-
nextSvgId,
|
|
55
55
|
rectPathWithCorners,
|
|
56
56
|
registerMarkRenderer,
|
|
57
57
|
renderActiveGeoColorKeys,
|
|
58
58
|
renderChartSVG,
|
|
59
59
|
stampAnimationVars
|
|
60
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-NGNHQOXO.js";
|
|
61
61
|
import {
|
|
62
62
|
injectThemeStyleBlock,
|
|
63
63
|
prepareSettledExportTheme
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-7XFFPRQ7.js";
|
|
65
65
|
import {
|
|
66
66
|
createTooltipManager,
|
|
67
67
|
observeResize,
|
|
68
68
|
resolveDarkMode
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-6GRMMSQA.js";
|
|
70
70
|
import {
|
|
71
|
+
createIdScope,
|
|
72
|
+
createRenderContext,
|
|
73
|
+
pageIdScope,
|
|
71
74
|
renderAttributionBrand,
|
|
72
75
|
renderChromeElement,
|
|
73
76
|
stampThemeProperties
|
|
74
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-XR4B3SPC.js";
|
|
75
78
|
import {
|
|
76
79
|
applyTextStyle
|
|
77
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-E3ETKTJQ.js";
|
|
78
81
|
|
|
79
82
|
// src/barlist-mount.ts
|
|
80
83
|
import { compileBarList } from "@opendata-ai/openchart-engine";
|
|
81
|
-
|
|
82
|
-
// src/barlist-renderer.ts
|
|
83
|
-
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
84
|
-
function createSVGElement(tag) {
|
|
85
|
-
return document.createElementNS(SVG_NS, tag);
|
|
86
|
-
}
|
|
87
|
-
function setAttrs(el, attrs) {
|
|
88
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
89
|
-
el.setAttribute(key, String(value));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function renderChrome(parent, layout) {
|
|
93
|
-
const g = createSVGElement("g");
|
|
94
|
-
g.setAttribute("class", "oc-chrome");
|
|
95
|
-
const { chrome } = layout;
|
|
96
|
-
const bottomOffset = layout.area.y + layout.area.height;
|
|
97
|
-
for (const key of ["title", "subtitle", "source", "byline", "footer"]) {
|
|
98
|
-
const el = chrome[key];
|
|
99
|
-
if (!el) continue;
|
|
100
|
-
const isBottom = key === "source" || key === "byline" || key === "footer";
|
|
101
|
-
renderChromeElement(
|
|
102
|
-
g,
|
|
103
|
-
isBottom ? { ...el, y: bottomOffset + el.y } : el,
|
|
104
|
-
`oc-${key}`,
|
|
105
|
-
key,
|
|
106
|
-
layout.measureText
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
parent.appendChild(g);
|
|
110
|
-
}
|
|
111
|
-
function renderRows(parent, rows, animation) {
|
|
112
|
-
const g = createSVGElement("g");
|
|
113
|
-
g.setAttribute("class", "oc-barlist-rows");
|
|
114
|
-
g.setAttribute("role", "list");
|
|
115
|
-
for (const row of rows) {
|
|
116
|
-
const rowGroup = createSVGElement("g");
|
|
117
|
-
rowGroup.setAttribute("class", "oc-barlist-row");
|
|
118
|
-
rowGroup.setAttribute("data-row-index", String(row.index));
|
|
119
|
-
rowGroup.setAttribute("role", "listitem");
|
|
120
|
-
if (row.aria?.label) {
|
|
121
|
-
rowGroup.setAttribute("aria-label", row.aria.label);
|
|
122
|
-
}
|
|
123
|
-
if (animation?.enter) {
|
|
124
|
-
rowGroup.setAttribute("data-animation-index", String(row.animationIndex));
|
|
125
|
-
const style = rowGroup.style;
|
|
126
|
-
style.setProperty("--oc-mark-index", String(row.animationIndex));
|
|
127
|
-
style.setProperty("--oc-row-delay", `${row.animationIndex * 40}ms`);
|
|
128
|
-
}
|
|
129
|
-
const labelEl = createSVGElement("text");
|
|
130
|
-
setAttrs(labelEl, {
|
|
131
|
-
x: row.label.x,
|
|
132
|
-
y: row.label.y,
|
|
133
|
-
"dominant-baseline": "central",
|
|
134
|
-
"text-anchor": "start",
|
|
135
|
-
"font-family": row.label.style.fontFamily,
|
|
136
|
-
"font-size": row.label.style.fontSize,
|
|
137
|
-
"font-weight": row.label.style.fontWeight
|
|
138
|
-
});
|
|
139
|
-
labelEl.style.setProperty("fill", row.label.style.fill);
|
|
140
|
-
labelEl.textContent = row.label.text;
|
|
141
|
-
rowGroup.appendChild(labelEl);
|
|
142
|
-
if (row.subtitle?.visible) {
|
|
143
|
-
const subEl = createSVGElement("text");
|
|
144
|
-
setAttrs(subEl, {
|
|
145
|
-
x: row.subtitle.x,
|
|
146
|
-
y: row.subtitle.y,
|
|
147
|
-
"dominant-baseline": "central",
|
|
148
|
-
"text-anchor": "start",
|
|
149
|
-
"font-family": row.subtitle.style.fontFamily,
|
|
150
|
-
"font-size": row.subtitle.style.fontSize,
|
|
151
|
-
"font-weight": row.subtitle.style.fontWeight
|
|
152
|
-
});
|
|
153
|
-
subEl.style.setProperty(
|
|
154
|
-
"fill",
|
|
155
|
-
row.subtitle.style.fill
|
|
156
|
-
);
|
|
157
|
-
subEl.textContent = row.subtitle.text;
|
|
158
|
-
rowGroup.appendChild(subEl);
|
|
159
|
-
}
|
|
160
|
-
const trackRect = createSVGElement("rect");
|
|
161
|
-
setAttrs(trackRect, {
|
|
162
|
-
x: row.track.x,
|
|
163
|
-
y: row.track.y,
|
|
164
|
-
width: row.track.width,
|
|
165
|
-
height: row.track.height,
|
|
166
|
-
rx: row.track.cornerRadius,
|
|
167
|
-
fill: "currentColor",
|
|
168
|
-
"fill-opacity": 0.06
|
|
169
|
-
});
|
|
170
|
-
trackRect.setAttribute("class", "oc-barlist-track");
|
|
171
|
-
rowGroup.appendChild(trackRect);
|
|
172
|
-
const barRect = createSVGElement("rect");
|
|
173
|
-
setAttrs(barRect, {
|
|
174
|
-
x: row.bar.x,
|
|
175
|
-
y: row.bar.y,
|
|
176
|
-
width: row.bar.width,
|
|
177
|
-
height: row.bar.height,
|
|
178
|
-
rx: row.bar.cornerRadius,
|
|
179
|
-
fill: row.bar.fill
|
|
180
|
-
});
|
|
181
|
-
barRect.setAttribute("class", "oc-barlist-bar");
|
|
182
|
-
rowGroup.appendChild(barRect);
|
|
183
|
-
const valueEl = createSVGElement("text");
|
|
184
|
-
setAttrs(valueEl, {
|
|
185
|
-
x: row.valueLabel.x,
|
|
186
|
-
y: row.valueLabel.y,
|
|
187
|
-
"dominant-baseline": "central",
|
|
188
|
-
"text-anchor": "end",
|
|
189
|
-
"font-family": row.valueLabel.style.fontFamily,
|
|
190
|
-
"font-size": row.valueLabel.style.fontSize,
|
|
191
|
-
"font-weight": row.valueLabel.style.fontWeight
|
|
192
|
-
});
|
|
193
|
-
valueEl.style.setProperty(
|
|
194
|
-
"fill",
|
|
195
|
-
row.valueLabel.style.fill
|
|
196
|
-
);
|
|
197
|
-
valueEl.textContent = row.valueLabel.text;
|
|
198
|
-
rowGroup.appendChild(valueEl);
|
|
199
|
-
g.appendChild(rowGroup);
|
|
200
|
-
}
|
|
201
|
-
parent.appendChild(g);
|
|
202
|
-
}
|
|
203
|
-
function renderBarListSVG(layout, opts) {
|
|
204
|
-
const { width, height, rows, a11y, animation } = layout;
|
|
205
|
-
const animate = opts?.animate && !!animation?.enter;
|
|
206
|
-
const svg = createSVGElement("svg");
|
|
207
|
-
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
208
|
-
svg.setAttribute("role", "list");
|
|
209
|
-
svg.style.height = `${height}px`;
|
|
210
|
-
if (a11y.altText) {
|
|
211
|
-
svg.setAttribute("aria-label", a11y.altText);
|
|
212
|
-
}
|
|
213
|
-
const classes = animate ? "oc-barlist oc-animate" : "oc-barlist";
|
|
214
|
-
svg.setAttribute("class", classes);
|
|
215
|
-
stampThemeProperties(svg, layout.theme);
|
|
216
|
-
if (animate && animation?.enter) {
|
|
217
|
-
stampAnimationVars(svg, {
|
|
218
|
-
duration: animation.enter.duration,
|
|
219
|
-
spring: animation.enter.spring,
|
|
220
|
-
stagger: 40
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
renderChrome(svg, layout);
|
|
224
|
-
renderRows(svg, rows, animate ? animation : void 0);
|
|
225
|
-
renderAttributionBrand(
|
|
226
|
-
svg,
|
|
227
|
-
layout.chrome,
|
|
228
|
-
layout.chrome.bottomAnchorY ?? layout.area.y + layout.area.height,
|
|
229
|
-
layout.measureText
|
|
230
|
-
);
|
|
231
|
-
return svg;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// src/barlist-mount.ts
|
|
235
84
|
function createBarList(container, spec, options) {
|
|
236
85
|
let currentSpec = spec;
|
|
237
86
|
let currentLayout;
|
|
@@ -349,7 +198,7 @@ function createBarList(container, spec, options) {
|
|
|
349
198
|
el.removeEventListener("click", handleClick);
|
|
350
199
|
});
|
|
351
200
|
}
|
|
352
|
-
cleanups.push(wireMarkNavigation(svg, navigation));
|
|
201
|
+
if (!layout.a11y.hidden) cleanups.push(wireMarkNavigation(svg, navigation));
|
|
353
202
|
return () => {
|
|
354
203
|
activeLeave?.();
|
|
355
204
|
for (const cleanup of cleanups) cleanup();
|
|
@@ -369,7 +218,10 @@ function createBarList(container, spec, options) {
|
|
|
369
218
|
}
|
|
370
219
|
svgElement.remove();
|
|
371
220
|
}
|
|
372
|
-
const newSvg = renderBarListSVG(currentLayout, {
|
|
221
|
+
const newSvg = renderBarListSVG(currentLayout, {
|
|
222
|
+
context: createRenderContext({ ids: pageIdScope }),
|
|
223
|
+
animate
|
|
224
|
+
});
|
|
373
225
|
container.appendChild(newSvg);
|
|
374
226
|
svgElement = newSvg;
|
|
375
227
|
cleanupTooltipEvents = wireTooltipAndInteraction(newSvg, currentLayout);
|
|
@@ -417,7 +269,10 @@ function createBarList(container, spec, options) {
|
|
|
417
269
|
}
|
|
418
270
|
function exportChart(format, options_) {
|
|
419
271
|
if (!svgElement) return "";
|
|
420
|
-
const terminalSvg = renderBarListSVG(currentLayout, {
|
|
272
|
+
const terminalSvg = renderBarListSVG(currentLayout, {
|
|
273
|
+
context: createRenderContext({ ids: pageIdScope }),
|
|
274
|
+
animate: false
|
|
275
|
+
});
|
|
421
276
|
const resolvedOptions = { theme: currentLayout.theme, ...options_ };
|
|
422
277
|
prepareSettledExportTheme(svgElement, terminalSvg, resolvedOptions.theme, !!options_?.theme);
|
|
423
278
|
switch (format) {
|
|
@@ -766,7 +621,7 @@ function createMapCompanion(actions) {
|
|
|
766
621
|
|
|
767
622
|
// src/map-reader-overlays.ts
|
|
768
623
|
var NS = "http://www.w3.org/2000/svg";
|
|
769
|
-
function renderMapReaderOverlay(svg, layout, camera, index, selection, getCamera) {
|
|
624
|
+
function renderMapReaderOverlay(svg, layout, camera, index, selection, getCamera, ctx = createRenderContext()) {
|
|
770
625
|
svg.querySelector("[data-oc-reader-overlay]")?.remove();
|
|
771
626
|
const group = document.createElementNS(NS, "g");
|
|
772
627
|
group.setAttribute("data-oc-reader-overlay", "");
|
|
@@ -774,7 +629,7 @@ function renderMapReaderOverlay(svg, layout, camera, index, selection, getCamera
|
|
|
774
629
|
group.setAttribute("aria-hidden", "true");
|
|
775
630
|
for (const view of layout.views ?? [void 0]) {
|
|
776
631
|
const frame = view ? geoViewMapLayout(layout, view) : layout;
|
|
777
|
-
const clipId =
|
|
632
|
+
const clipId = ctx.ids.next("oc-reader-clip");
|
|
778
633
|
const clip = document.createElementNS(NS, "clipPath");
|
|
779
634
|
clip.id = clipId;
|
|
780
635
|
const rect = document.createElementNS(NS, "rect");
|
|
@@ -2941,11 +2796,11 @@ import { compileSankey } from "@opendata-ai/openchart-engine";
|
|
|
2941
2796
|
// src/sankey-renderer.ts
|
|
2942
2797
|
import { estimateTextWidth, wrapText } from "@opendata-ai/openchart-core";
|
|
2943
2798
|
import { clampStaggerDelay } from "@opendata-ai/openchart-engine";
|
|
2944
|
-
var
|
|
2945
|
-
function
|
|
2946
|
-
return document.createElementNS(
|
|
2799
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
2800
|
+
function createSVGElement(tag) {
|
|
2801
|
+
return document.createElementNS(SVG_NS, tag);
|
|
2947
2802
|
}
|
|
2948
|
-
function
|
|
2803
|
+
function setAttrs(el, attrs) {
|
|
2949
2804
|
for (const [key, value] of Object.entries(attrs)) {
|
|
2950
2805
|
el.setAttribute(key, String(value));
|
|
2951
2806
|
}
|
|
@@ -2956,8 +2811,8 @@ function stampAnimationAttrs(el, mark, fallbackIndex, animation) {
|
|
|
2956
2811
|
el.setAttribute("data-animation-index", String(idx));
|
|
2957
2812
|
el.style.setProperty("--oc-mark-index", String(idx));
|
|
2958
2813
|
}
|
|
2959
|
-
function
|
|
2960
|
-
const g =
|
|
2814
|
+
function renderChrome(parent, layout) {
|
|
2815
|
+
const g = createSVGElement("g");
|
|
2961
2816
|
g.setAttribute("class", "oc-chrome");
|
|
2962
2817
|
const { chrome, measureText } = layout;
|
|
2963
2818
|
if (chrome.title) {
|
|
@@ -2999,7 +2854,7 @@ function renderChrome2(parent, layout) {
|
|
|
2999
2854
|
function renderLegend(parent, legendLayout) {
|
|
3000
2855
|
if (!("entries" in legendLayout) || legendLayout.entries.length === 0) return;
|
|
3001
2856
|
const legend = legendLayout;
|
|
3002
|
-
const g =
|
|
2857
|
+
const g = createSVGElement("g");
|
|
3003
2858
|
g.setAttribute("class", "oc-legend");
|
|
3004
2859
|
g.setAttribute("role", "list");
|
|
3005
2860
|
g.setAttribute("aria-label", "Chart legend");
|
|
@@ -3020,7 +2875,7 @@ function renderLegend(parent, legendLayout) {
|
|
|
3020
2875
|
offsetY += legend.swatchSize + 6;
|
|
3021
2876
|
}
|
|
3022
2877
|
}
|
|
3023
|
-
const entryG =
|
|
2878
|
+
const entryG = createSVGElement("g");
|
|
3024
2879
|
entryG.setAttribute("class", "oc-legend-entry");
|
|
3025
2880
|
entryG.setAttribute("role", "listitem");
|
|
3026
2881
|
entryG.setAttribute("data-legend-index", String(i));
|
|
@@ -3039,8 +2894,8 @@ function renderLegend(parent, legendLayout) {
|
|
|
3039
2894
|
entryG.setAttribute("opacity", "0.3");
|
|
3040
2895
|
}
|
|
3041
2896
|
}
|
|
3042
|
-
const rect =
|
|
3043
|
-
|
|
2897
|
+
const rect = createSVGElement("rect");
|
|
2898
|
+
setAttrs(rect, {
|
|
3044
2899
|
x: offsetX,
|
|
3045
2900
|
y: offsetY,
|
|
3046
2901
|
width: legend.swatchSize,
|
|
@@ -3049,8 +2904,8 @@ function renderLegend(parent, legendLayout) {
|
|
|
3049
2904
|
rx: 2
|
|
3050
2905
|
});
|
|
3051
2906
|
entryG.appendChild(rect);
|
|
3052
|
-
const label =
|
|
3053
|
-
|
|
2907
|
+
const label = createSVGElement("text");
|
|
2908
|
+
setAttrs(label, {
|
|
3054
2909
|
x: offsetX + legend.swatchSize + legend.swatchGap,
|
|
3055
2910
|
y: offsetY + legend.swatchSize / 2,
|
|
3056
2911
|
"dominant-baseline": "central"
|
|
@@ -3083,12 +2938,12 @@ function buildNodePositionMap(nodes) {
|
|
|
3083
2938
|
function sanitizeId(s) {
|
|
3084
2939
|
return s.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3085
2940
|
}
|
|
3086
|
-
function renderGradientDefs(defs, links, nodePositions) {
|
|
2941
|
+
function renderGradientDefs(defs, links, nodePositions, gradientIds) {
|
|
3087
2942
|
for (let i = 0; i < links.length; i++) {
|
|
3088
2943
|
const link = links[i];
|
|
3089
2944
|
if (link.sourceColor === link.targetColor) continue;
|
|
3090
|
-
const gradId =
|
|
3091
|
-
const gradient =
|
|
2945
|
+
const gradId = gradientIds.get(i);
|
|
2946
|
+
const gradient = createSVGElement("linearGradient");
|
|
3092
2947
|
gradient.setAttribute("id", gradId);
|
|
3093
2948
|
gradient.setAttribute("gradientUnits", "userSpaceOnUse");
|
|
3094
2949
|
const sourcePos = nodePositions.get(link.sourceId);
|
|
@@ -3097,21 +2952,21 @@ function renderGradientDefs(defs, links, nodePositions) {
|
|
|
3097
2952
|
const x2 = targetPos ? targetPos.x : 0;
|
|
3098
2953
|
gradient.setAttribute("x1", String(x1));
|
|
3099
2954
|
gradient.setAttribute("x2", String(x2));
|
|
3100
|
-
const stop0 =
|
|
3101
|
-
|
|
2955
|
+
const stop0 = createSVGElement("stop");
|
|
2956
|
+
setAttrs(stop0, { offset: "0%", "stop-color": link.sourceColor });
|
|
3102
2957
|
gradient.appendChild(stop0);
|
|
3103
|
-
const stop1 =
|
|
3104
|
-
|
|
2958
|
+
const stop1 = createSVGElement("stop");
|
|
2959
|
+
setAttrs(stop1, { offset: "100%", "stop-color": link.targetColor });
|
|
3105
2960
|
gradient.appendChild(stop1);
|
|
3106
2961
|
defs.appendChild(gradient);
|
|
3107
2962
|
}
|
|
3108
2963
|
}
|
|
3109
|
-
function renderLinks(parent, links, _nodePositions, animation) {
|
|
3110
|
-
const g =
|
|
2964
|
+
function renderLinks(parent, links, _nodePositions, animation, gradientIds) {
|
|
2965
|
+
const g = createSVGElement("g");
|
|
3111
2966
|
g.setAttribute("class", "oc-sankey-links");
|
|
3112
2967
|
for (let i = 0; i < links.length; i++) {
|
|
3113
2968
|
const link = links[i];
|
|
3114
|
-
const linkG =
|
|
2969
|
+
const linkG = createSVGElement("g");
|
|
3115
2970
|
linkG.setAttribute("class", "oc-sankey-link");
|
|
3116
2971
|
linkG.setAttribute("data-mark-id", `link-${link.sourceId}-${link.targetId}-${i}`);
|
|
3117
2972
|
linkG.setAttribute("data-source", link.sourceId);
|
|
@@ -3120,12 +2975,12 @@ function renderLinks(parent, links, _nodePositions, animation) {
|
|
|
3120
2975
|
linkG.setAttribute("aria-label", link.aria.label);
|
|
3121
2976
|
}
|
|
3122
2977
|
stampAnimationAttrs(linkG, link, i, animation);
|
|
3123
|
-
const path =
|
|
2978
|
+
const path = createSVGElement("path");
|
|
3124
2979
|
path.setAttribute("d", link.path);
|
|
3125
2980
|
path.setAttribute("stroke", "none");
|
|
3126
2981
|
path.setAttribute("fill-opacity", String(link.fillOpacity));
|
|
3127
2982
|
if (link.sourceColor !== link.targetColor) {
|
|
3128
|
-
const gradId =
|
|
2983
|
+
const gradId = gradientIds.get(i);
|
|
3129
2984
|
path.setAttribute("fill", `url(#${gradId})`);
|
|
3130
2985
|
} else {
|
|
3131
2986
|
path.setAttribute("fill", link.sourceColor);
|
|
@@ -3136,11 +2991,11 @@ function renderLinks(parent, links, _nodePositions, animation) {
|
|
|
3136
2991
|
parent.appendChild(g);
|
|
3137
2992
|
}
|
|
3138
2993
|
function renderNodes(parent, nodes, animation) {
|
|
3139
|
-
const g =
|
|
2994
|
+
const g = createSVGElement("g");
|
|
3140
2995
|
g.setAttribute("class", "oc-sankey-nodes");
|
|
3141
2996
|
for (let i = 0; i < nodes.length; i++) {
|
|
3142
2997
|
const node = nodes[i];
|
|
3143
|
-
const nodeG =
|
|
2998
|
+
const nodeG = createSVGElement("g");
|
|
3144
2999
|
nodeG.setAttribute("class", "oc-sankey-node");
|
|
3145
3000
|
nodeG.setAttribute("data-mark-id", `node-${node.nodeId}`);
|
|
3146
3001
|
nodeG.setAttribute("data-node-id", node.nodeId);
|
|
@@ -3148,8 +3003,8 @@ function renderNodes(parent, nodes, animation) {
|
|
|
3148
3003
|
nodeG.setAttribute("aria-label", node.aria.label);
|
|
3149
3004
|
}
|
|
3150
3005
|
stampAnimationAttrs(nodeG, node, i, animation);
|
|
3151
|
-
const rect =
|
|
3152
|
-
|
|
3006
|
+
const rect = createSVGElement("rect");
|
|
3007
|
+
setAttrs(rect, {
|
|
3153
3008
|
x: node.x,
|
|
3154
3009
|
y: node.y,
|
|
3155
3010
|
width: node.width,
|
|
@@ -3170,13 +3025,13 @@ function renderNodes(parent, nodes, animation) {
|
|
|
3170
3025
|
parent.appendChild(g);
|
|
3171
3026
|
}
|
|
3172
3027
|
function renderLabels(parent, nodes, measureText) {
|
|
3173
|
-
const g =
|
|
3028
|
+
const g = createSVGElement("g");
|
|
3174
3029
|
g.setAttribute("class", "oc-sankey-labels");
|
|
3175
3030
|
for (const node of nodes) {
|
|
3176
3031
|
const { label } = node;
|
|
3177
3032
|
if (!label.visible) continue;
|
|
3178
|
-
const text =
|
|
3179
|
-
|
|
3033
|
+
const text = createSVGElement("text");
|
|
3034
|
+
setAttrs(text, { x: label.x, y: label.y });
|
|
3180
3035
|
applyTextStyle(text, label.style);
|
|
3181
3036
|
text.setAttribute("class", "oc-sankey-label");
|
|
3182
3037
|
text.setAttribute("data-node-id", node.nodeId);
|
|
@@ -3191,7 +3046,7 @@ function renderLabels(parent, nodes, measureText) {
|
|
|
3191
3046
|
const totalHeight = (lines.length - 1) * lineHeight;
|
|
3192
3047
|
const startY = label.y - totalHeight / 2;
|
|
3193
3048
|
for (let i = 0; i < lines.length; i++) {
|
|
3194
|
-
const tspan =
|
|
3049
|
+
const tspan = createSVGElement("tspan");
|
|
3195
3050
|
tspan.setAttribute("x", String(label.x));
|
|
3196
3051
|
tspan.setAttribute("y", String(startY + i * lineHeight));
|
|
3197
3052
|
tspan.textContent = lines[i];
|
|
@@ -3202,12 +3057,12 @@ function renderLabels(parent, nodes, measureText) {
|
|
|
3202
3057
|
}
|
|
3203
3058
|
if (node.valueLabel) {
|
|
3204
3059
|
if (text.childNodes.length === 0) {
|
|
3205
|
-
const nameSpan =
|
|
3060
|
+
const nameSpan = createSVGElement("tspan");
|
|
3206
3061
|
nameSpan.textContent = text.textContent;
|
|
3207
3062
|
text.textContent = "";
|
|
3208
3063
|
text.appendChild(nameSpan);
|
|
3209
3064
|
}
|
|
3210
|
-
const valueSpan =
|
|
3065
|
+
const valueSpan = createSVGElement("tspan");
|
|
3211
3066
|
valueSpan.setAttribute("class", "oc-sankey-label-value");
|
|
3212
3067
|
valueSpan.setAttribute("dx", "5");
|
|
3213
3068
|
applyTextStyle(valueSpan, node.valueLabel.style);
|
|
@@ -3218,12 +3073,12 @@ function renderLabels(parent, nodes, measureText) {
|
|
|
3218
3073
|
}
|
|
3219
3074
|
parent.appendChild(g);
|
|
3220
3075
|
}
|
|
3221
|
-
function renderSankeySVG(layout, animation) {
|
|
3076
|
+
function renderSankeySVG(layout, animation, ctx = createRenderContext()) {
|
|
3222
3077
|
const { width, height } = layout.dimensions;
|
|
3223
|
-
const svg =
|
|
3224
|
-
|
|
3078
|
+
const svg = createSVGElement("svg");
|
|
3079
|
+
setAttrs(svg, {
|
|
3225
3080
|
viewBox: `0 0 ${width} ${height}`,
|
|
3226
|
-
xmlns:
|
|
3081
|
+
xmlns: SVG_NS,
|
|
3227
3082
|
overflow: "visible"
|
|
3228
3083
|
});
|
|
3229
3084
|
svg.style.height = `${height}px`;
|
|
@@ -3245,9 +3100,9 @@ function renderSankeySVG(layout, animation) {
|
|
|
3245
3100
|
ease: enterPhase.ease
|
|
3246
3101
|
});
|
|
3247
3102
|
}
|
|
3248
|
-
const bg =
|
|
3103
|
+
const bg = createSVGElement("rect");
|
|
3249
3104
|
bg.setAttribute("class", "oc-background");
|
|
3250
|
-
|
|
3105
|
+
setAttrs(bg, {
|
|
3251
3106
|
x: 0,
|
|
3252
3107
|
y: 0,
|
|
3253
3108
|
width,
|
|
@@ -3256,14 +3111,20 @@ function renderSankeySVG(layout, animation) {
|
|
|
3256
3111
|
});
|
|
3257
3112
|
svg.appendChild(bg);
|
|
3258
3113
|
const nodePositions = buildNodePositionMap(layout.nodes);
|
|
3259
|
-
const defs =
|
|
3260
|
-
|
|
3114
|
+
const defs = createSVGElement("defs");
|
|
3115
|
+
const gradientIds = new Map(
|
|
3116
|
+
layout.links.map((link, i) => [
|
|
3117
|
+
i,
|
|
3118
|
+
ctx.ids.next(`oc-sg-${sanitizeId(link.sourceId)}-${sanitizeId(link.targetId)}`)
|
|
3119
|
+
])
|
|
3120
|
+
);
|
|
3121
|
+
renderGradientDefs(defs, layout.links, nodePositions, gradientIds);
|
|
3261
3122
|
svg.appendChild(defs);
|
|
3262
|
-
renderLinks(svg, layout.links, nodePositions, animation);
|
|
3123
|
+
renderLinks(svg, layout.links, nodePositions, animation, gradientIds);
|
|
3263
3124
|
renderNodes(svg, layout.nodes, animation);
|
|
3264
3125
|
renderLabels(svg, layout.nodes, layout.measureText);
|
|
3265
3126
|
renderLegend(svg, layout.legend);
|
|
3266
|
-
|
|
3127
|
+
renderChrome(svg, layout);
|
|
3267
3128
|
renderAttributionBrand(
|
|
3268
3129
|
svg,
|
|
3269
3130
|
layout.chrome,
|
|
@@ -4806,7 +4667,10 @@ function createTileMap(container, spec, options) {
|
|
|
4806
4667
|
}
|
|
4807
4668
|
svgElement.remove();
|
|
4808
4669
|
}
|
|
4809
|
-
const newSvg = renderTileMapSVG(currentLayout, {
|
|
4670
|
+
const newSvg = renderTileMapSVG(currentLayout, {
|
|
4671
|
+
context: createRenderContext({ ids: pageIdScope }),
|
|
4672
|
+
animate
|
|
4673
|
+
});
|
|
4810
4674
|
container.appendChild(newSvg);
|
|
4811
4675
|
svgElement = newSvg;
|
|
4812
4676
|
cleanupTooltipEvents = wireTooltipAndInteraction(newSvg, currentLayout);
|
|
@@ -4854,7 +4718,10 @@ function createTileMap(container, spec, options) {
|
|
|
4854
4718
|
}
|
|
4855
4719
|
function exportChart(format, options_) {
|
|
4856
4720
|
if (!svgElement) return "";
|
|
4857
|
-
const terminalSvg = renderTileMapSVG(currentLayout, {
|
|
4721
|
+
const terminalSvg = renderTileMapSVG(currentLayout, {
|
|
4722
|
+
context: createRenderContext({ ids: pageIdScope }),
|
|
4723
|
+
animate: false
|
|
4724
|
+
});
|
|
4858
4725
|
const resolvedOptions = { theme: currentLayout.theme, ...options_ };
|
|
4859
4726
|
prepareSettledExportTheme(svgElement, terminalSvg, resolvedOptions.theme, !!options_?.theme);
|
|
4860
4727
|
switch (format) {
|
|
@@ -4938,7 +4805,9 @@ export {
|
|
|
4938
4805
|
createGeoReader,
|
|
4939
4806
|
createGeoReaderBinding,
|
|
4940
4807
|
createGraph,
|
|
4808
|
+
createIdScope,
|
|
4941
4809
|
createReader,
|
|
4810
|
+
createRenderContext,
|
|
4942
4811
|
createSankey,
|
|
4943
4812
|
createSimulationWorker,
|
|
4944
4813
|
createTable,
|