Skip to content

Commit 522b7a0

Browse files
committed
wip
1 parent 598aed4 commit 522b7a0

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/components/Graph/utils.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import type {TBlock, TConnection, TGraphConfig} from '@gravity-ui/graph';
2+
import type {Data, GraphNode, Options, Shapes} from '@gravity-ui/paranoid';
3+
import type {ElkExtendedEdge, ElkNode} from 'elkjs';
4+
5+
export const prepareChildren = (blocks: TGraphConfig['blocks']) => {
6+
return blocks?.map((b) => {
7+
return {
8+
id: b.id as string,
9+
width: b.width,
10+
height: b.height,
11+
ports: [
12+
{
13+
id: `port_${b.id as string}`,
14+
},
15+
],
16+
// properties: {
17+
// 'elk.portConstraints': 'FIXED_ORDER',
18+
// // 'elk.spacing.portPort': '0',
19+
// },
20+
} satisfies ElkNode;
21+
});
22+
};
23+
24+
export const prepareEdges = (connections: TGraphConfig['connections'], skipLabels?: boolean) => {
25+
return connections?.map((c, i) => {
26+
const labelText = `label ${i}`;
27+
28+
return {
29+
id: c.id as string,
30+
sources: [`port_${c.sourceBlockId as string}`],
31+
// sources: [c.sourceBlockId as string],
32+
targets: [c.targetBlockId as string],
33+
// labels: skipLabels ? [] : [{text: labelText, width: 50, height: 14}],
34+
} satisfies ElkExtendedEdge;
35+
});
36+
};
37+
38+
export const prepareBlocks = (nodes: Data['nodes']): TBlock[] => {
39+
return nodes?.map(({data: {id, name, ...rest}}) => ({
40+
id: String(id),
41+
name,
42+
width: 200,
43+
height: 100,
44+
...rest,
45+
}));
46+
};
47+
48+
export const prepareConnections = (links: Data['links']): TConnection[] => {
49+
return links?.map(({from, to}) => ({
50+
id: `${from}:${to}`,
51+
sourceBlockId: from,
52+
targetBlockId: to,
53+
}));
54+
};

0 commit comments

Comments
 (0)