@uipath/apollo-react 3.44.0 → 3.44.2
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/canvas/components/StageNode/StageNode.cjs +11 -5
- package/dist/canvas/components/StageNode/StageNode.d.ts.map +1 -1
- package/dist/canvas/components/StageNode/StageNode.js +12 -6
- package/dist/canvas/components/StageNode/StageNodeTaskUtilities.cjs +7 -4
- package/dist/canvas/components/StageNode/StageNodeTaskUtilities.d.ts +1 -0
- package/dist/canvas/components/StageNode/StageNodeTaskUtilities.d.ts.map +1 -1
- package/dist/canvas/components/StageNode/StageNodeTaskUtilities.js +3 -3
- package/dist/material/components/ap-sankey-diagram/ApSankeyDiagram.cjs +44 -21
- package/dist/material/components/ap-sankey-diagram/ApSankeyDiagram.d.ts.map +1 -1
- package/dist/material/components/ap-sankey-diagram/ApSankeyDiagram.js +44 -21
- package/package.json +1 -1
|
@@ -97,7 +97,7 @@ const StageNodeComponent = (props)=>{
|
|
|
97
97
|
taskIndex: pendingReplaceTask.taskIndex
|
|
98
98
|
};
|
|
99
99
|
setIsReplacingTask(true);
|
|
100
|
-
}
|
|
100
|
+
} else setIsReplacingTask(false);
|
|
101
101
|
}, [
|
|
102
102
|
pendingReplaceTask,
|
|
103
103
|
tasks
|
|
@@ -201,7 +201,10 @@ const StageNodeComponent = (props)=>{
|
|
|
201
201
|
]);
|
|
202
202
|
const contextMenuItems = (0, external_react_namespaceObject.useCallback)((isParallel, groupIndex, taskIndex, tasksLength, taskGroupLength, isAboveParallel, isBelowParallel)=>{
|
|
203
203
|
const items = [];
|
|
204
|
-
if (onReplaceTaskFromToolbox)
|
|
204
|
+
if (onReplaceTaskFromToolbox) {
|
|
205
|
+
items.push((0, external_StageNodeTaskUtilities_cjs_namespaceObject.getMenuItem)('replace-task', 'Replace task', ()=>setIsReplacingTask(true)));
|
|
206
|
+
items.push((0, external_StageNodeTaskUtilities_cjs_namespaceObject.getDivider)());
|
|
207
|
+
}
|
|
205
208
|
if (onTaskGroupModification) {
|
|
206
209
|
const reGroupOptions = (0, external_StageNodeTaskUtilities_cjs_namespaceObject.getContextMenuItems)(isParallel, groupIndex, tasksLength, taskIndex, taskGroupLength, isAboveParallel, isBelowParallel, reGroupTaskFunction);
|
|
207
210
|
return [
|
|
@@ -252,13 +255,16 @@ const StageNodeComponent = (props)=>{
|
|
|
252
255
|
]);
|
|
253
256
|
const handleReplaceTaskToolboxItemSelected = (0, external_react_namespaceObject.useCallback)((item)=>{
|
|
254
257
|
setIsReplacingTask(true);
|
|
258
|
+
const groupIndex = taskStateReference.current.groupIndex;
|
|
259
|
+
const taskIndex = taskStateReference.current.taskIndex;
|
|
260
|
+
const taskId = tasks[groupIndex]?.[taskIndex]?.id;
|
|
261
|
+
if (taskId) onTaskClick?.(taskId);
|
|
255
262
|
onReplaceTaskFromToolbox?.(item, taskStateReference.current.groupIndex, taskStateReference.current.taskIndex);
|
|
256
263
|
setIsReplacingTask(false);
|
|
257
|
-
setSelectedNodeId(id);
|
|
258
264
|
}, [
|
|
259
265
|
onReplaceTaskFromToolbox,
|
|
260
|
-
|
|
261
|
-
|
|
266
|
+
onTaskClick,
|
|
267
|
+
tasks
|
|
262
268
|
]);
|
|
263
269
|
const handleConfigurations = (0, external_react_namespaceObject.useMemo)(()=>isException ? [] : [
|
|
264
270
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StageNode.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/StageNode/StageNode.tsx"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"StageNode.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/StageNode/StageNode.tsx"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAkpBxD,eAAO,MAAM,SAAS,8CAxoBa,cAAc,6CAwoBA,CAAC"}
|
|
@@ -17,7 +17,7 @@ import { Toolbox } from "../Toolbox/index.js";
|
|
|
17
17
|
import { DraggableTask, TaskContent } from "./DraggableTask.js";
|
|
18
18
|
import { INDENTATION_WIDTH, STAGE_CONTENT_INSET, StageContainer, StageContent, StageHeader, StageParallelBracket, StageParallelLabel, StageTask, StageTaskGroup, StageTaskList, StageTitleContainer, StageTitleInput } from "./StageNode.styles.js";
|
|
19
19
|
import { flattenTasks, getProjection, reorderTasks } from "./StageNode.utils.js";
|
|
20
|
-
import { getContextMenuItems, getMenuItem } from "./StageNodeTaskUtilities.js";
|
|
20
|
+
import { getContextMenuItems, getDivider, getMenuItem } from "./StageNodeTaskUtilities.js";
|
|
21
21
|
const StageNodeComponent = (props)=>{
|
|
22
22
|
const { dragging, selected, id, width, execution, stageDetails, addTaskLabel = 'Add task', addTaskLoading = false, replaceTaskLabel = 'Replace task', taskOptions = [], menuItems, pendingReplaceTask, onStageClick, onTaskAdd, onAddTaskFromToolbox, onTaskToolboxSearch, onTaskClick, onTaskGroupModification, onStageTitleChange, onTaskReorder, onReplaceTaskFromToolbox } = props;
|
|
23
23
|
const taskWidth = width ? width - STAGE_CONTENT_INSET : void 0;
|
|
@@ -69,7 +69,7 @@ const StageNodeComponent = (props)=>{
|
|
|
69
69
|
taskIndex: pendingReplaceTask.taskIndex
|
|
70
70
|
};
|
|
71
71
|
setIsReplacingTask(true);
|
|
72
|
-
}
|
|
72
|
+
} else setIsReplacingTask(false);
|
|
73
73
|
}, [
|
|
74
74
|
pendingReplaceTask,
|
|
75
75
|
tasks
|
|
@@ -173,7 +173,10 @@ const StageNodeComponent = (props)=>{
|
|
|
173
173
|
]);
|
|
174
174
|
const contextMenuItems = useCallback((isParallel, groupIndex, taskIndex, tasksLength, taskGroupLength, isAboveParallel, isBelowParallel)=>{
|
|
175
175
|
const items = [];
|
|
176
|
-
if (onReplaceTaskFromToolbox)
|
|
176
|
+
if (onReplaceTaskFromToolbox) {
|
|
177
|
+
items.push(getMenuItem('replace-task', 'Replace task', ()=>setIsReplacingTask(true)));
|
|
178
|
+
items.push(getDivider());
|
|
179
|
+
}
|
|
177
180
|
if (onTaskGroupModification) {
|
|
178
181
|
const reGroupOptions = getContextMenuItems(isParallel, groupIndex, tasksLength, taskIndex, taskGroupLength, isAboveParallel, isBelowParallel, reGroupTaskFunction);
|
|
179
182
|
return [
|
|
@@ -224,13 +227,16 @@ const StageNodeComponent = (props)=>{
|
|
|
224
227
|
]);
|
|
225
228
|
const handleReplaceTaskToolboxItemSelected = useCallback((item)=>{
|
|
226
229
|
setIsReplacingTask(true);
|
|
230
|
+
const groupIndex = taskStateReference.current.groupIndex;
|
|
231
|
+
const taskIndex = taskStateReference.current.taskIndex;
|
|
232
|
+
const taskId = tasks[groupIndex]?.[taskIndex]?.id;
|
|
233
|
+
if (taskId) onTaskClick?.(taskId);
|
|
227
234
|
onReplaceTaskFromToolbox?.(item, taskStateReference.current.groupIndex, taskStateReference.current.taskIndex);
|
|
228
235
|
setIsReplacingTask(false);
|
|
229
|
-
setSelectedNodeId(id);
|
|
230
236
|
}, [
|
|
231
237
|
onReplaceTaskFromToolbox,
|
|
232
|
-
|
|
233
|
-
|
|
238
|
+
onTaskClick,
|
|
239
|
+
tasks
|
|
234
240
|
]);
|
|
235
241
|
const handleConfigurations = useMemo(()=>isException ? [] : [
|
|
236
242
|
{
|
|
@@ -24,15 +24,16 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
getDivider: ()=>getDivider,
|
|
28
|
+
getMenuItem: ()=>getMenuItem,
|
|
27
29
|
transformMenuItems: ()=>transformMenuItems,
|
|
28
|
-
getContextMenuItems: ()=>getContextMenuItems
|
|
29
|
-
getMenuItem: ()=>getMenuItem
|
|
30
|
+
getContextMenuItems: ()=>getContextMenuItems
|
|
30
31
|
});
|
|
31
32
|
const GroupModificationUtils_cjs_namespaceObject = require("../../utils/GroupModificationUtils.cjs");
|
|
32
33
|
const getContextMenuItems = (isParallelGroup, groupIndex, tasksLength, taskIndex, _taskGroupLength, isAboveParallel, isBelowParallel, reGroupTaskFunction)=>{
|
|
33
34
|
const CONTEXT_MENU_ITEMS = {
|
|
34
|
-
MOVE_UP: getMenuItem('move-up', 'Move
|
|
35
|
-
MOVE_DOWN: getMenuItem('move-down', 'Move
|
|
35
|
+
MOVE_UP: getMenuItem('move-up', 'Move up', ()=>reGroupTaskFunction(GroupModificationUtils_cjs_namespaceObject.GroupModificationType.TASK_GROUP_UP, groupIndex, taskIndex)),
|
|
36
|
+
MOVE_DOWN: getMenuItem('move-down', 'Move down', ()=>reGroupTaskFunction(GroupModificationUtils_cjs_namespaceObject.GroupModificationType.TASK_GROUP_DOWN, groupIndex, taskIndex)),
|
|
36
37
|
UNGROUP_ALL: getMenuItem('ungroup', 'Ungroup parallel tasks', ()=>reGroupTaskFunction(GroupModificationUtils_cjs_namespaceObject.GroupModificationType.UNGROUP_ALL_TASKS, groupIndex, taskIndex)),
|
|
37
38
|
SPLIT_TASK: getMenuItem('split', 'Remove from parallel group', ()=>reGroupTaskFunction(GroupModificationUtils_cjs_namespaceObject.GroupModificationType.SPLIT_GROUP, groupIndex, taskIndex)),
|
|
38
39
|
REMOVE_GROUP: getMenuItem('remove-group', 'Remove group from stage', ()=>reGroupTaskFunction(GroupModificationUtils_cjs_namespaceObject.GroupModificationType.REMOVE_GROUP, groupIndex, taskIndex)),
|
|
@@ -87,10 +88,12 @@ const transformMenuItems = (menuItems, onItemClick)=>{
|
|
|
87
88
|
});
|
|
88
89
|
};
|
|
89
90
|
exports.getContextMenuItems = __webpack_exports__.getContextMenuItems;
|
|
91
|
+
exports.getDivider = __webpack_exports__.getDivider;
|
|
90
92
|
exports.getMenuItem = __webpack_exports__.getMenuItem;
|
|
91
93
|
exports.transformMenuItems = __webpack_exports__.transformMenuItems;
|
|
92
94
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
93
95
|
"getContextMenuItems",
|
|
96
|
+
"getDivider",
|
|
94
97
|
"getMenuItem",
|
|
95
98
|
"transformMenuItems"
|
|
96
99
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
@@ -3,6 +3,7 @@ import { GroupModificationType } from '../../utils/GroupModificationUtils';
|
|
|
3
3
|
import type { NodeMenuAction, NodeMenuItem } from '../NodeContextMenu';
|
|
4
4
|
export declare const getContextMenuItems: (isParallelGroup: boolean, groupIndex: number, tasksLength: number, taskIndex: number, _taskGroupLength: number, isAboveParallel: boolean, isBelowParallel: boolean, reGroupTaskFunction: (groupModificationType: GroupModificationType, groupIndex: number, taskIndex: number) => void) => NodeMenuItem[];
|
|
5
5
|
export declare function getMenuItem(id: string | undefined, label: string | undefined, onClick: () => void, isDisabled?: boolean): NodeMenuItem;
|
|
6
|
+
export declare const getDivider: () => NodeMenuItem;
|
|
6
7
|
export interface TransformedMenuItem {
|
|
7
8
|
key: string;
|
|
8
9
|
title?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StageNodeTaskUtilities.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/StageNode/StageNodeTaskUtilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvE,eAAO,MAAM,mBAAmB,GAC9B,iBAAiB,OAAO,EACxB,YAAY,MAAM,EAClB,aAAa,MAAM,EACnB,WAAW,MAAM,EACjB,kBAAkB,MAAM,EACxB,iBAAiB,OAAO,EACxB,iBAAiB,OAAO,EACxB,qBAAqB,CACnB,qBAAqB,EAAE,qBAAqB,EAC5C,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,KACd,IAAI,KACR,YAAY,EAiFd,CAAC;AAEF,wBAAgB,WAAW,CACzB,EAAE,EAAE,MAAM,YAAO,EACjB,KAAK,EAAE,MAAM,YAAU,EACvB,OAAO,EAAE,MAAM,IAAI,EACnB,UAAU,UAAQ,GACjB,YAAY,CAEd;
|
|
1
|
+
{"version":3,"file":"StageNodeTaskUtilities.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/StageNode/StageNodeTaskUtilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvE,eAAO,MAAM,mBAAmB,GAC9B,iBAAiB,OAAO,EACxB,YAAY,MAAM,EAClB,aAAa,MAAM,EACnB,WAAW,MAAM,EACjB,kBAAkB,MAAM,EACxB,iBAAiB,OAAO,EACxB,iBAAiB,OAAO,EACxB,qBAAqB,CACnB,qBAAqB,EAAE,qBAAqB,EAC5C,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,KACd,IAAI,KACR,YAAY,EAiFd,CAAC;AAEF,wBAAgB,WAAW,CACzB,EAAE,EAAE,MAAM,YAAO,EACjB,KAAK,EAAE,MAAM,YAAU,EACvB,OAAO,EAAE,MAAM,IAAI,EACnB,UAAU,UAAQ,GACjB,YAAY,CAEd;AAED,eAAO,MAAM,UAAU,QAAO,YAI7B,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAMD,eAAO,MAAM,kBAAkB,GAC7B,WAAW,YAAY,EAAE,GAAG,SAAS,EACrC,aAAa,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,KAC1C,mBAAmB,EAwBrB,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GroupModificationType } from "../../utils/GroupModificationUtils.js";
|
|
2
2
|
const getContextMenuItems = (isParallelGroup, groupIndex, tasksLength, taskIndex, _taskGroupLength, isAboveParallel, isBelowParallel, reGroupTaskFunction)=>{
|
|
3
3
|
const CONTEXT_MENU_ITEMS = {
|
|
4
|
-
MOVE_UP: getMenuItem('move-up', 'Move
|
|
5
|
-
MOVE_DOWN: getMenuItem('move-down', 'Move
|
|
4
|
+
MOVE_UP: getMenuItem('move-up', 'Move up', ()=>reGroupTaskFunction(GroupModificationType.TASK_GROUP_UP, groupIndex, taskIndex)),
|
|
5
|
+
MOVE_DOWN: getMenuItem('move-down', 'Move down', ()=>reGroupTaskFunction(GroupModificationType.TASK_GROUP_DOWN, groupIndex, taskIndex)),
|
|
6
6
|
UNGROUP_ALL: getMenuItem('ungroup', 'Ungroup parallel tasks', ()=>reGroupTaskFunction(GroupModificationType.UNGROUP_ALL_TASKS, groupIndex, taskIndex)),
|
|
7
7
|
SPLIT_TASK: getMenuItem('split', 'Remove from parallel group', ()=>reGroupTaskFunction(GroupModificationType.SPLIT_GROUP, groupIndex, taskIndex)),
|
|
8
8
|
REMOVE_GROUP: getMenuItem('remove-group', 'Remove group from stage', ()=>reGroupTaskFunction(GroupModificationType.REMOVE_GROUP, groupIndex, taskIndex)),
|
|
@@ -56,4 +56,4 @@ const transformMenuItems = (menuItems, onItemClick)=>{
|
|
|
56
56
|
};
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
|
-
export { getContextMenuItems, getMenuItem, transformMenuItems };
|
|
59
|
+
export { getContextMenuItems, getDivider, getMenuItem, transformMenuItems };
|
|
@@ -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
|