Skip to content

Commit

Permalink
Merge pull request #1 from kaishuu0123/feat/node_table_edge-style
Browse files Browse the repository at this point in the history
Graph Style Change(like rails-erd)
  • Loading branch information
kaishuu0123 committed Jan 19, 2018
2 parents 381ebdb + 5af056e commit 21821ae
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 186 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ depend:

bindata:
go-bindata -o=templates_bindata.go ./templates/...

examples: build
cat examples/simple.er | ./erd-go -o examples/outputs/simple.dot
cat examples/simple.er | ./erd-go | dot -Tpng -o examples/outputs/simple.png
cat examples/nfldb.er | ./erd-go -o examples/outputs/nfldb.dot
cat examples/nfldb.er | ./erd-go | dot -Tpng -o examples/outputs/nfldb.png
315 changes: 194 additions & 121 deletions examples/outputs/nfldb.dot

Large diffs are not rendered by default.

Binary file modified examples/outputs/nfldb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 57 additions & 33 deletions examples/outputs/simple.dot
Original file line number Diff line number Diff line change
@@ -1,66 +1,90 @@
graph {
graph [
label=<<FONT POINT-SIZE="20"><no value></FONT>>,
labeljust=l,
labelloc=t,
graph [nodesep=0.5,
ranksep=0.5,
pad="0.2,0.2",
margin="0.0",
cencentrate=true,
splines="spline",
rankdir=LR
];
node [
label="\N",
shape=plaintext
fontsize=14,
margin="0.07,0.05",
penwidth=1.0,
shape=Mrecord
];
edge [
color=gray50,
minlen=2,
style=dashed
dir=both,
fontsize=12,
arrowsize=0.9,
penwidth=1.0,
labelangle=32,
labeldistance=1.8
];


Person -- Location [headlabel=<<FONT>0..N</FONT>>,taillabel=<<FONT>1</FONT>>];
Person -- Location [arrowhead=noneotee,headlabel=<<FONT>1</FONT>>,arrowtail=ocrow,taillabel=<<FONT>0..N</FONT>>];


Location [label=<<FONT FACE="Helvetica">
<TABLE
BORDER="0" CELLBORDER="1"
CELLPADDING="4"
CELLSPACING="0">
Location [label=<<TABLE
BORDER="0"
CELLPADDING="0"
CELLSPACING="0.5"
WIDTH="134"
ALIGN="CENTER"
>
<TR>
<TD><FONT POINT-SIZE="16" FACE="Helvetica bold">Location</FONT></TD>
<TD ALIGN="CENTER" VALIGN="BOTTOM" WIDTH="134"><FONT POINT-SIZE="14" FACE="Helvetica bold"><B>Location</B></FONT></TD>
</TR>
</TABLE>|
<TABLE
BORDER="0"
ALIGN="LEFT"
CELLPADDING="0"
CELLSPACING="4"
WIDTH="134">
<TR>
<TD ALIGN="LEFT"><FONT>*id</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">*id</FONT></TD>
</TR>
<TR>
<TD ALIGN="LEFT"><FONT>city</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">city</FONT></TD>
</TR>
<TR>
<TD ALIGN="LEFT"><FONT>state</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">state</FONT></TD>
</TR>
<TR>
<TD ALIGN="LEFT"><FONT>country</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">country</FONT></TD>
</TR>
</TABLE>
</FONT>>];
Person [label=<<FONT FACE="Helvetica">
<TABLE
BORDER="0" CELLBORDER="1"
CELLPADDING="4"
CELLSPACING="0">
</TABLE>>];
Person [label=<<TABLE
BORDER="0"
CELLPADDING="0"
CELLSPACING="0.5"
WIDTH="134"
ALIGN="CENTER"
>
<TR>
<TD><FONT POINT-SIZE="16" FACE="Helvetica bold">Person</FONT></TD>
<TD ALIGN="CENTER" VALIGN="BOTTOM" WIDTH="134"><FONT POINT-SIZE="14" FACE="Helvetica bold"><B>Person</B></FONT></TD>
</TR>
</TABLE>|
<TABLE
BORDER="0"
ALIGN="LEFT"
CELLPADDING="0"
CELLSPACING="4"
WIDTH="134">
<TR>
<TD ALIGN="LEFT"><FONT>*name</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">*name</FONT></TD>
</TR>
<TR>
<TD ALIGN="LEFT"><FONT>height</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">height</FONT></TD>
</TR>
<TR>
<TD ALIGN="LEFT"><FONT>weight</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">weight</FONT></TD>
</TR>
<TR>
<TD ALIGN="LEFT"><FONT>+birth_location_id</FONT></TD>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">+birth_location_id</FONT></TD>
</TR>
</TABLE>
</FONT>>];
</TABLE>>];
}
Binary file modified examples/outputs/simple.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions templates/dot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ graph {
labeljust=l,
labelloc=t,
{{- end -}}
nodesep=0.5,
ranksep=0.5,
pad="0.2,0.2",
margin="0.0",
cencentrate=true,
splines="spline",
rankdir=LR
];
node [
label="\N",
shape=plaintext
fontsize=14,
margin="0.07,0.05",
penwidth=1.0,
shape=Mrecord
];
edge [
color=gray50,
minlen=2,
style=dashed
dir=both,
fontsize=12,
arrowsize=0.9,
penwidth=1.0,
labelangle=32,
labeldistance=1.8
];
{{template "dot_relations" .}}
{{template "dot_tables" .}}
Expand Down
20 changes: 10 additions & 10 deletions templates/dot_relations.tmpl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{{define "dot_relations"}}
{{range .Relations}}
{{.LeftTableName}} -- {{.RightTableName}} [
{{- if (eq .LeftCardinality "*") -}}
headlabel=<<FONT>0..N</FONT>>,
{{- else if (eq .LeftCardinality "+")}}
headlabel=<<FONT>1..N</FONT>>,
{{- if (eq .RightCardinality "*") -}}
arrowhead=ocrow,headlabel=<<FONT>0..N</FONT>>,
{{- else if (eq .RightCardinality "+")}}
arrowhead=ocrowtee,headlabel=<<FONT>1..N</FONT>>,
{{- else -}}
headlabel=<<FONT>{{.LeftCardinality}}</FONT>>,
arrowhead=noneotee,headlabel=<<FONT>{{.RightCardinality}}</FONT>>,
{{- end -}}
{{- if .RelationAttributes.label -}}
label=<<FONT>{{.RelationAttributes.label}}</FONT>>,
{{- end -}}
{{- if (eq .RightCardinality "*") -}}
taillabel=<<FONT>0..N</FONT>>,
{{- else if (eq .RightCardinality "+")}}
taillabel=<<FONT>1..N</FONT>>,
{{- if (eq .LeftCardinality "*") -}}
arrowtail=ocrow,taillabel=<<FONT>0..N</FONT>>
{{- else if (eq .LeftCardinality "+")}}
arrowtail=ocrowtee,taillabel=<<FONT>1..N</FONT>>
{{- else -}}
taillabel=<<FONT>{{.RightCardinality}}</FONT>>
arrowtail=noneotee,taillabel=<<FONT>{{.LeftCardinality}}</FONT>>
{{- end -}}
];
{{- end -}}
Expand Down
36 changes: 24 additions & 12 deletions templates/dot_tables.tmpl
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
{{define "dot_tables"}}
{{range $tk, $t := .Tables}}
{{.Title}} [label=<<FONT FACE="Helvetica">
<TABLE
BORDER="0" CELLBORDER="1"
CELLPADDING="4"
CELLSPACING="0"
{{- if .TableAttributes.bgcolor}}
BGCOLOR="{{.TableAttributes.bgcolor}}"
{{- end -}}
{{.Title}} [label=<<TABLE
BORDER="0"
CELLPADDING="0"
CELLSPACING="0.5"
WIDTH="134"
ALIGN="CENTER"
>
<TR>
<TD><FONT POINT-SIZE="16" FACE="Helvetica bold"><B>{{.Title}}</B></FONT></TD>
<TD ALIGN="CENTER" VALIGN="BOTTOM" WIDTH="134"><FONT POINT-SIZE="14" FACE="Helvetica bold"><B>{{.Title}}</B></FONT></TD>
</TR>
</TABLE>
{{- if .Columns -}}
|
<TABLE
BORDER="0"
ALIGN="LEFT"
CELLPADDING="0"
CELLSPACING="4"
WIDTH="134">
{{- range $k, $c := .Columns}}
<TR>
<TD ALIGN="LEFT"><FONT>{{.Title}}</FONT>
<TD ALIGN="LEFT"><FONT POINT-SIZE="12">{{.Title}}</FONT>
{{- if .ColumnAttributes.label -}}
<FONT> [{{.ColumnAttributes.label}}]</FONT>
<FONT FACE="Arial Italic" POINT-SIZE="10" COLOR="grey60"> [{{.ColumnAttributes.label}}]</FONT>
{{- end -}}
</TD>
</TR>
{{- end}}
</TABLE>
</FONT>>];
{{- end -}}>
{{- if .TableAttributes.bgcolor}}
,fillcolor="{{.TableAttributes.bgcolor}}",
style=filled
{{- end -}}
];
{{- end -}}
{{- end -}}
12 changes: 6 additions & 6 deletions templates_bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 21821ae

Please sign in to comment.