Building Class object using CSV Import

773 views
Skip to first unread message

Joel Berg

unread,
Aug 6, 2022, 5:00:26 PM8/6/22
to diagrams.net Q&A
Hello diagrams.net users,

I am trying to reverse engineer my class architecture to create a UML and I've come across diagrams.net, which looked encouraging. Creating a CSV file of my classes properties is easy enough, but I cannot find a way to import that into diagrams.net to build class diagrams.

If I create a "class" object using swimlane and and "attribute" object using text shape. Then, from the drawio canvas I can simply move the attribute into the class. Very nice.

However, I need to do this programmatically. I notice that the parent property of mxCell updated to the class object when I slid the text into the class object. 

I can set the parent of the attribute object, but apparently not the parent of the mxCell that is created.

If I do set the attribute's parent to the class object, the the class object is messed up. The figure below shows the messed up version (top half) and the desired version although without the text objects embedded in the class (lower half)

Here is the code to produce those examples.

## Reverse Engineer UML using CSV import
#
# identity: id
# namespace: csvimport-
#
## Label types
# labelname: labeltype
# labels: {\
# "classlabel" : "%name%<br><i style=\u0022color:gray;\u0022>%super%</i>",\
# "pubattlabel" : "+ %name%"}
#
## Shapes and their styles
# stylename: type
# styles: {\
# "class": "swimlane;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;horizontalStack=0;resizeParent=1;collapsible=1;marginBottom=0;rounded=1;fontSize=15;fillColor=#80FF00;labelBackgroundColor=#80FF00;labelBorderColor=none;startSize=50;html=1;",\
# "attribute": "text;"}
#
# parent: Parent
# width: @wid
# height: @ht
# padding: 5
# nodespacing: 20
# levelspacing: 30
# edgespacing: 40
# ignore: labeltype,wid,ht
#
## **********************************************************
## CSV Data
## **********************************************************
## ---- CSV below this line. First line are column names. ----
id,type,name,labeltype,super,Parent,wid,ht
1,class,Pipeline,classlabel,mySuper,,200,300
2,attribute,att1,pubattlabel,,1,80,40
3,attribute,att2,pubattlabel,,csvimport-1,80,30
11,class,Pipeline,classlabel,mySuper,,200,300
12,attribute,att3,pubattlabel,,,80,30
13,attribute,att4,pubattlabel,,csvimport-11,80,40
2022-08-06_16-57-41.png

Joel Berg

unread,
Aug 8, 2022, 8:07:08 AM8/8/22
to diagrams.net Q&A
Looks like a newbie issue. I solved the problem by setting parentstyle.

## Reverse Engineer UML using CSV import
#
# identity: id
# namespace: csvimport-
#
## Label types
# labelname: labeltype
# labels: {\
# "classlabel" : "%name%<br><i style=\u0022color:gray;\u0022>%super%</i>",\
# "pubattlabel" : "+ %name%"}
#
## Shapes and their styles
# stylename: type
# styles: {\
# "class": "swimlane;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;horizontalStack=0;resizeParent=1;collapsible=1;marginBottom=0;rounded=1;fontSize=15;fillColor=#80FF00;labelBackgroundColor=#80FF00;labelBorderColor=none;startSize=50;html=1;",\
# "attribute": "text;"}
#
# parentstyle:shape=swimlane;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;horizontalStack=0;resizeParent=1;collapsible=1;marginBottom=0;rounded=1;fontSize=15;fillColor=#80FF00;labelBackgroundColor=#80FF00;labelBorderColor=none;startSize=50;html=1;
# parent: Parent
# width: @wid
# height: @ht
# padding: 5
# nodespacing: 20
# levelspacing: 30
# edgespacing: 40
# ignore: labeltype,wid,ht
#
## **********************************************************
## CSV Data
## **********************************************************
## ---- CSV below this line. First line are column names. ----
id,type,name,labeltype,super,Parent,wid,ht
1,class,Pipeline,classlabel,mySuper,,200,300
2,attribute,att1,pubattlabel,,1,80,40
3,attribute,att2,pubattlabel,,1,80,30
Reply all
Reply to author
Forward
0 new messages