Skip to content

Commit 45601e5

Browse files
committed
wip read text representation from ocif
1 parent bbb705c commit 45601e5

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

apps/vps-web/src/app/custom-nodes/classes/rect-node-class.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ w-min h-min
4040
getElement={(element: HTMLElement) => {
4141
this.rectElement = element;
4242
}}
43-
class={`rounded`}
43+
class={`rounded flex justify-center items-center text-center`}
4444
style={`width:${node.width ?? 50}px;height:${
4545
node.height ?? 50
4646
}px;background:${nodeInfo?.fillColor ?? 'black'};border: ${
47-
nodeInfo?.strokeWidth ?? '2px'
48-
} ${nodeInfo?.strokeColor ?? 'white'} solid`}
49-
></div>
47+
nodeInfo?.strokeWidth ?? '2'
48+
}px ${nodeInfo?.strokeColor ?? 'white'} solid;color:${
49+
nodeInfo?.strokeColor ?? 'white'
50+
}`}
51+
>
52+
{nodeInfo?.text ?? ''}
53+
</div>
5054
</div>
5155
);
5256
};

libs/app-canvas/src/app/importers/ocif-importer.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ function getConnectionInfoFromOCIFNode(node: any): any | false {
7171
return false;
7272
}
7373

74+
export const getResourceById = (ocif: any, resourceId: string) => {
75+
if (!ocif.resources || !resourceId) {
76+
return undefined;
77+
}
78+
return ocif.resources.find((r: any) => r.id === resourceId);
79+
};
80+
81+
export const getTextRepresentation = (resource: any): string | false => {
82+
if (!resource || !resource.representations) {
83+
return false;
84+
}
85+
return (
86+
resource.representations.find((r: any) => r['mime-type'] === 'text/plain')
87+
?.content ?? false
88+
);
89+
};
90+
7491
export const importOCIF = (ocif: any) => {
7592
rootOCIF = ocif;
7693
const flow: Flow<NodeInfo> = {
@@ -112,6 +129,14 @@ export const importOCIF = (ocif: any) => {
112129
}
113130
} else if (node.data && isSupportedOCIFNode(node)) {
114131
const data = getExtenstionData(node, 'rect-node');
132+
let text = '';
133+
const resource = getResourceById(ocif, node.resource);
134+
if (resource) {
135+
const textRepresentation = getTextRepresentation(resource);
136+
if (textRepresentation) {
137+
text = textRepresentation;
138+
}
139+
}
115140
flow.flows['flow'].nodes.push({
116141
id: node.id,
117142
x: node.position[0],
@@ -124,10 +149,19 @@ export const importOCIF = (ocif: any) => {
124149
strokeColor: data?.strokeColor ?? 'black',
125150
fillColor: data?.fillColor ?? 'white',
126151
strokeWidth: data?.strokeWidth ?? 2,
152+
text: text,
127153
} as any,
128154
});
129155
console.log('ocif node size', node.size);
130156
} else if (!node.data) {
157+
let text = '';
158+
const resource = getResourceById(ocif, node.resource);
159+
if (resource) {
160+
const textRepresentation = getTextRepresentation(resource);
161+
if (textRepresentation) {
162+
text = textRepresentation;
163+
}
164+
}
131165
flow.flows['flow'].nodes.push({
132166
id: node.id,
133167
x: node.position[0],
@@ -140,6 +174,7 @@ export const importOCIF = (ocif: any) => {
140174
strokeColor: 'black',
141175
fillColor: 'white',
142176
strokeWidth: 2,
177+
text: text,
143178
} as any,
144179
});
145180
}

0 commit comments

Comments
 (0)