Skip to content

Commit 829dc94

Browse files
committed
Added fields for bounds properties.
If label is undefined then we use the id as label. Now making sure parsed nodes have unique ids.
1 parent 43f9956 commit 829dc94

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/dgmlParser.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,16 @@ export class DgmlParser {
101101
if (newNode.category === undefined) {
102102
newNode.category = this.createCategoryRef(xmlNode);
103103
}
104-
nodes.push(newNode);
104+
if (attributesCopy['bounds'] !== undefined && attributesCopy['bounds'].indexOf(',') !== -1) {
105+
const bounds = attributesCopy['bounds'].split(',');
106+
newNode.boundsX = +bounds[0];
107+
newNode.boundsY = +bounds[1];
108+
newNode.boundsWidth = +bounds[2];
109+
newNode.boundsHeight = +bounds[3];
110+
}
111+
if (nodes.filter(n => n.id === newNode.id).length === 0) {
112+
nodes.push(newNode);
113+
}
105114
}
106115
});
107116
}

src/model/Node.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export class Node {
2929
public maxWidth: number | undefined;
3030
public nodeRadius: number | undefined;
3131
// CodeSchemaAttributes - Not included
32+
// Visual Studio generated properties
33+
public boundsX: number | undefined;
34+
public boundsY: number | undefined;
35+
public boundsWidth: number | undefined;
36+
public boundsHeight: number | undefined;
3237

3338
private categoryRef: ICategory | undefined;
3439
public setCategoryRef(categoryRef: ICategory | undefined) {
@@ -39,7 +44,11 @@ export class Node {
3944
const jsStringProperties: string[] = [];
4045
if (this.id !== undefined) { jsStringProperties.push(`id: "${this.id}"`); }
4146
const label = this.convertNewlines(this.label);
42-
if (this.label !== undefined) { jsStringProperties.push(`label: "${label}"`); }
47+
if (this.label !== undefined) {
48+
jsStringProperties.push(`label: "${label}"`);
49+
} else {
50+
jsStringProperties.push(`label: "${this.id}"`);
51+
}
4352
const description = this.convertNewlines(this.description);
4453
if (this.description !== undefined) { jsStringProperties.push(`title: "${description}"`); }
4554
if (this.strokeThickness !== undefined) { jsStringProperties.push(`borderWidth: "${this.strokeThickness}"`); }
@@ -49,11 +58,12 @@ export class Node {
4958
if (this.categoryRef !== undefined && this.background === undefined && this.categoryRef.background !== undefined) { jsStringColorProperties.push(`background: "${this.categoryRef.background}"`); }
5059
if (this.categoryRef !== undefined && this.stroke === undefined && this.categoryRef.stroke !== undefined) { jsStringColorProperties.push(`border: "${this.categoryRef.stroke}"`); }
5160
if (jsStringColorProperties.length > 0) { jsStringProperties.push(`color: { ${jsStringColorProperties.join(', ')} }`); }
61+
if (this.boundsX !== undefined && this.boundsY !== undefined) { jsStringProperties.push(`x: ${this.boundsX}, y: ${this.boundsY}, fixed: { x: true, y: true}`); }
5262
return `{${jsStringProperties.join(', ')}}`;
5363
}
5464

5565
private convertNewlines(text: string | undefined): string {
56-
if(text === undefined) {
66+
if(text === undefined || text.length === 0) {
5767
return '';
5868
}
5969
text = text.replace('
', '\\n');

0 commit comments

Comments
 (0)