@opendata-ai/openchart-engine 6.18.0 → 6.19.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 +24 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/sankey/compile-sankey.ts +27 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-engine",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.19.0",
|
|
4
4
|
"description": "Headless compiler for openchart: spec validation, data compilation, scales, and layout",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Riley Hilliard",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typecheck": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@opendata-ai/openchart-core": "6.
|
|
48
|
+
"@opendata-ai/openchart-core": "6.19.0",
|
|
49
49
|
"d3-array": "^3.2.0",
|
|
50
50
|
"d3-format": "^3.1.2",
|
|
51
51
|
"d3-interpolate": "^3.0.0",
|
|
@@ -140,6 +140,8 @@ function computeNodeLabel(
|
|
|
140
140
|
theme: ResolvedTheme,
|
|
141
141
|
nodeWidth: number,
|
|
142
142
|
nodeLabelAlign: 'auto' | 'left' | 'right' = 'auto',
|
|
143
|
+
containerWidth?: number,
|
|
144
|
+
padding?: number,
|
|
143
145
|
): SankeyNodeMark['label'] {
|
|
144
146
|
const depth = node.depth ?? 0;
|
|
145
147
|
|
|
@@ -168,6 +170,20 @@ function computeNodeLabel(
|
|
|
168
170
|
const y1 = node.y1 ?? 0;
|
|
169
171
|
const midY = (y0 + y1) / 2;
|
|
170
172
|
|
|
173
|
+
// Compute maxWidth: space from label position to the container edge
|
|
174
|
+
const pad = padding ?? 0;
|
|
175
|
+
let maxWidth: number | undefined;
|
|
176
|
+
if (containerWidth !== undefined) {
|
|
177
|
+
if (placeLeft) {
|
|
178
|
+
// Label goes left from x0: available space is from left padding to x0
|
|
179
|
+
maxWidth = x0 - LABEL_GAP - pad;
|
|
180
|
+
} else {
|
|
181
|
+
// Label goes right from x1: available space is from x1 to right edge
|
|
182
|
+
maxWidth = containerWidth - pad - (x1 + LABEL_GAP);
|
|
183
|
+
}
|
|
184
|
+
if (maxWidth !== undefined && maxWidth < 0) maxWidth = 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
171
187
|
if (placeLeft) {
|
|
172
188
|
return {
|
|
173
189
|
text: node.label ?? node.id,
|
|
@@ -175,6 +191,7 @@ function computeNodeLabel(
|
|
|
175
191
|
y: midY,
|
|
176
192
|
style: { ...style, textAnchor: 'end', dominantBaseline: 'central' },
|
|
177
193
|
visible: true,
|
|
194
|
+
maxWidth,
|
|
178
195
|
};
|
|
179
196
|
}
|
|
180
197
|
|
|
@@ -184,6 +201,7 @@ function computeNodeLabel(
|
|
|
184
201
|
y: midY,
|
|
185
202
|
style: { ...style, textAnchor: 'start', dominantBaseline: 'central' },
|
|
186
203
|
visible: true,
|
|
204
|
+
maxWidth,
|
|
187
205
|
};
|
|
188
206
|
}
|
|
189
207
|
|
|
@@ -394,7 +412,15 @@ export function compileSankey(spec: unknown, options: CompileOptions): SankeyLay
|
|
|
394
412
|
height: (node.y1 ?? 0) - (node.y0 ?? 0),
|
|
395
413
|
fill,
|
|
396
414
|
cornerRadius: NODE_CORNER_RADIUS,
|
|
397
|
-
label: computeNodeLabel(
|
|
415
|
+
label: computeNodeLabel(
|
|
416
|
+
node,
|
|
417
|
+
maxDepth,
|
|
418
|
+
theme,
|
|
419
|
+
sankeySpec.nodeWidth,
|
|
420
|
+
nodeLabelAlign,
|
|
421
|
+
options.width,
|
|
422
|
+
padding,
|
|
423
|
+
),
|
|
398
424
|
nodeId: node.id,
|
|
399
425
|
value: node.value ?? 0,
|
|
400
426
|
depth,
|