Skip to content

Commit 5689e36

Browse files
Tweak comment creation
1 parent a98130f commit 5689e36

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

libs/envi/modeler/src/lib/create-envi-modeler-workflow.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { ENVIModelerEdge, ENVIModelerNode } from '@idl/types/envi/modeler';
44
import {
55
LAYOUT_BASE_X,
66
LAYOUT_BASE_Y,
7-
LAYOUT_COMMENT_Y_OFFSET,
87
} from './create-envi-modeler-workflow.interface';
98
import { InjectAggregatorNodes } from './helpers/add-aggregator-nodes';
9+
import { AddCommentNodes } from './helpers/add-comment-nodes';
1010
import { BuildIdMap } from './helpers/build-id-map';
1111
import { BuildNodeJSON } from './helpers/build-node-json';
1212
import { ComputeLayout } from './helpers/compute-layout';
@@ -45,22 +45,8 @@ export function CreateENVIModelerWorkflow(
4545
return BuildNodeJSON(node, modelName, location, registry);
4646
});
4747

48-
// Synthesize comment nodes from node.comment properties
49-
let commentCounter = 0;
50-
for (const node of injected.nodes) {
51-
if (node.comment) {
52-
const rawLocation = layout.get(node.id);
53-
const parentX = rawLocation ? rawLocation[0] : LAYOUT_BASE_X;
54-
const parentY = rawLocation ? rawLocation[1] : LAYOUT_BASE_Y;
55-
commentCounter++;
56-
modelNodes.push({
57-
display_name: node.comment,
58-
location: [parentX, parentY + LAYOUT_COMMENT_Y_OFFSET],
59-
name: `comment_${commentCounter}`,
60-
type: 'comment',
61-
});
62-
}
63-
}
48+
// automatically add in comment nodes
49+
AddCommentNodes(injected.nodes, modelNodes, layout);
6450

6551
// Build edges array
6652
const modelEdges = injected.edges.map((edge) => ({
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ENVIModelerNode } from '@idl/types/mcp';
2+
3+
import {
4+
LAYOUT_BASE_X,
5+
LAYOUT_BASE_Y,
6+
LAYOUT_COMMENT_Y_OFFSET,
7+
} from '../create-envi-modeler-workflow.interface';
8+
9+
/**
10+
* Add comment nodes into the ENVI Modeler Nodes
11+
*/
12+
export function AddCommentNodes(
13+
inputNodes: ENVIModelerNode[],
14+
modelNodes: { [key: string]: any }[],
15+
layout: Map<string, [number, number]>,
16+
) {
17+
// Synthesize comment nodes from node.comment properties
18+
let commentCounter = 0;
19+
for (const node of inputNodes) {
20+
if (node.comment) {
21+
const rawLocation = layout.get(node.id);
22+
const parentX = rawLocation ? rawLocation[0] : LAYOUT_BASE_X;
23+
const parentY = rawLocation ? rawLocation[1] : LAYOUT_BASE_Y;
24+
commentCounter++;
25+
modelNodes.push({
26+
display_name: node.comment,
27+
location: [parentX, parentY + LAYOUT_COMMENT_Y_OFFSET],
28+
name: `comment_${commentCounter}`,
29+
type: 'comment',
30+
});
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)