@opendata-ai/openchart-vanilla 6.15.0 → 6.16.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/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/gradient-utils.ts +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-vanilla",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.16.0",
|
|
4
4
|
"description": "Vanilla JS renderer for openchart: SVG charts, HTML tables, force-directed graphs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Riley Hilliard",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@floating-ui/dom": "^1.7.6",
|
|
53
|
-
"@opendata-ai/openchart-core": "6.
|
|
54
|
-
"@opendata-ai/openchart-engine": "6.
|
|
53
|
+
"@opendata-ai/openchart-core": "6.16.0",
|
|
54
|
+
"@opendata-ai/openchart-engine": "6.16.0",
|
|
55
55
|
"d3-force": "^3.0.0",
|
|
56
56
|
"d3-quadtree": "^3.0.1"
|
|
57
57
|
},
|
package/src/gradient-utils.ts
CHANGED
|
@@ -89,25 +89,31 @@ function appendStop(
|
|
|
89
89
|
parent.appendChild(stopEl);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Global counter for gradient IDs. Ensures uniqueness across all charts
|
|
94
|
+
* on the same page, since SVG url(#id) resolves globally in the document.
|
|
95
|
+
*/
|
|
96
|
+
let globalGradientCounter = 0;
|
|
97
|
+
|
|
92
98
|
/**
|
|
93
99
|
* Scan all marks for GradientDef fill values, create SVG gradient elements
|
|
94
100
|
* in the provided <defs> node, and return a map from gradient key to element ID.
|
|
95
101
|
*
|
|
96
|
-
* Identical gradients (by key) share a single SVG element.
|
|
102
|
+
* Identical gradients (by key) share a single SVG element within one chart.
|
|
103
|
+
* IDs are globally unique across charts to avoid SVG url(#id) collisions.
|
|
97
104
|
*/
|
|
98
105
|
export function buildGradientDefs(
|
|
99
106
|
marks: Array<{ fill?: unknown }>,
|
|
100
107
|
defs: SVGElement,
|
|
101
108
|
): Map<string, string> {
|
|
102
109
|
const map = new Map<string, string>();
|
|
103
|
-
let counter = 0;
|
|
104
110
|
|
|
105
111
|
for (const mark of marks) {
|
|
106
112
|
const fill = mark.fill;
|
|
107
113
|
if (fill && isGradientDef(fill)) {
|
|
108
114
|
const key = gradientKey(fill);
|
|
109
115
|
if (!map.has(key)) {
|
|
110
|
-
const id = `oc-grad-${
|
|
116
|
+
const id = `oc-grad-${globalGradientCounter++}`;
|
|
111
117
|
const el = createGradientElement(fill, id);
|
|
112
118
|
defs.appendChild(el);
|
|
113
119
|
map.set(key, id);
|