@opendata-ai/openchart-vanilla 7.7.0 → 7.9.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/dist/{chunk-PSMDJEXK.js → chunk-QRE4FQQM.js} +380 -14
- package/dist/chunk-QRE4FQQM.js.map +1 -0
- package/dist/index.d.ts +26 -19
- package/dist/index.js +1755 -378
- package/dist/index.js.map +1 -1
- package/dist/static.d.ts +2 -2
- package/dist/static.js +37 -27
- package/dist/static.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/animation.test.ts +1 -1
- package/src/__tests__/transition.test.ts +1592 -0
- package/src/barlist-mount.ts +1 -1
- package/src/barlist-renderer.ts +4 -4
- package/src/index.ts +2 -0
- package/src/mount.ts +64 -1
- package/src/renderers/axes.ts +18 -0
- package/src/renderers/marks.ts +21 -7
- package/src/sankey-mount.ts +2 -2
- package/src/sankey-renderer.ts +9 -8
- package/src/static.ts +42 -32
- package/src/svg-renderer.ts +8 -7
- package/src/table-mount.ts +1 -1
- package/src/table-renderer.ts +5 -5
- package/src/tilemap-mount.ts +1 -1
- package/src/tilemap-renderer.ts +8 -9
- package/src/transition.ts +2473 -0
- package/dist/chunk-PSMDJEXK.js.map +0 -1
|
@@ -128,7 +128,10 @@ function resetMarkRenderState() {
|
|
|
128
128
|
currentGradientMap = /* @__PURE__ */ new Map();
|
|
129
129
|
}
|
|
130
130
|
function stampAnimationAttrs(el, mark, fallbackIndex) {
|
|
131
|
-
if (
|
|
131
|
+
if (mark.key) {
|
|
132
|
+
el.setAttribute("data-key", mark.key);
|
|
133
|
+
}
|
|
134
|
+
if (!currentAnimation?.enter) return;
|
|
132
135
|
const idx = mark.animationIndex ?? fallbackIndex;
|
|
133
136
|
el.setAttribute("data-animation-index", String(idx));
|
|
134
137
|
el.style.setProperty("--oc-mark-index", String(idx));
|
|
@@ -214,7 +217,7 @@ function renderAreaMark(mark, index) {
|
|
|
214
217
|
}
|
|
215
218
|
return g;
|
|
216
219
|
}
|
|
217
|
-
function
|
|
220
|
+
function rectPathWithCorners(mark, sides) {
|
|
218
221
|
const { x, y, width: w, height: h } = mark;
|
|
219
222
|
const r = Math.max(0, Math.min(mark.cornerRadius ?? 0, w / 2, h / 2));
|
|
220
223
|
const tl = sides.tl ? r : 0;
|
|
@@ -239,14 +242,14 @@ function renderRectMark(mark, index) {
|
|
|
239
242
|
g.setAttribute("data-mark-id", `rect-${index}`);
|
|
240
243
|
g.setAttribute("class", "oc-mark oc-mark-rect");
|
|
241
244
|
stampAnimationAttrs(g, mark, index);
|
|
242
|
-
if (currentAnimation?.
|
|
245
|
+
if (currentAnimation?.enter && mark.orient === "horizontal") {
|
|
243
246
|
g.setAttribute("data-orient", "horizontal");
|
|
244
247
|
}
|
|
245
248
|
const sides = mark.cornerRadiusSides;
|
|
246
249
|
const partialCorners = !!sides && (!sides.tl || !sides.tr || !sides.br || !sides.bl) && !!mark.cornerRadius;
|
|
247
250
|
const shapeEl = partialCorners ? createSVGElement("path") : createSVGElement("rect");
|
|
248
251
|
if (partialCorners) {
|
|
249
|
-
shapeEl.setAttribute("d",
|
|
252
|
+
shapeEl.setAttribute("d", rectPathWithCorners(mark, sides));
|
|
250
253
|
} else {
|
|
251
254
|
setAttrs(shapeEl, {
|
|
252
255
|
x: mark.x,
|
|
@@ -396,6 +399,11 @@ registerMarkRenderer("point", renderPointMark);
|
|
|
396
399
|
registerMarkRenderer("textMark", renderTextMark);
|
|
397
400
|
registerMarkRenderer("rule", renderRuleMark);
|
|
398
401
|
registerMarkRenderer("tick", renderTickMark);
|
|
402
|
+
function renderSingleMark(mark, index) {
|
|
403
|
+
const renderer = markRenderers[mark.type];
|
|
404
|
+
if (!renderer) return void 0;
|
|
405
|
+
return renderer(mark, index);
|
|
406
|
+
}
|
|
399
407
|
function getMarkSeries(mark) {
|
|
400
408
|
if (mark.type === "line" || mark.type === "area") {
|
|
401
409
|
return mark.seriesKey;
|
|
@@ -426,7 +434,7 @@ function renderMarks(parent, layout) {
|
|
|
426
434
|
if (series) {
|
|
427
435
|
el.setAttribute("data-series", series);
|
|
428
436
|
}
|
|
429
|
-
if (currentAnimation?.
|
|
437
|
+
if (currentAnimation?.enter && mark.type === "rect") {
|
|
430
438
|
const rect = mark;
|
|
431
439
|
if (rect.stackGroup && rect.stackPos !== void 0) {
|
|
432
440
|
el.setAttribute("data-stack-pos", String(rect.stackPos));
|
|
@@ -454,7 +462,7 @@ function renderMarks(parent, layout) {
|
|
|
454
462
|
setAttrs(label, { x: rect.label.x, y: rect.label.y });
|
|
455
463
|
applyTextStyle(label, rect.label.style);
|
|
456
464
|
label.textContent = rect.label.text;
|
|
457
|
-
if (currentAnimation?.
|
|
465
|
+
if (currentAnimation?.enter) {
|
|
458
466
|
const idx = rect.animationIndex ?? i;
|
|
459
467
|
label.setAttribute("data-animation-index", String(idx));
|
|
460
468
|
label.style.setProperty(
|
|
@@ -741,6 +749,7 @@ import {
|
|
|
741
749
|
TICK_LABEL_OFFSET,
|
|
742
750
|
textAscent
|
|
743
751
|
} from "@opendata-ai/openchart-core";
|
|
752
|
+
import { serializeKeyValue } from "@opendata-ai/openchart-engine";
|
|
744
753
|
function appendCompoundLabel(parent, primaryText, subtitle, fontWeight) {
|
|
745
754
|
const primarySpan = createSVGElement("tspan");
|
|
746
755
|
primarySpan.setAttribute("font-weight", String(fontWeight));
|
|
@@ -776,9 +785,11 @@ function renderAxis(parent, axis, orientation, layout) {
|
|
|
776
785
|
g.appendChild(line);
|
|
777
786
|
}
|
|
778
787
|
for (const tick of axis.ticks) {
|
|
788
|
+
const tickKey = serializeKeyValue(tick.value);
|
|
779
789
|
if (orientation === "x") {
|
|
780
790
|
const label = createSVGElement("text");
|
|
781
791
|
label.setAttribute("class", "oc-axis-tick");
|
|
792
|
+
label.setAttribute("data-tick-key", tickKey);
|
|
782
793
|
if (axis.tickAngle && Math.abs(axis.tickAngle) > 10) {
|
|
783
794
|
const labelX = tick.position;
|
|
784
795
|
const xLabelPad = axis.labelPadding ?? layout.theme.spacing.xAxisLabelPadding;
|
|
@@ -804,6 +815,7 @@ function renderAxis(parent, axis, orientation, layout) {
|
|
|
804
815
|
} else if (isInlineY) {
|
|
805
816
|
const label = createSVGElement("text");
|
|
806
817
|
label.setAttribute("class", "oc-axis-tick oc-axis-tick-inline");
|
|
818
|
+
label.setAttribute("data-tick-key", tickKey);
|
|
807
819
|
setAttrs(label, {
|
|
808
820
|
x: area.x,
|
|
809
821
|
y: tick.position - 6,
|
|
@@ -815,6 +827,7 @@ function renderAxis(parent, axis, orientation, layout) {
|
|
|
815
827
|
} else {
|
|
816
828
|
const label = createSVGElement("text");
|
|
817
829
|
label.setAttribute("class", "oc-axis-tick");
|
|
830
|
+
label.setAttribute("data-tick-key", tickKey);
|
|
818
831
|
setAttrs(label, {
|
|
819
832
|
x: isRight ? area.x + area.width + TICK_LABEL_OFFSET : area.x - TICK_LABEL_OFFSET,
|
|
820
833
|
y: tick.position,
|
|
@@ -890,9 +903,17 @@ function renderAxis(parent, axis, orientation, layout) {
|
|
|
890
903
|
}
|
|
891
904
|
}
|
|
892
905
|
if (!isRight) {
|
|
906
|
+
const posToTickKey = /* @__PURE__ */ new Map();
|
|
907
|
+
for (const tick of axis.ticks) {
|
|
908
|
+
posToTickKey.set(tick.position, serializeKeyValue(tick.value));
|
|
909
|
+
}
|
|
893
910
|
for (const gridline of axis.gridlines) {
|
|
894
911
|
const gl = createSVGElement("line");
|
|
895
912
|
gl.setAttribute("class", "oc-gridline");
|
|
913
|
+
const glKey = posToTickKey.get(gridline.position);
|
|
914
|
+
if (glKey) {
|
|
915
|
+
gl.setAttribute("data-tick-key", glKey);
|
|
916
|
+
}
|
|
896
917
|
if (orientation === "y") {
|
|
897
918
|
setAttrs(gl, {
|
|
898
919
|
x1: area.x,
|
|
@@ -1471,13 +1492,14 @@ function renderChartSVG(layout, container, opts) {
|
|
|
1471
1492
|
}
|
|
1472
1493
|
const classes = opts?.animate ? "oc-chart oc-animate" : "oc-chart";
|
|
1473
1494
|
svg.setAttribute("class", classes);
|
|
1474
|
-
|
|
1495
|
+
const enterPhase = animation?.enter;
|
|
1496
|
+
if (enterPhase) {
|
|
1475
1497
|
const markCount = layout.marks.length;
|
|
1476
|
-
const stagger = clampStaggerDelay(
|
|
1477
|
-
svg.style.setProperty("--oc-animation-duration", `${
|
|
1498
|
+
const stagger = clampStaggerDelay(enterPhase.staggerDelay, markCount);
|
|
1499
|
+
svg.style.setProperty("--oc-animation-duration", `${enterPhase.duration}ms`);
|
|
1478
1500
|
svg.style.setProperty("--oc-animation-stagger", `${stagger}ms`);
|
|
1479
1501
|
svg.style.setProperty("--oc-annotation-delay", `${animation.annotationDelay}ms`);
|
|
1480
|
-
const easeVar = EASE_VAR_MAP[
|
|
1502
|
+
const easeVar = EASE_VAR_MAP[enterPhase.ease] || EASE_VAR_MAP.smooth;
|
|
1481
1503
|
svg.style.setProperty("--oc-animation-ease", easeVar);
|
|
1482
1504
|
let maxSegments = 0;
|
|
1483
1505
|
for (const m of layout.marks) {
|
|
@@ -1489,7 +1511,7 @@ function renderChartSVG(layout, container, opts) {
|
|
|
1489
1511
|
}
|
|
1490
1512
|
}
|
|
1491
1513
|
if (maxSegments > 0) {
|
|
1492
|
-
const segDuration = Math.round(
|
|
1514
|
+
const segDuration = Math.round(enterPhase.duration / maxSegments);
|
|
1493
1515
|
svg.style.setProperty("--oc-stack-segment-duration", `${segDuration}ms`);
|
|
1494
1516
|
}
|
|
1495
1517
|
}
|
|
@@ -1670,11 +1692,355 @@ function renderFacetedPanels(svg, layout, panels, defs) {
|
|
|
1670
1692
|
}
|
|
1671
1693
|
}
|
|
1672
1694
|
|
|
1695
|
+
// src/tilemap-renderer.ts
|
|
1696
|
+
import { textAscent as textAscent4 } from "@opendata-ai/openchart-core";
|
|
1697
|
+
var SVG_NS3 = "http://www.w3.org/2000/svg";
|
|
1698
|
+
var XLINK_NS2 = "http://www.w3.org/1999/xlink";
|
|
1699
|
+
var BRAND_URL2 = "https://tryopendata.ai";
|
|
1700
|
+
var EASE_VAR_MAP2 = {
|
|
1701
|
+
smooth: "var(--oc-ease-smooth)",
|
|
1702
|
+
snappy: "var(--oc-ease-snappy)"
|
|
1703
|
+
};
|
|
1704
|
+
function createSVGElement2(tag) {
|
|
1705
|
+
return document.createElementNS(SVG_NS3, tag);
|
|
1706
|
+
}
|
|
1707
|
+
function setAttrs2(el, attrs) {
|
|
1708
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
1709
|
+
el.setAttribute(key, String(value));
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
function renderChrome2(parent, layout) {
|
|
1713
|
+
const g = createSVGElement2("g");
|
|
1714
|
+
g.setAttribute("class", "oc-chrome");
|
|
1715
|
+
const { chrome } = layout;
|
|
1716
|
+
const bottomOffset = layout.area.y + layout.area.height;
|
|
1717
|
+
if (chrome.title) {
|
|
1718
|
+
const text = createSVGElement2("text");
|
|
1719
|
+
setAttrs2(text, {
|
|
1720
|
+
x: chrome.title.x,
|
|
1721
|
+
y: chrome.title.y + textAscent4(chrome.title.style.fontSize)
|
|
1722
|
+
});
|
|
1723
|
+
text.setAttribute("class", "oc-title");
|
|
1724
|
+
text.setAttribute("font-family", chrome.title.style.fontFamily);
|
|
1725
|
+
text.setAttribute("font-size", String(chrome.title.style.fontSize));
|
|
1726
|
+
text.setAttribute("font-weight", String(chrome.title.style.fontWeight));
|
|
1727
|
+
text.style.setProperty("fill", chrome.title.style.fill);
|
|
1728
|
+
text.textContent = chrome.title.text;
|
|
1729
|
+
g.appendChild(text);
|
|
1730
|
+
}
|
|
1731
|
+
if (chrome.subtitle) {
|
|
1732
|
+
const text = createSVGElement2("text");
|
|
1733
|
+
setAttrs2(text, {
|
|
1734
|
+
x: chrome.subtitle.x,
|
|
1735
|
+
y: chrome.subtitle.y + textAscent4(chrome.subtitle.style.fontSize)
|
|
1736
|
+
});
|
|
1737
|
+
text.setAttribute("class", "oc-subtitle");
|
|
1738
|
+
text.setAttribute("font-family", chrome.subtitle.style.fontFamily);
|
|
1739
|
+
text.setAttribute("font-size", String(chrome.subtitle.style.fontSize));
|
|
1740
|
+
text.setAttribute("font-weight", String(chrome.subtitle.style.fontWeight));
|
|
1741
|
+
text.style.setProperty(
|
|
1742
|
+
"fill",
|
|
1743
|
+
chrome.subtitle.style.fill
|
|
1744
|
+
);
|
|
1745
|
+
text.textContent = chrome.subtitle.text;
|
|
1746
|
+
g.appendChild(text);
|
|
1747
|
+
}
|
|
1748
|
+
if (chrome.source) {
|
|
1749
|
+
const text = createSVGElement2("text");
|
|
1750
|
+
setAttrs2(text, {
|
|
1751
|
+
x: chrome.source.x,
|
|
1752
|
+
y: bottomOffset + chrome.source.y + textAscent4(chrome.source.style.fontSize)
|
|
1753
|
+
});
|
|
1754
|
+
text.setAttribute("class", "oc-source");
|
|
1755
|
+
text.setAttribute("font-family", chrome.source.style.fontFamily);
|
|
1756
|
+
text.setAttribute("font-size", String(chrome.source.style.fontSize));
|
|
1757
|
+
text.setAttribute("font-weight", String(chrome.source.style.fontWeight));
|
|
1758
|
+
text.style.setProperty(
|
|
1759
|
+
"fill",
|
|
1760
|
+
chrome.source.style.fill
|
|
1761
|
+
);
|
|
1762
|
+
text.textContent = chrome.source.text;
|
|
1763
|
+
g.appendChild(text);
|
|
1764
|
+
}
|
|
1765
|
+
if (chrome.byline) {
|
|
1766
|
+
const text = createSVGElement2("text");
|
|
1767
|
+
setAttrs2(text, {
|
|
1768
|
+
x: chrome.byline.x,
|
|
1769
|
+
y: bottomOffset + chrome.byline.y + textAscent4(chrome.byline.style.fontSize)
|
|
1770
|
+
});
|
|
1771
|
+
text.setAttribute("class", "oc-byline");
|
|
1772
|
+
text.setAttribute("font-family", chrome.byline.style.fontFamily);
|
|
1773
|
+
text.setAttribute("font-size", String(chrome.byline.style.fontSize));
|
|
1774
|
+
text.setAttribute("font-weight", String(chrome.byline.style.fontWeight));
|
|
1775
|
+
text.style.setProperty(
|
|
1776
|
+
"fill",
|
|
1777
|
+
chrome.byline.style.fill
|
|
1778
|
+
);
|
|
1779
|
+
text.textContent = chrome.byline.text;
|
|
1780
|
+
g.appendChild(text);
|
|
1781
|
+
}
|
|
1782
|
+
if (chrome.footer) {
|
|
1783
|
+
const text = createSVGElement2("text");
|
|
1784
|
+
setAttrs2(text, {
|
|
1785
|
+
x: chrome.footer.x,
|
|
1786
|
+
y: bottomOffset + chrome.footer.y + textAscent4(chrome.footer.style.fontSize)
|
|
1787
|
+
});
|
|
1788
|
+
text.setAttribute("class", "oc-footer");
|
|
1789
|
+
text.setAttribute("font-family", chrome.footer.style.fontFamily);
|
|
1790
|
+
text.setAttribute("font-size", String(chrome.footer.style.fontSize));
|
|
1791
|
+
text.setAttribute("font-weight", String(chrome.footer.style.fontWeight));
|
|
1792
|
+
text.style.setProperty(
|
|
1793
|
+
"fill",
|
|
1794
|
+
chrome.footer.style.fill
|
|
1795
|
+
);
|
|
1796
|
+
text.textContent = chrome.footer.text;
|
|
1797
|
+
g.appendChild(text);
|
|
1798
|
+
}
|
|
1799
|
+
parent.appendChild(g);
|
|
1800
|
+
}
|
|
1801
|
+
function renderWatermark(parent, layout) {
|
|
1802
|
+
if (layout.width < 480) return;
|
|
1803
|
+
const { width, height } = layout;
|
|
1804
|
+
const { theme } = layout;
|
|
1805
|
+
const padding = theme.spacing.padding;
|
|
1806
|
+
const rightEdge = width - padding;
|
|
1807
|
+
const bottomEdge = height - padding;
|
|
1808
|
+
const fill = theme.colors.axis;
|
|
1809
|
+
const a = createSVGElement2("a");
|
|
1810
|
+
a.setAttribute("href", BRAND_URL2);
|
|
1811
|
+
a.setAttributeNS(XLINK_NS2, "xlink:href", BRAND_URL2);
|
|
1812
|
+
a.setAttribute("target", "_blank");
|
|
1813
|
+
a.setAttribute("rel", "noopener");
|
|
1814
|
+
a.setAttribute("class", "oc-chrome-ref");
|
|
1815
|
+
const text = createSVGElement2("text");
|
|
1816
|
+
setAttrs2(text, {
|
|
1817
|
+
x: rightEdge,
|
|
1818
|
+
y: bottomEdge,
|
|
1819
|
+
"dominant-baseline": "alphabetic",
|
|
1820
|
+
"text-anchor": "end",
|
|
1821
|
+
"font-family": theme.fonts.family,
|
|
1822
|
+
"font-size": 12,
|
|
1823
|
+
"fill-opacity": 0.55
|
|
1824
|
+
});
|
|
1825
|
+
text.style.setProperty("fill", fill);
|
|
1826
|
+
const trySpan = createSVGElement2("tspan");
|
|
1827
|
+
setAttrs2(trySpan, { "font-weight": 500 });
|
|
1828
|
+
trySpan.textContent = "try";
|
|
1829
|
+
const openDataSpan = createSVGElement2("tspan");
|
|
1830
|
+
setAttrs2(openDataSpan, { "font-weight": 600, "font-size": 16 });
|
|
1831
|
+
openDataSpan.textContent = "OpenData";
|
|
1832
|
+
const aiSpan = createSVGElement2("tspan");
|
|
1833
|
+
setAttrs2(aiSpan, { "font-weight": 500 });
|
|
1834
|
+
aiSpan.textContent = ".ai";
|
|
1835
|
+
text.appendChild(trySpan);
|
|
1836
|
+
text.appendChild(openDataSpan);
|
|
1837
|
+
text.appendChild(aiSpan);
|
|
1838
|
+
a.appendChild(text);
|
|
1839
|
+
parent.appendChild(a);
|
|
1840
|
+
}
|
|
1841
|
+
function renderTiles(parent, tiles, animation) {
|
|
1842
|
+
const g = createSVGElement2("g");
|
|
1843
|
+
g.setAttribute("class", "oc-tilemap-tiles");
|
|
1844
|
+
g.setAttribute("role", "list");
|
|
1845
|
+
const tileDelays = [];
|
|
1846
|
+
if (animation?.enter) {
|
|
1847
|
+
const baseStagger = 800 / Math.max(tiles.length, 1);
|
|
1848
|
+
let seed = 17;
|
|
1849
|
+
for (let i = 0; i < tiles.length; i++) {
|
|
1850
|
+
const idx = tiles[i].animationIndex ?? i;
|
|
1851
|
+
seed = seed * 1103515245 + 12345 & 2147483647;
|
|
1852
|
+
const jitter = (seed % 1e3 / 1e3 - 0.5) * 0.8;
|
|
1853
|
+
tileDelays.push(Math.max(0, Math.round(idx * baseStagger * (1 + jitter))));
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
for (let i = 0; i < tiles.length; i++) {
|
|
1857
|
+
const tile = tiles[i];
|
|
1858
|
+
const tileGroup = createSVGElement2("g");
|
|
1859
|
+
tileGroup.setAttribute("class", "oc-tilemap-tile");
|
|
1860
|
+
tileGroup.setAttribute("data-state", tile.stateCode);
|
|
1861
|
+
tileGroup.setAttribute("role", "listitem");
|
|
1862
|
+
if (tile.aria?.label) {
|
|
1863
|
+
tileGroup.setAttribute("aria-label", tile.aria.label);
|
|
1864
|
+
}
|
|
1865
|
+
if (animation?.enter) {
|
|
1866
|
+
const idx = tile.animationIndex ?? i;
|
|
1867
|
+
tileGroup.setAttribute("data-animation-index", String(idx));
|
|
1868
|
+
tileGroup.style.setProperty(
|
|
1869
|
+
"--oc-mark-index",
|
|
1870
|
+
String(idx)
|
|
1871
|
+
);
|
|
1872
|
+
tileGroup.style.setProperty(
|
|
1873
|
+
"--oc-tile-delay",
|
|
1874
|
+
`${tileDelays[i]}ms`
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
const rect = createSVGElement2("rect");
|
|
1878
|
+
setAttrs2(rect, {
|
|
1879
|
+
x: tile.x,
|
|
1880
|
+
y: tile.y,
|
|
1881
|
+
width: tile.size,
|
|
1882
|
+
height: tile.size,
|
|
1883
|
+
rx: tile.cornerRadius,
|
|
1884
|
+
fill: tile.fill,
|
|
1885
|
+
"fill-opacity": tile.fillOpacity ?? 1,
|
|
1886
|
+
stroke: tile.stroke,
|
|
1887
|
+
"stroke-width": tile.strokeWidth
|
|
1888
|
+
});
|
|
1889
|
+
tileGroup.appendChild(rect);
|
|
1890
|
+
const codeLabel = createSVGElement2("text");
|
|
1891
|
+
setAttrs2(codeLabel, {
|
|
1892
|
+
x: tile.label.x,
|
|
1893
|
+
y: tile.label.y,
|
|
1894
|
+
"text-anchor": "middle",
|
|
1895
|
+
"dominant-baseline": "central",
|
|
1896
|
+
"font-family": tile.label.style.fontFamily,
|
|
1897
|
+
"font-size": tile.label.style.fontSize,
|
|
1898
|
+
"font-weight": tile.label.style.fontWeight
|
|
1899
|
+
});
|
|
1900
|
+
codeLabel.style.setProperty(
|
|
1901
|
+
"fill",
|
|
1902
|
+
tile.label.style.fill
|
|
1903
|
+
);
|
|
1904
|
+
codeLabel.textContent = tile.label.text;
|
|
1905
|
+
tileGroup.appendChild(codeLabel);
|
|
1906
|
+
if (tile.valueLabel.visible && tile.valueLabel.text) {
|
|
1907
|
+
const valueLabel = createSVGElement2("text");
|
|
1908
|
+
setAttrs2(valueLabel, {
|
|
1909
|
+
x: tile.valueLabel.x,
|
|
1910
|
+
y: tile.valueLabel.y,
|
|
1911
|
+
"text-anchor": "middle",
|
|
1912
|
+
"dominant-baseline": "central",
|
|
1913
|
+
"font-family": tile.valueLabel.style.fontFamily,
|
|
1914
|
+
"font-size": tile.valueLabel.style.fontSize,
|
|
1915
|
+
"font-weight": tile.valueLabel.style.fontWeight
|
|
1916
|
+
});
|
|
1917
|
+
valueLabel.style.setProperty(
|
|
1918
|
+
"fill",
|
|
1919
|
+
tile.valueLabel.style.fill
|
|
1920
|
+
);
|
|
1921
|
+
valueLabel.textContent = tile.valueLabel.text;
|
|
1922
|
+
tileGroup.appendChild(valueLabel);
|
|
1923
|
+
}
|
|
1924
|
+
g.appendChild(tileGroup);
|
|
1925
|
+
}
|
|
1926
|
+
parent.appendChild(g);
|
|
1927
|
+
}
|
|
1928
|
+
function renderGradientLegend(parent, layout) {
|
|
1929
|
+
if (!layout.gradientLegend) return;
|
|
1930
|
+
const { gradientLegend } = layout;
|
|
1931
|
+
const g = createSVGElement2("g");
|
|
1932
|
+
g.setAttribute("class", "oc-tilemap-legend");
|
|
1933
|
+
const defs = parent.querySelector("defs") || createSVGElement2("defs");
|
|
1934
|
+
const exists = parent.querySelector("defs");
|
|
1935
|
+
if (!exists) {
|
|
1936
|
+
parent.insertBefore(defs, parent.firstChild);
|
|
1937
|
+
}
|
|
1938
|
+
const gradientId = nextSvgId("oc-tilemap-legend-gradient");
|
|
1939
|
+
const grad = createSVGElement2("linearGradient");
|
|
1940
|
+
grad.id = gradientId;
|
|
1941
|
+
grad.setAttribute("x1", "0%");
|
|
1942
|
+
grad.setAttribute("y1", "0%");
|
|
1943
|
+
grad.setAttribute("x2", "100%");
|
|
1944
|
+
grad.setAttribute("y2", "0%");
|
|
1945
|
+
for (const stop of gradientLegend.colorStops) {
|
|
1946
|
+
const s = createSVGElement2("stop");
|
|
1947
|
+
const attrs = {
|
|
1948
|
+
offset: `${stop.offset * 100}%`,
|
|
1949
|
+
"stop-color": stop.color
|
|
1950
|
+
};
|
|
1951
|
+
if (stop.opacity !== void 0) {
|
|
1952
|
+
attrs["stop-opacity"] = stop.opacity;
|
|
1953
|
+
}
|
|
1954
|
+
setAttrs2(s, attrs);
|
|
1955
|
+
grad.appendChild(s);
|
|
1956
|
+
}
|
|
1957
|
+
defs.appendChild(grad);
|
|
1958
|
+
const barHeight = gradientLegend.bounds.height;
|
|
1959
|
+
const bar = createSVGElement2("rect");
|
|
1960
|
+
setAttrs2(bar, {
|
|
1961
|
+
x: gradientLegend.bounds.x,
|
|
1962
|
+
y: gradientLegend.bounds.y,
|
|
1963
|
+
width: gradientLegend.bounds.width,
|
|
1964
|
+
height: barHeight,
|
|
1965
|
+
rx: barHeight / 2,
|
|
1966
|
+
fill: `url(#${gradientId})`
|
|
1967
|
+
});
|
|
1968
|
+
g.appendChild(bar);
|
|
1969
|
+
const minText = createSVGElement2("text");
|
|
1970
|
+
setAttrs2(minText, {
|
|
1971
|
+
x: gradientLegend.bounds.x,
|
|
1972
|
+
y: gradientLegend.bounds.y + gradientLegend.bounds.height + 14,
|
|
1973
|
+
"text-anchor": "start",
|
|
1974
|
+
"font-family": gradientLegend.labelStyle.fontFamily,
|
|
1975
|
+
"font-size": gradientLegend.labelStyle.fontSize,
|
|
1976
|
+
"font-weight": gradientLegend.labelStyle.fontWeight
|
|
1977
|
+
});
|
|
1978
|
+
minText.style.setProperty(
|
|
1979
|
+
"fill",
|
|
1980
|
+
gradientLegend.labelStyle.fill
|
|
1981
|
+
);
|
|
1982
|
+
minText.textContent = gradientLegend.minLabel;
|
|
1983
|
+
g.appendChild(minText);
|
|
1984
|
+
const maxText = createSVGElement2("text");
|
|
1985
|
+
setAttrs2(maxText, {
|
|
1986
|
+
x: gradientLegend.bounds.x + gradientLegend.bounds.width,
|
|
1987
|
+
y: gradientLegend.bounds.y + gradientLegend.bounds.height + 14,
|
|
1988
|
+
"text-anchor": "end",
|
|
1989
|
+
"font-family": gradientLegend.labelStyle.fontFamily,
|
|
1990
|
+
"font-size": gradientLegend.labelStyle.fontSize,
|
|
1991
|
+
"font-weight": gradientLegend.labelStyle.fontWeight
|
|
1992
|
+
});
|
|
1993
|
+
maxText.style.setProperty(
|
|
1994
|
+
"fill",
|
|
1995
|
+
gradientLegend.labelStyle.fill
|
|
1996
|
+
);
|
|
1997
|
+
maxText.textContent = gradientLegend.maxLabel;
|
|
1998
|
+
g.appendChild(maxText);
|
|
1999
|
+
parent.appendChild(g);
|
|
2000
|
+
}
|
|
2001
|
+
function renderTileMapSVG(layout, opts) {
|
|
2002
|
+
const { width, height, tiles, a11y, watermark, animation } = layout;
|
|
2003
|
+
const animate = opts?.animate && !!animation?.enter;
|
|
2004
|
+
const svg = createSVGElement2("svg");
|
|
2005
|
+
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
2006
|
+
svg.setAttribute("role", "img");
|
|
2007
|
+
if (a11y.altText) {
|
|
2008
|
+
svg.setAttribute("aria-label", a11y.altText);
|
|
2009
|
+
}
|
|
2010
|
+
const classes = animate ? "oc-tilemap oc-animate" : "oc-tilemap";
|
|
2011
|
+
svg.setAttribute("class", classes);
|
|
2012
|
+
if (animate && animation?.enter) {
|
|
2013
|
+
const stagger = Math.max(5, Math.round(800 / Math.max(tiles.length, 1)));
|
|
2014
|
+
svg.style.setProperty("--oc-animation-duration", `${animation.enter.duration}ms`);
|
|
2015
|
+
svg.style.setProperty("--oc-animation-stagger", `${stagger}ms`);
|
|
2016
|
+
svg.style.setProperty("--oc-annotation-delay", `${animation.annotationDelay}ms`);
|
|
2017
|
+
const easeVar = EASE_VAR_MAP2[animation.enter.ease] || EASE_VAR_MAP2.smooth;
|
|
2018
|
+
svg.style.setProperty("--oc-animation-ease", easeVar);
|
|
2019
|
+
}
|
|
2020
|
+
const defs = createSVGElement2("defs");
|
|
2021
|
+
svg.appendChild(defs);
|
|
2022
|
+
renderChrome2(svg, layout);
|
|
2023
|
+
renderTiles(svg, tiles, animate ? animation : void 0);
|
|
2024
|
+
if (layout.categoricalLegend) {
|
|
2025
|
+
renderLegend(svg, layout.categoricalLegend);
|
|
2026
|
+
} else {
|
|
2027
|
+
renderGradientLegend(svg, layout);
|
|
2028
|
+
}
|
|
2029
|
+
if (watermark) {
|
|
2030
|
+
renderWatermark(svg, layout);
|
|
2031
|
+
}
|
|
2032
|
+
return svg;
|
|
2033
|
+
}
|
|
2034
|
+
|
|
1673
2035
|
export {
|
|
1674
2036
|
resetSvgIdCounter,
|
|
2037
|
+
buildGradientDefs,
|
|
2038
|
+
resolveMarkFill,
|
|
1675
2039
|
SVG_NS,
|
|
1676
|
-
renderLegend,
|
|
1677
2040
|
registerMarkRenderer,
|
|
1678
|
-
|
|
2041
|
+
rectPathWithCorners,
|
|
2042
|
+
renderSingleMark,
|
|
2043
|
+
renderChartSVG,
|
|
2044
|
+
renderTileMapSVG
|
|
1679
2045
|
};
|
|
1680
|
-
//# sourceMappingURL=chunk-
|
|
2046
|
+
//# sourceMappingURL=chunk-QRE4FQQM.js.map
|