@uipath/apollo-react 3.44.0 → 3.44.1
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.
|
@@ -71,15 +71,20 @@ const StyledSankeyLink = (0, styles_namespaceObject.styled)('path')({
|
|
|
71
71
|
opacity: 1
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
+
const LABEL_FONT_SIZE = apollo_core_default().FontVariantToken.fontSizeL;
|
|
75
|
+
const LABEL_FONT_FAMILY = apollo_core_default().FontFamily.FontNormal;
|
|
76
|
+
const LABEL_CSS_FONT = `${apollo_core_default().Typography.fontSizeL.fontWeight} ${apollo_core_default().Typography.fontSizeL.fontSize} ${LABEL_FONT_FAMILY}`;
|
|
74
77
|
const StyledSankeyNodeLabel = (0, styles_namespaceObject.styled)('text')({
|
|
75
|
-
fontSize:
|
|
78
|
+
fontSize: LABEL_FONT_SIZE,
|
|
79
|
+
fontFamily: LABEL_FONT_FAMILY,
|
|
76
80
|
fill: 'var(--color-foreground-emp)',
|
|
77
81
|
pointerEvents: 'auto',
|
|
78
82
|
userSelect: 'none',
|
|
79
83
|
cursor: 'default'
|
|
80
84
|
});
|
|
81
85
|
const StyledSankeyNodeValue = (0, styles_namespaceObject.styled)('text')({
|
|
82
|
-
fontSize:
|
|
86
|
+
fontSize: LABEL_FONT_SIZE,
|
|
87
|
+
fontFamily: LABEL_FONT_FAMILY,
|
|
83
88
|
fontWeight: apollo_core_default().FontFamily.FontWeightMedium,
|
|
84
89
|
fill: 'var(--color-foreground-emp)',
|
|
85
90
|
pointerEvents: 'auto',
|
|
@@ -116,11 +121,21 @@ const TooltipValue = (0, styles_namespaceObject.styled)('span')({
|
|
|
116
121
|
color: 'var(--color-foreground-emp)',
|
|
117
122
|
fontWeight: apollo_core_default().FontFamily.FontWeightSemibold
|
|
118
123
|
});
|
|
119
|
-
const
|
|
124
|
+
const DIAGRAM_MARGIN_LEFT = 5;
|
|
125
|
+
const DIAGRAM_MARGIN_RIGHT = 120;
|
|
120
126
|
const DIAGRAM_MARGIN_VERTICAL = 5;
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
|
|
127
|
+
const truncateToFit = (text, maxWidth, ctx)=>{
|
|
128
|
+
if (maxWidth <= 0) return '';
|
|
129
|
+
if (ctx.measureText(text).width <= maxWidth) return text;
|
|
130
|
+
const ellipsis = '\u2026';
|
|
131
|
+
let lo = 0;
|
|
132
|
+
let hi = text.length;
|
|
133
|
+
while(lo < hi){
|
|
134
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
135
|
+
if (ctx.measureText(text.substring(0, mid) + ellipsis).width <= maxWidth) lo = mid;
|
|
136
|
+
else hi = mid - 1;
|
|
137
|
+
}
|
|
138
|
+
return 0 === lo ? ellipsis : text.substring(0, lo) + ellipsis;
|
|
124
139
|
};
|
|
125
140
|
const ApSankeyDiagram = /*#__PURE__*/ external_react_default().forwardRef((props, ref)=>{
|
|
126
141
|
const { data, nodeAlignment = 'justify', nodePadding = 16, nodeWidth = 24, style, className, colorScheme = external_d3_scale_chromatic_namespaceObject.schemeTableau10, ariaLabel = 'Sankey diagram', onLinkClick, onNodeClick } = props;
|
|
@@ -164,11 +179,11 @@ const ApSankeyDiagram = /*#__PURE__*/ external_react_default().forwardRef((props
|
|
|
164
179
|
const alignmentFn = 'left' === nodeAlignment ? external_d3_sankey_namespaceObject.sankeyLeft : 'right' === nodeAlignment ? external_d3_sankey_namespaceObject.sankeyRight : 'center' === nodeAlignment ? external_d3_sankey_namespaceObject.sankeyCenter : external_d3_sankey_namespaceObject.sankeyJustify;
|
|
165
180
|
const sankeyGenerator = (0, external_d3_sankey_namespaceObject.sankey)().nodeId((d)=>d.id).nodeAlign(alignmentFn).nodeWidth(nodeWidth).nodePadding(nodePadding).extent([
|
|
166
181
|
[
|
|
167
|
-
|
|
182
|
+
DIAGRAM_MARGIN_LEFT,
|
|
168
183
|
DIAGRAM_MARGIN_VERTICAL
|
|
169
184
|
],
|
|
170
185
|
[
|
|
171
|
-
actualWidth -
|
|
186
|
+
actualWidth - DIAGRAM_MARGIN_RIGHT,
|
|
172
187
|
actualHeight - DIAGRAM_MARGIN_VERTICAL
|
|
173
188
|
]
|
|
174
189
|
]);
|
|
@@ -233,20 +248,29 @@ const ApSankeyDiagram = /*#__PURE__*/ external_react_default().forwardRef((props
|
|
|
233
248
|
]);
|
|
234
249
|
const nodeData = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
235
250
|
if (!sankeyGraph) return [];
|
|
236
|
-
const
|
|
251
|
+
const labelPad = parseInt(apollo_core_default().Spacing.SpacingXs, 10);
|
|
252
|
+
const ctx = 'undefined' != typeof document ? document.createElement('canvas').getContext('2d') : null;
|
|
253
|
+
if (ctx) ctx.font = LABEL_CSS_FONT;
|
|
254
|
+
const columnSet = new Map();
|
|
255
|
+
for (const n of sankeyGraph.nodes){
|
|
256
|
+
const ext = n;
|
|
257
|
+
const x0 = ext.x0 || 0;
|
|
258
|
+
const x1 = ext.x1 || 0;
|
|
259
|
+
if (!columnSet.has(x0)) columnSet.set(x0, x1);
|
|
260
|
+
}
|
|
261
|
+
const columns = Array.from(columnSet.entries()).map(([x0, x1])=>({
|
|
262
|
+
x0,
|
|
263
|
+
x1
|
|
264
|
+
})).sort((a, b)=>a.x0 - b.x0);
|
|
237
265
|
return sankeyGraph.nodes.map((node, index)=>{
|
|
238
266
|
const extNode = node;
|
|
239
267
|
const x0 = extNode.x0 || 0;
|
|
240
268
|
const x1 = extNode.x1 || 0;
|
|
241
269
|
const y0 = extNode.y0 || 0;
|
|
242
270
|
const y1 = extNode.y1 || 0;
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
const spaceToMidpoint = labelOnRight ? midpoint - x1 - parseInt(apollo_core_default().Spacing.SpacingXs) : x0 - midpoint - parseInt(apollo_core_default().Spacing.SpacingXs);
|
|
247
|
-
const availableSpace = spaceToMidpoint > 0 ? Math.min(fullSpace, spaceToMidpoint) : fullSpace;
|
|
248
|
-
const maxChars = Math.floor(Math.max(0, availableSpace) / parseInt(apollo_core_default().Spacing.SpacingXs));
|
|
249
|
-
const displayLabel = truncateText(extNode.label, maxChars);
|
|
271
|
+
const colIndex = columns.findIndex((col)=>col.x0 === x0);
|
|
272
|
+
const nextCol = columns[colIndex + 1];
|
|
273
|
+
const displayLabel = nextCol && ctx ? truncateToFit(extNode.label, Math.max(0, nextCol.x0 - x1 - labelPad), ctx) : extNode.label;
|
|
250
274
|
return {
|
|
251
275
|
node: extNode,
|
|
252
276
|
x: x0,
|
|
@@ -254,9 +278,9 @@ const ApSankeyDiagram = /*#__PURE__*/ external_react_default().forwardRef((props
|
|
|
254
278
|
width: x1 - x0,
|
|
255
279
|
height: y1 - y0,
|
|
256
280
|
color: nodeColorMap.get(extNode.id) || colorScheme[index % colorScheme.length],
|
|
257
|
-
labelX:
|
|
281
|
+
labelX: x1 + labelPad,
|
|
258
282
|
labelY: (y0 + y1) / 2,
|
|
259
|
-
labelAnchor:
|
|
283
|
+
labelAnchor: 'start',
|
|
260
284
|
value: extNode.value || 0,
|
|
261
285
|
displayLabel,
|
|
262
286
|
fullLabel: extNode.label
|
|
@@ -265,8 +289,7 @@ const ApSankeyDiagram = /*#__PURE__*/ external_react_default().forwardRef((props
|
|
|
265
289
|
}, [
|
|
266
290
|
sankeyGraph,
|
|
267
291
|
nodeColorMap,
|
|
268
|
-
colorScheme
|
|
269
|
-
actualWidth
|
|
292
|
+
colorScheme
|
|
270
293
|
]);
|
|
271
294
|
const handleLinkMouseEnter = (0, external_react_namespaceObject.useCallback)((index, centerX, centerY)=>{
|
|
272
295
|
if (selectedLinkIndex === index) return;
|
|
@@ -393,7 +416,7 @@ const ApSankeyDiagram = /*#__PURE__*/ external_react_default().forwardRef((props
|
|
|
393
416
|
}),
|
|
394
417
|
nodeItem.value > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StyledSankeyNodeValue, {
|
|
395
418
|
x: nodeItem.labelX,
|
|
396
|
-
y: nodeItem.labelY + parseInt(apollo_core_default().Spacing.SpacingM),
|
|
419
|
+
y: nodeItem.labelY + parseInt(apollo_core_default().Spacing.SpacingM, 10),
|
|
397
420
|
dy: "0.35em",
|
|
398
421
|
textAnchor: nodeItem.labelAnchor,
|
|
399
422
|
children: nodeItem.value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApSankeyDiagram.d.ts","sourceRoot":"","sources":["../../../../src/material/components/ap-sankey-diagram/ApSankeyDiagram.tsx"],"names":[],"mappings":"AAeA,OAAO,KAON,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,oBAAoB,EAA0B,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"ApSankeyDiagram.d.ts","sourceRoot":"","sources":["../../../../src/material/components/ap-sankey-diagram/ApSankeyDiagram.tsx"],"names":[],"mappings":"AAeA,OAAO,KAON,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,oBAAoB,EAA0B,MAAM,yBAAyB,CAAC;AA4J5F,eAAO,MAAM,eAAe,6FAsb3B,CAAC"}
|
|
@@ -32,15 +32,20 @@ const StyledSankeyLink = styled('path')({
|
|
|
32
32
|
opacity: 1
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
+
const LABEL_FONT_SIZE = apollo_core.FontVariantToken.fontSizeL;
|
|
36
|
+
const LABEL_FONT_FAMILY = apollo_core.FontFamily.FontNormal;
|
|
37
|
+
const LABEL_CSS_FONT = `${apollo_core.Typography.fontSizeL.fontWeight} ${apollo_core.Typography.fontSizeL.fontSize} ${LABEL_FONT_FAMILY}`;
|
|
35
38
|
const StyledSankeyNodeLabel = styled('text')({
|
|
36
|
-
fontSize:
|
|
39
|
+
fontSize: LABEL_FONT_SIZE,
|
|
40
|
+
fontFamily: LABEL_FONT_FAMILY,
|
|
37
41
|
fill: 'var(--color-foreground-emp)',
|
|
38
42
|
pointerEvents: 'auto',
|
|
39
43
|
userSelect: 'none',
|
|
40
44
|
cursor: 'default'
|
|
41
45
|
});
|
|
42
46
|
const StyledSankeyNodeValue = styled('text')({
|
|
43
|
-
fontSize:
|
|
47
|
+
fontSize: LABEL_FONT_SIZE,
|
|
48
|
+
fontFamily: LABEL_FONT_FAMILY,
|
|
44
49
|
fontWeight: apollo_core.FontFamily.FontWeightMedium,
|
|
45
50
|
fill: 'var(--color-foreground-emp)',
|
|
46
51
|
pointerEvents: 'auto',
|
|
@@ -77,11 +82,21 @@ const TooltipValue = styled('span')({
|
|
|
77
82
|
color: 'var(--color-foreground-emp)',
|
|
78
83
|
fontWeight: apollo_core.FontFamily.FontWeightSemibold
|
|
79
84
|
});
|
|
80
|
-
const
|
|
85
|
+
const DIAGRAM_MARGIN_LEFT = 5;
|
|
86
|
+
const DIAGRAM_MARGIN_RIGHT = 120;
|
|
81
87
|
const DIAGRAM_MARGIN_VERTICAL = 5;
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
|
|
88
|
+
const truncateToFit = (text, maxWidth, ctx)=>{
|
|
89
|
+
if (maxWidth <= 0) return '';
|
|
90
|
+
if (ctx.measureText(text).width <= maxWidth) return text;
|
|
91
|
+
const ellipsis = '\u2026';
|
|
92
|
+
let lo = 0;
|
|
93
|
+
let hi = text.length;
|
|
94
|
+
while(lo < hi){
|
|
95
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
96
|
+
if (ctx.measureText(text.substring(0, mid) + ellipsis).width <= maxWidth) lo = mid;
|
|
97
|
+
else hi = mid - 1;
|
|
98
|
+
}
|
|
99
|
+
return 0 === lo ? ellipsis : text.substring(0, lo) + ellipsis;
|
|
85
100
|
};
|
|
86
101
|
const ApSankeyDiagram = /*#__PURE__*/ react.forwardRef((props, ref)=>{
|
|
87
102
|
const { data, nodeAlignment = 'justify', nodePadding = 16, nodeWidth = 24, style, className, colorScheme = schemeTableau10, ariaLabel = 'Sankey diagram', onLinkClick, onNodeClick } = props;
|
|
@@ -125,11 +140,11 @@ const ApSankeyDiagram = /*#__PURE__*/ react.forwardRef((props, ref)=>{
|
|
|
125
140
|
const alignmentFn = 'left' === nodeAlignment ? sankeyLeft : 'right' === nodeAlignment ? sankeyRight : 'center' === nodeAlignment ? sankeyCenter : sankeyJustify;
|
|
126
141
|
const sankeyGenerator = sankey().nodeId((d)=>d.id).nodeAlign(alignmentFn).nodeWidth(nodeWidth).nodePadding(nodePadding).extent([
|
|
127
142
|
[
|
|
128
|
-
|
|
143
|
+
DIAGRAM_MARGIN_LEFT,
|
|
129
144
|
DIAGRAM_MARGIN_VERTICAL
|
|
130
145
|
],
|
|
131
146
|
[
|
|
132
|
-
actualWidth -
|
|
147
|
+
actualWidth - DIAGRAM_MARGIN_RIGHT,
|
|
133
148
|
actualHeight - DIAGRAM_MARGIN_VERTICAL
|
|
134
149
|
]
|
|
135
150
|
]);
|
|
@@ -194,20 +209,29 @@ const ApSankeyDiagram = /*#__PURE__*/ react.forwardRef((props, ref)=>{
|
|
|
194
209
|
]);
|
|
195
210
|
const nodeData = useMemo(()=>{
|
|
196
211
|
if (!sankeyGraph) return [];
|
|
197
|
-
const
|
|
212
|
+
const labelPad = parseInt(apollo_core.Spacing.SpacingXs, 10);
|
|
213
|
+
const ctx = 'undefined' != typeof document ? document.createElement('canvas').getContext('2d') : null;
|
|
214
|
+
if (ctx) ctx.font = LABEL_CSS_FONT;
|
|
215
|
+
const columnSet = new Map();
|
|
216
|
+
for (const n of sankeyGraph.nodes){
|
|
217
|
+
const ext = n;
|
|
218
|
+
const x0 = ext.x0 || 0;
|
|
219
|
+
const x1 = ext.x1 || 0;
|
|
220
|
+
if (!columnSet.has(x0)) columnSet.set(x0, x1);
|
|
221
|
+
}
|
|
222
|
+
const columns = Array.from(columnSet.entries()).map(([x0, x1])=>({
|
|
223
|
+
x0,
|
|
224
|
+
x1
|
|
225
|
+
})).sort((a, b)=>a.x0 - b.x0);
|
|
198
226
|
return sankeyGraph.nodes.map((node, index)=>{
|
|
199
227
|
const extNode = node;
|
|
200
228
|
const x0 = extNode.x0 || 0;
|
|
201
229
|
const x1 = extNode.x1 || 0;
|
|
202
230
|
const y0 = extNode.y0 || 0;
|
|
203
231
|
const y1 = extNode.y1 || 0;
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const spaceToMidpoint = labelOnRight ? midpoint - x1 - parseInt(apollo_core.Spacing.SpacingXs) : x0 - midpoint - parseInt(apollo_core.Spacing.SpacingXs);
|
|
208
|
-
const availableSpace = spaceToMidpoint > 0 ? Math.min(fullSpace, spaceToMidpoint) : fullSpace;
|
|
209
|
-
const maxChars = Math.floor(Math.max(0, availableSpace) / parseInt(apollo_core.Spacing.SpacingXs));
|
|
210
|
-
const displayLabel = truncateText(extNode.label, maxChars);
|
|
232
|
+
const colIndex = columns.findIndex((col)=>col.x0 === x0);
|
|
233
|
+
const nextCol = columns[colIndex + 1];
|
|
234
|
+
const displayLabel = nextCol && ctx ? truncateToFit(extNode.label, Math.max(0, nextCol.x0 - x1 - labelPad), ctx) : extNode.label;
|
|
211
235
|
return {
|
|
212
236
|
node: extNode,
|
|
213
237
|
x: x0,
|
|
@@ -215,9 +239,9 @@ const ApSankeyDiagram = /*#__PURE__*/ react.forwardRef((props, ref)=>{
|
|
|
215
239
|
width: x1 - x0,
|
|
216
240
|
height: y1 - y0,
|
|
217
241
|
color: nodeColorMap.get(extNode.id) || colorScheme[index % colorScheme.length],
|
|
218
|
-
labelX:
|
|
242
|
+
labelX: x1 + labelPad,
|
|
219
243
|
labelY: (y0 + y1) / 2,
|
|
220
|
-
labelAnchor:
|
|
244
|
+
labelAnchor: 'start',
|
|
221
245
|
value: extNode.value || 0,
|
|
222
246
|
displayLabel,
|
|
223
247
|
fullLabel: extNode.label
|
|
@@ -226,8 +250,7 @@ const ApSankeyDiagram = /*#__PURE__*/ react.forwardRef((props, ref)=>{
|
|
|
226
250
|
}, [
|
|
227
251
|
sankeyGraph,
|
|
228
252
|
nodeColorMap,
|
|
229
|
-
colorScheme
|
|
230
|
-
actualWidth
|
|
253
|
+
colorScheme
|
|
231
254
|
]);
|
|
232
255
|
const handleLinkMouseEnter = useCallback((index, centerX, centerY)=>{
|
|
233
256
|
if (selectedLinkIndex === index) return;
|
|
@@ -354,7 +377,7 @@ const ApSankeyDiagram = /*#__PURE__*/ react.forwardRef((props, ref)=>{
|
|
|
354
377
|
}),
|
|
355
378
|
nodeItem.value > 0 && /*#__PURE__*/ jsx(StyledSankeyNodeValue, {
|
|
356
379
|
x: nodeItem.labelX,
|
|
357
|
-
y: nodeItem.labelY + parseInt(apollo_core.Spacing.SpacingM),
|
|
380
|
+
y: nodeItem.labelY + parseInt(apollo_core.Spacing.SpacingM, 10),
|
|
358
381
|
dy: "0.35em",
|
|
359
382
|
textAnchor: nodeItem.labelAnchor,
|
|
360
383
|
children: nodeItem.value
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/apollo-react",
|
|
3
|
-
"version": "3.44.
|
|
3
|
+
"version": "3.44.1",
|
|
4
4
|
"description": "Apollo Design System - React component library with Material UI theming",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -198,8 +198,8 @@
|
|
|
198
198
|
"use-sync-external-store": "^1.2.0",
|
|
199
199
|
"zod": "^4.3.5",
|
|
200
200
|
"zustand": "^5.0.9",
|
|
201
|
-
"@uipath/apollo-
|
|
202
|
-
"@uipath/apollo-
|
|
201
|
+
"@uipath/apollo-wind": "0.10.0",
|
|
202
|
+
"@uipath/apollo-core": "5.7.0"
|
|
203
203
|
},
|
|
204
204
|
"devDependencies": {
|
|
205
205
|
"@lingui/cli": "^5.6.1",
|