Codebase list golang-github-awalterschulze-gographviz / dd06a2d
New upstream version 2.0.1 Utkarsh Gupta 4 years ago
17 changed file(s) with 687 addition(s) and 186 deletion(s). Raw diff Collapse all Expand all
66 language: go
77
88 go:
9 - 1.8
9 - 1.x
11 Walter Schulze <awalterschulze@gmail.com>
22 Xuanyi Chew <chewxy@gmail.com>
33 Nathan Kitchen <nathan.kitchen@gmail.com>
4 Ruud Kamphuis <https://github.com/ruudk>
3131 - [aptly](https://github.com/smira/aptly) - Debian repository management tool
3232 - [gorgonia](https://github.com/chewxy/gorgonia) - A Library that helps facilitate machine learning in Go
3333 - [imagemonkey](https://imagemonkey.io/graph?editor=true) - Let's create our own image dataset
34 - [depviz](https://github.com/moul/depviz) - GitHub dependency visualizer (auto-roadmap)
35 - [kustomize-graph](https://github.com/jpreese/kustomize-graph) - A tool to visualize Kustomize dependencies
3436
3537 ### Mentions ###
3638
2020 "math/rand"
2121 "sort"
2222 "strings"
23 "sync"
2324
2425 "github.com/awalterschulze/gographviz/internal/token"
2526 )
2627
2728 var (
28 r = rand.New(rand.NewSource(1234))
29 r = rand.New(rand.NewSource(1234))
30 randLock sync.Mutex
2931 )
3032
3133 type Visitor interface {
182184 StmtList StmtList
183185 }
184186
185 func NewSubGraph(id, l Attrib) (*SubGraph, error) {
186 g := &SubGraph{ID: ID(fmt.Sprintf("anon%d", r.Int63()))}
187 if id != nil {
188 if len(id.(ID)) > 0 {
189 g.ID = id.(ID)
190 }
187 func NewSubGraph(maybeId, l Attrib) (*SubGraph, error) {
188 g := &SubGraph{}
189 if id, ok := maybeId.(ID); maybeId == nil || (ok && len(id) == 0) {
190 g.ID = ID(fmt.Sprintf("anon%d", randInt63()))
191 } else if ok && (len(id) > 0) {
192 g.ID = id
193 } else {
194 return nil, fmt.Errorf("expected maybeId.(ID) got=%v", maybeId)
191195 }
192196 if l != nil {
193197 g.StmtList = l.(StmtList)
194198 }
195199 return g, nil
200 }
201
202 func randInt63() int64 {
203 randLock.Lock()
204 result := r.Int63()
205 randLock.Unlock()
206 return result
196207 }
197208
198209 func (this *SubGraph) GetID() ID {
+170
-170
attr.go less more
2828 }
2929
3030 const (
31 // Damping http://www.graphviz.org/content/attrs#dDamping
31 // Damping http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:Damping
3232 Damping Attr = "Damping"
33 // K http://www.graphviz.org/content/attrs#dK
33 // K http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:K
3434 K Attr = "K"
35 // URL http://www.graphviz.org/content/attrs#dURL
35 // URL http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:URL
3636 URL Attr = "URL"
37 // Background http://www.graphviz.org/content/attrs#d_background
37 // Background http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:_background
3838 Background Attr = "_background"
39 // Area http://www.graphviz.org/content/attrs#darea
39 // Area http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:area
4040 Area Attr = "area"
41 // ArrowHead http://www.graphviz.org/content/attrs#darrowhead
41 // ArrowHead http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:arrowhead
4242 ArrowHead Attr = "arrowhead"
43 // ArrowSize http://www.graphviz.org/content/attrs#darrowsize
43 // ArrowSize http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:arrowsize
4444 ArrowSize Attr = "arrowsize"
45 // ArrowTail http://www.graphviz.org/content/attrs#darrowtail
45 // ArrowTail http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:arrowtail
4646 ArrowTail Attr = "arrowtail"
47 // BB http://www.graphviz.org/content/attrs#dbb
47 // BB http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:bb
4848 BB Attr = "bb"
49 // BgColor http://www.graphviz.org/content/attrs#dbgcolor
49 // BgColor http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:bgcolor
5050 BgColor Attr = "bgcolor"
51 // Center http://www.graphviz.org/content/attrs#dcenter
51 // Center http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:center
5252 Center Attr = "center"
53 // Charset http://www.graphviz.org/content/attrs#dcharset
53 // Charset http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:charset
5454 Charset Attr = "charset"
55 // ClusterRank http://www.graphviz.org/content/attrs#dclusterrank
55 // ClusterRank http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:clusterrank
5656 ClusterRank Attr = "clusterrank"
57 // Color http://www.graphviz.org/content/attrs#dcolor
57 // Color http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:color
5858 Color Attr = "color"
59 // ColorScheme http://www.graphviz.org/content/attrs#dcolorscheme
59 // ColorScheme http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:colorscheme
6060 ColorScheme Attr = "colorscheme"
61 // Comment http://www.graphviz.org/content/attrs#dcomment
61 // Comment http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:comment
6262 Comment Attr = "comment"
63 // Compound http://www.graphviz.org/content/attrs#dcompound
63 // Compound http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:compound
6464 Compound Attr = "compound"
65 // Concentrate http://www.graphviz.org/content/attrs#dconcentrate
65 // Concentrate http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:concentrate
6666 Concentrate Attr = "concentrate"
67 // Constraint http://www.graphviz.org/content/attrs#dconstraint
67 // Constraint http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:constraint
6868 Constraint Attr = "constraint"
69 // Decorate http://www.graphviz.org/content/attrs#ddecorate
69 // Decorate http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:decorate
7070 Decorate Attr = "decorate"
71 // DefaultDist http://www.graphviz.org/content/attrs#ddefaultdist
71 // DefaultDist http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:defaultdist
7272 DefaultDist Attr = "defaultdist"
73 // Dim http://www.graphviz.org/content/attrs#ddim
73 // Dim http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:dim
7474 Dim Attr = "dim"
75 // Dimen http://www.graphviz.org/content/attrs#ddimen
75 // Dimen http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:dimen
7676 Dimen Attr = "dimen"
77 // Dir http://www.graphviz.org/content/attrs#ddir
77 // Dir http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:dir
7878 Dir Attr = "dir"
79 // DirEdgeConstraints http://www.graphviz.org/content/attrs#ddir
79 // DirEdgeConstraints http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:dir
8080 DirEdgeConstraints Attr = "diredgeconstraints"
81 // Distortion http://www.graphviz.org/content/attrs#ddistortion
81 // Distortion http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:distortion
8282 Distortion Attr = "distortion"
83 // DPI http://www.graphviz.org/content/attrs#ddpi
83 // DPI http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:dpi
8484 DPI Attr = "dpi"
85 // EdgeURL http://www.graphviz.org/content/attrs#d:edgeURL
85 // EdgeURL http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d::edgeURL
8686 EdgeURL Attr = "edgeURL"
87 // EdgeHREF http://www.graphviz.org/content/attrs#d:edgehref
87 // EdgeHREF http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d::edgehref
8888 EdgeHREF Attr = "edgehref"
89 // EdgeTarget http://www.graphviz.org/content/attrs#d:edgetarget
89 // EdgeTarget http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d::edgetarget
9090 EdgeTarget Attr = "edgetarget"
91 // EdgeTooltip http://www.graphviz.org/content/attrs#d:edgetooltip
91 // EdgeTooltip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d::edgetooltip
9292 EdgeTooltip Attr = "edgetooltip"
93 // Epsilon http://www.graphviz.org/content/attrs#d:epsilon
93 // Epsilon http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d::epsilon
9494 Epsilon Attr = "epsilon"
95 // ESep http://www.graphviz.org/content/attrs#d:epsilon
95 // ESep http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d::epsilon
9696 ESep Attr = "esep"
97 // FillColor http://www.graphviz.org/content/attrs#dfillcolor
97 // FillColor http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fillcolor
9898 FillColor Attr = "fillcolor"
99 // FixedSize http://www.graphviz.org/content/attrs#dfixedsize
99 // FixedSize http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fixedsize
100100 FixedSize Attr = "fixedsize"
101 // FontColor http://www.graphviz.org/content/attrs#dfontcolor
101 // FontColor http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fontcolor
102102 FontColor Attr = "fontcolor"
103 // FontName http://www.graphviz.org/content/attrs#dfontname
103 // FontName http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fontname
104104 FontName Attr = "fontname"
105 // FontNames http://www.graphviz.org/content/attrs#dfontnames
105 // FontNames http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fontnames
106106 FontNames Attr = "fontnames"
107 // FontPath http://www.graphviz.org/content/attrs#dfontpath
107 // FontPath http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fontpath
108108 FontPath Attr = "fontpath"
109 // FontSize http://www.graphviz.org/content/attrs#dfontsize
109 // FontSize http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:fontsize
110110 FontSize Attr = "fontsize"
111 // ForceLabels http://www.graphviz.org/content/attrs#dforcelabels
111 // ForceLabels http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:forcelabels
112112 ForceLabels Attr = "forcelabels"
113 // GradientAngle http://www.graphviz.org/content/attrs#dgradientangle
113 // GradientAngle http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:gradientangle
114114 GradientAngle Attr = "gradientangle"
115 // Group http://www.graphviz.org/content/attrs#dgroup
115 // Group http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:group
116116 Group Attr = "group"
117 // HeadURL http://www.graphviz.org/content/attrs#dheadURL
117 // HeadURL http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headURL
118118 HeadURL Attr = "headURL"
119 // HeadLP http://www.graphviz.org/content/attrs#dhead_lp
119 // HeadLP http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:head_lp
120120 HeadLP Attr = "head_lp"
121 // HeadClip http://www.graphviz.org/content/attrs#dheadclip
121 // HeadClip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headclip
122122 HeadClip Attr = "headclip"
123 // HeadHREF http://www.graphviz.org/content/attrs#dheadhref
123 // HeadHREF http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headhref
124124 HeadHREF Attr = "headhref"
125 // HeadLabel http://www.graphviz.org/content/attrs#dheadlabel
125 // HeadLabel http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headlabel
126126 HeadLabel Attr = "headlabel"
127 // HeadPort http://www.graphviz.org/content/attrs#dheadport
127 // HeadPort http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headport
128128 HeadPort Attr = "headport"
129 // HeadTarget http://www.graphviz.org/content/attrs#dheadtarget
129 // HeadTarget http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headtarget
130130 HeadTarget Attr = "headtarget"
131 // HeadTooltip http://www.graphviz.org/content/attrs#dheadtooltip
131 // HeadTooltip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headtooltip
132132 HeadTooltip Attr = "headtooltip"
133 // Height http://www.graphviz.org/content/attrs#dheight
133 // Height http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:height
134134 Height Attr = "height"
135 // HREF http://www.graphviz.org/content/attrs#dhref
135 // HREF http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:href
136136 HREF Attr = "href"
137 // ID http://www.graphviz.org/content/attrs#did
137 // ID http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:id
138138 ID Attr = "id"
139 // Image http://www.graphviz.org/content/attrs#dimage
139 // Image http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:image
140140 Image Attr = "image"
141 // ImagePath http://www.graphviz.org/content/attrs#dimagepath
141 // ImagePath http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:imagepath
142142 ImagePath Attr = "imagepath"
143 // ImageScale http://www.graphviz.org/content/attrs#dimagescale
143 // ImageScale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:imagescale
144144 ImageScale Attr = "imagescale"
145 // InputScale http://www.graphviz.org/content/attrs#dinputscale
145 // InputScale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:inputscale
146146 InputScale Attr = "inputscale"
147 // Label http://www.graphviz.org/content/attrs#dlabel
147 // Label http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:label
148148 Label Attr = "label"
149 // LabelURL http://www.graphviz.org/content/attrs#dlabelURL
149 // LabelURL http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelURL
150150 LabelURL Attr = "labelURL"
151 // LabelScheme http://www.graphviz.org/content/attrs#dlabel_scheme
151 // LabelScheme http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:label_scheme
152152 LabelScheme Attr = "label_scheme"
153 // LabelAngle http://www.graphviz.org/content/attrs#dlabelangle
153 // LabelAngle http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelangle
154154 LabelAngle Attr = "labelangle"
155 // LabelDistance http://www.graphviz.org/content/attrs#dlabeldistance
155 // LabelDistance http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labeldistance
156156 LabelDistance Attr = "labeldistance"
157 // LabelFloat http://www.graphviz.org/content/attrs#dlabelfloat
157 // LabelFloat http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelfloat
158158 LabelFloat Attr = "labelfloat"
159 // LabelFontColor http://www.graphviz.org/content/attrs#dlabelfontcolor
159 // LabelFontColor http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelfontcolor
160160 LabelFontColor Attr = "labelfontcolor"
161 // LabelFontName http://www.graphviz.org/content/attrs#dlabelfontname
161 // LabelFontName http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelfontname
162162 LabelFontName Attr = "labelfontname"
163 // LabelFontSize http://www.graphviz.org/content/attrs#dlabelfontsize
163 // LabelFontSize http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelfontsize
164164 LabelFontSize Attr = "labelfontsize"
165 // LabelHREF http://www.graphviz.org/content/attrs#dlabelhref
165 // LabelHREF http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelhref
166166 LabelHREF Attr = "labelhref"
167 // LabelJust http://www.graphviz.org/content/attrs#dlabeljust
167 // LabelJust http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labeljust
168168 LabelJust Attr = "labeljust"
169 // LabelLOC http://www.graphviz.org/content/attrs#dlabelloc
169 // LabelLOC http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labelloc
170170 LabelLOC Attr = "labelloc"
171 // LabelTarget http://www.graphviz.org/content/attrs#dlabeltarget
171 // LabelTarget http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labeltarget
172172 LabelTarget Attr = "labeltarget"
173 // LabelTooltip http://www.graphviz.org/content/attrs#dlabeltooltip
173 // LabelTooltip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:labeltooltip
174174 LabelTooltip Attr = "labeltooltip"
175 // Landscape http://www.graphviz.org/content/attrs#dlandscape
175 // Landscape http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:landscape
176176 Landscape Attr = "landscape"
177 // Layer http://www.graphviz.org/content/attrs#dlayer
177 // Layer http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:layer
178178 Layer Attr = "layer"
179 // LayerListSep http://www.graphviz.org/content/attrs#dlayerlistsep
179 // LayerListSep http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:layerlistsep
180180 LayerListSep Attr = "layerlistsep"
181 // Layers http://www.graphviz.org/content/attrs#dlayers
181 // Layers http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:layers
182182 Layers Attr = "layers"
183 // LayerSelect http://www.graphviz.org/content/attrs#dlayerselect
183 // LayerSelect http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:layerselect
184184 LayerSelect Attr = "layerselect"
185 // LayerSep http://www.graphviz.org/content/attrs#dlayersep
185 // LayerSep http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:layersep
186186 LayerSep Attr = "layersep"
187 // Layout http://www.graphviz.org/content/attrs#dlayout
187 // Layout http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:layout
188188 Layout Attr = "layout"
189 // Len http://www.graphviz.org/content/attrs#dlen
189 // Len http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:len
190190 Len Attr = "len"
191 // Levels http://www.graphviz.org/content/attrs#dlevels
191 // Levels http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:levels
192192 Levels Attr = "levels"
193 // LevelsGap http://www.graphviz.org/content/attrs#dlevelsgap
193 // LevelsGap http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:levelsgap
194194 LevelsGap Attr = "levelsgap"
195 // LHead http://www.graphviz.org/content/attrs#dlhead
195 // LHead http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:lhead
196196 LHead Attr = "lhead"
197 // LHeight http://www.graphviz.org/content/attrs#dlheight
197 // LHeight http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:lheight
198198 LHeight Attr = "lheight"
199 // LP http://www.graphviz.org/content/attrs#dlp
199 // LP http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:lp
200200 LP Attr = "lp"
201 // LTail http://www.graphviz.org/content/attrs#dltail
201 // LTail http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:ltail
202202 LTail Attr = "ltail"
203 // LWidth http://www.graphviz.org/content/attrs#dlwidth
203 // LWidth http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:lwidth
204204 LWidth Attr = "lwidth"
205 // Margin http://www.graphviz.org/content/attrs#dmargin
205 // Margin http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:margin
206206 Margin Attr = "margin"
207 // MaxIter http://www.graphviz.org/content/attrs#dmaxiter
207 // MaxIter http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:maxiter
208208 MaxIter Attr = "maxiter"
209 // MCLimit http://www.graphviz.org/content/attrs#dmclimit
209 // MCLimit http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:mclimit
210210 MCLimit Attr = "mclimit"
211 // MinDist http://www.graphviz.org/content/attrs#dmindist
211 // MinDist http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:mindist
212212 MinDist Attr = "mindist"
213 // MinLen http://www.graphviz.org/content/attrs#dmindist
213 // MinLen http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:mindist
214214 MinLen Attr = "minlen"
215 // Mode http://www.graphviz.org/content/attrs#dmode
215 // Mode http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:mode
216216 Mode Attr = "mode"
217 // Model http://www.graphviz.org/content/attrs#dmodel
217 // Model http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:model
218218 Model Attr = "model"
219 // Mosek http://www.graphviz.org/content/attrs#dmosek
219 // Mosek http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:mosek
220220 Mosek Attr = "mosek"
221 // NewRank http://www.graphviz.org/content/attrs#dnewrank
221 // NewRank http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:newrank
222222 NewRank Attr = "newrank"
223 // NodeSep http://www.graphviz.org/content/attrs#dnodesep
223 // NodeSep http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:nodesep
224224 NodeSep Attr = "nodesep"
225 // NoJustify http://www.graphviz.org/content/attrs#dnojustify
225 // NoJustify http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:nojustify
226226 NoJustify Attr = "nojustify"
227 // Normalize http://www.graphviz.org/content/attrs#dnormalize
227 // Normalize http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:normalize
228228 Normalize Attr = "normalize"
229 // NoTranslate http://www.graphviz.org/content/attrs#dnotranslate
229 // NoTranslate http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:notranslate
230230 NoTranslate Attr = "notranslate"
231 // NSLimit http://www.graphviz.org/content/attrs#dnslimit
231 // NSLimit http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:nslimit
232232 NSLimit Attr = "nslimit"
233 // NSLimit1 http://www.graphviz.org/content/attrs#dnslimit1
233 // NSLimit1 http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:nslimit1
234234 NSLimit1 Attr = "nslimit1"
235 // Ordering http://www.graphviz.org/content/attrs#dnslimit1
235 // Ordering http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:nslimit1
236236 Ordering Attr = "ordering"
237 // Orientation http://www.graphviz.org/content/attrs#dorientation
237 // Orientation http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:orientation
238238 Orientation Attr = "orientation"
239 // OutputOrder http://www.graphviz.org/content/attrs#doutputorder
239 // OutputOrder http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:outputorder
240240 OutputOrder Attr = "outputorder"
241 // Overlap http://www.graphviz.org/content/attrs#doverlap
241 // Overlap http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:overlap
242242 Overlap Attr = "overlap"
243 // OverlapScaling http://www.graphviz.org/content/attrs#doverlap_scaling
243 // OverlapScaling http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:overlap_scaling
244244 OverlapScaling Attr = "overlap_scaling"
245 // OverlapShrink http://www.graphviz.org/content/attrs#doverlap_shrink
245 // OverlapShrink http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:overlap_shrink
246246 OverlapShrink Attr = "overlap_shrink"
247 // Pack http://www.graphviz.org/content/attrs#dpack
247 // Pack http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:pack
248248 Pack Attr = "pack"
249 // PackMode http://www.graphviz.org/content/attrs#dpackmode
249 // PackMode http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:packmode
250250 PackMode Attr = "packmode"
251 // Pad http://www.graphviz.org/content/attrs#dpad
251 // Pad http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:pad
252252 Pad Attr = "pad"
253 // Page http://www.graphviz.org/content/attrs#dpage
253 // Page http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:page
254254 Page Attr = "page"
255 // PageDir http://www.graphviz.org/content/attrs#dpagedir
255 // PageDir http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:pagedir
256256 PageDir Attr = "pagedir"
257 // PenColor http://www.graphviz.org/content/attrs#dpencolor
257 // PenColor http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:pencolor
258258 PenColor Attr = "pencolor"
259 // PenWidth http://www.graphviz.org/content/attrs#dpenwidth
259 // PenWidth http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:penwidth
260260 PenWidth Attr = "penwidth"
261 // Peripheries http://www.graphviz.org/content/attrs#dperipheries
261 // Peripheries http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:peripheries
262262 Peripheries Attr = "peripheries"
263 // Pin http://www.graphviz.org/content/attrs#dperipheries
263 // Pin http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:peripheries
264264 Pin Attr = "pin"
265 // Pos http://www.graphviz.org/content/attrs#dpos
265 // Pos http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:pos
266266 Pos Attr = "pos"
267 // QuadTree http://www.graphviz.org/content/attrs#dquadtree
267 // QuadTree http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:quadtree
268268 QuadTree Attr = "quadtree"
269 // Quantum http://www.graphviz.org/content/attrs#dquantum
269 // Quantum http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:quantum
270270 Quantum Attr = "quantum"
271 // Rank http://www.graphviz.org/content/attrs#drank
271 // Rank http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:rank
272272 Rank Attr = "rank"
273 // RankDir http://www.graphviz.org/content/attrs#drankdir
273 // RankDir http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:rankdir
274274 RankDir Attr = "rankdir"
275 // RankSep http://www.graphviz.org/content/attrs#dranksep
275 // RankSep http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:ranksep
276276 RankSep Attr = "ranksep"
277 // Ratio http://www.graphviz.org/content/attrs#dratio
277 // Ratio http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:ratio
278278 Ratio Attr = "ratio"
279 // Rects http://www.graphviz.org/content/attrs#drects
279 // Rects http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:rects
280280 Rects Attr = "rects"
281 // Regular http://www.graphviz.org/content/attrs#dregular
281 // Regular http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:regular
282282 Regular Attr = "regular"
283 // ReMinCross http://www.graphviz.org/content/attrs#dremincross
283 // ReMinCross http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:remincross
284284 ReMinCross Attr = "remincross"
285 // RepulsiveForce http://www.graphviz.org/content/attrs#drepulsiveforce
285 // RepulsiveForce http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:repulsiveforce
286286 RepulsiveForce Attr = "repulsiveforce"
287 // Resolution http://www.graphviz.org/content/attrs#dresolution
287 // Resolution http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:resolution
288288 Resolution Attr = "resolution"
289 // Root http://www.graphviz.org/content/attrs#droot
289 // Root http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:root
290290 Root Attr = "root"
291 // Rotate http://www.graphviz.org/content/attrs#drotate
291 // Rotate http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:rotate
292292 Rotate Attr = "rotate"
293 // Rotation http://www.graphviz.org/content/attrs#drotation
293 // Rotation http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:rotation
294294 Rotation Attr = "rotation"
295 // SameHead http://www.graphviz.org/content/attrs#dsamehead
295 // SameHead http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:samehead
296296 SameHead Attr = "samehead"
297 // SameTail http://www.graphviz.org/content/attrs#dsametail
297 // SameTail http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:sametail
298298 SameTail Attr = "sametail"
299 // SamplePoints http://www.graphviz.org/content/attrs#dsamplepoints
299 // SamplePoints http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:samplepoints
300300 SamplePoints Attr = "samplepoints"
301 // Scale http://www.graphviz.org/content/attrs#dscale
301 // Scale http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:scale
302302 Scale Attr = "scale"
303 // SearchSize http://www.graphviz.org/content/attrs#dsearchsize
303 // SearchSize http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:searchsize
304304 SearchSize Attr = "searchsize"
305 // Sep http://www.graphviz.org/content/attrs#dsep
305 // Sep http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:sep
306306 Sep Attr = "sep"
307 // Shape http://www.graphviz.org/content/attrs#dshape
307 // Shape http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:shape
308308 Shape Attr = "shape"
309 // ShapeFile http://www.graphviz.org/content/attrs#dshapefile
309 // ShapeFile http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:shapefile
310310 ShapeFile Attr = "shapefile"
311 // ShowBoxes http://www.graphviz.org/content/attrs#dshowboxes
311 // ShowBoxes http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:showboxes
312312 ShowBoxes Attr = "showboxes"
313 // Sides http://www.graphviz.org/content/attrs#dsides
313 // Sides http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:sides
314314 Sides Attr = "sides"
315 // Size http://www.graphviz.org/content/attrs#dsize
315 // Size http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:size
316316 Size Attr = "size"
317 // Skew http://www.graphviz.org/content/attrs#dskew
317 // Skew http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:skew
318318 Skew Attr = "skew"
319 // Smoothing http://www.graphviz.org/content/attrs#dsmoothing
319 // Smoothing http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:smoothing
320320 Smoothing Attr = "smoothing"
321 // SortV http://www.graphviz.org/content/attrs#dsortv
321 // SortV http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:sortv
322322 SortV Attr = "sortv"
323 // Splines http://www.graphviz.org/content/attrs#dsplines
323 // Splines http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:splines
324324 Splines Attr = "splines"
325 // Start http://www.graphviz.org/content/attrs#dstart
325 // Start http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:start
326326 Start Attr = "start"
327 // Style http://www.graphviz.org/content/attrs#dstyle
327 // Style http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:style
328328 Style Attr = "style"
329 // StyleSheet http://www.graphviz.org/content/attrs#dstylesheet
329 // StyleSheet http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:stylesheet
330330 StyleSheet Attr = "stylesheet"
331 // TailURL http://www.graphviz.org/content/attrs#dtailURL
331 // TailURL http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tailURL
332332 TailURL Attr = "tailURL"
333 // TailLP http://www.graphviz.org/content/attrs#dtail_lp
333 // TailLP http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tail_lp
334334 TailLP Attr = "tail_lp"
335 // TailClip http://www.graphviz.org/content/attrs#dtailclip
335 // TailClip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tailclip
336336 TailClip Attr = "tailclip"
337 // TailHREF http://www.graphviz.org/content/attrs#dtailhref
337 // TailHREF http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tailhref
338338 TailHREF Attr = "tailhref"
339 // TailLabel http://www.graphviz.org/content/attrs#dtaillabel
339 // TailLabel http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:taillabel
340340 TailLabel Attr = "taillabel"
341 // TailPort http://www.graphviz.org/content/attrs#dtailport
341 // TailPort http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tailport
342342 TailPort Attr = "tailport"
343 // TailTarget http://www.graphviz.org/content/attrs#dtailtarget
343 // TailTarget http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tailtarget
344344 TailTarget Attr = "tailtarget"
345 // TailTooltip http://www.graphviz.org/content/attrs#dtailtooltip
345 // TailTooltip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tailtooltip
346346 TailTooltip Attr = "tailtooltip"
347 // Target http://www.graphviz.org/content/attrs#dtarget
347 // Target http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:target
348348 Target Attr = "target"
349 // Tooltip http://www.graphviz.org/content/attrs#dtooltip
349 // Tooltip http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tooltip
350350 Tooltip Attr = "tooltip"
351 // TrueColor http://www.graphviz.org/content/attrs#dtooltip
351 // TrueColor http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:tooltip
352352 TrueColor Attr = "truecolor"
353 // Vertices http://www.graphviz.org/content/attrs#dvertices
353 // Vertices http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:vertices
354354 Vertices Attr = "vertices"
355 // ViewPort http://www.graphviz.org/content/attrs#dviewport
355 // ViewPort http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:viewport
356356 ViewPort Attr = "viewport"
357 // VoroMargin http://www.graphviz.org/content/attrs#dvoro_margin
357 // VoroMargin http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:voro_margin
358358 VoroMargin Attr = "voro_margin"
359 // Weight http://www.graphviz.org/content/attrs#dweight
359 // Weight http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:weight
360360 Weight Attr = "weight"
361 // Width http://www.graphviz.org/content/attrs#dwidth
361 // Width http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:width
362362 Width Attr = "width"
363 // XDotVersion http://www.graphviz.org/content/attrs#dxdotversion
363 // XDotVersion http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:xdotversion
364364 XDotVersion Attr = "xdotversion"
365 // XLabel http://www.graphviz.org/content/attrs#dxlabel
365 // XLabel http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:xlabel
366366 XLabel Attr = "xlabel"
367 // XLP http://www.graphviz.org/content/attrs#dxlp
367 // XLP http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:xlp
368368 XLP Attr = "xlp"
369 // Z http://www.graphviz.org/content/attrs#dz
369 // Z http://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:z
370370 Z Attr = "z"
371371
372372 // MinCross is not in the documentation, but found in the Ped_Lion_Share (lion_share.gv.txt) example
1111 //See the License for the specific language governing permissions and
1212 //limitations under the License.
1313
14 //This bnf has been derived from http://www.graphviz.org/content/dot-language
14 //This bnf has been derived from https://graphviz.gitlab.io/_pages/doc/info/lang.html
1515 //The rules have been copied and are shown in the comments, with their derived bnf rules below.
1616
1717 // ### [ Tokens ] ##############################################################
7272 return false
7373 }
7474 if c == '-' {
75 return false
76 }
77 if c == '/' {
7578 return false
7679 }
7780 i++
4242 if err := g.AddEdge("kasdf99 99", "7", true, nil); err != nil {
4343 t.Fatal(err)
4444 }
45 if err := g.AddNode("asdf asdf", "a/b", nil); err != nil {
46 t.Fatal(err)
47 }
4548 s := g.String()
4649 if !strings.HasPrefix(s, `digraph "asdf adsf" {
4750 "kasdf99 99"->7;
4851 "a &lt;&lt; b";
52 "a/b";
4953 "kasdf99 99" [ URL="<a" ];
5054 7 [ URL="<a" ];
5155
9696 return nil
9797 }
9898
99 // RemoveNode removes a node from the graph
100 func (g *Graph) RemoveNode(parentGraph string, name string) error {
101 err := g.Nodes.Remove(name)
102 if err != nil {
103 return err
104 }
105
106 g.Relations.Remove(parentGraph, name)
107
108 edges := NewEdges()
109 for _, e := range g.Edges.Edges {
110 if e.Dst == name || e.Src == name {
111 continue
112 }
113
114 edges.Add(e)
115 }
116
117 g.Edges = edges
118
119 return nil
120 }
121
99122 func (g *Graph) getAttrs(graphName string) (Attrs, error) {
100123 if g.Name == graphName {
101124 return g.Attrs, nil
128151 return nil
129152 }
130153
154 // RemoveSubGraph removes the subgraph including nodes
155 func (g *Graph) RemoveSubGraph(parentGraph string, name string) error {
156 for child := range g.Relations.ParentToChildren[name] {
157 err := g.RemoveNode(parentGraph, child)
158 if err != nil {
159 return err
160 }
161 }
162
163 g.Relations.Remove(parentGraph, name)
164 g.SubGraphs.Remove(name)
165
166 edges := NewEdges()
167 for _, e := range g.Edges.Edges {
168 if e.Dst == name || e.DstPort == name || e.Src == name || e.SrcPort == name {
169 continue
170 }
171
172 edges.Add(e)
173 }
174
175 g.Edges = edges
176
177 return nil
178 }
179
131180 // IsNode returns whether a given node name exists as a node in the graph.
132181 func (g *Graph) IsNode(name string) bool {
133182 _, ok := g.Nodes.Lookup[name]
33 git clone https://github.com/goccmack/gocc $GOPATH/src/github.com/goccmack/gocc
44 go get golang.org/x/tools/cmd/goimports
55 go get github.com/kisielk/errcheck
6 go get -u github.com/golang/lint/golint
6 go get -u golang.org/x/lint/golint
22 package errors
33
44 import (
5 "bytes"
65 "fmt"
6 "strings"
77
88 "github.com/awalterschulze/gographviz/internal/token"
99 )
2020 }
2121
2222 func (e *Error) String() string {
23 w := new(bytes.Buffer)
23 w := new(strings.Builder)
2424 fmt.Fprintf(w, "Error")
2525 if e.Err != nil {
2626 fmt.Fprintf(w, " %s\n", e.Err)
4141 }
4242
4343 func (e *Error) Error() string {
44 w := new(bytes.Buffer)
44 w := new(strings.Builder)
4545 fmt.Fprintf(w, "Error in S%d: %s, %s", e.StackTop, token.TokMap.TokenString(e.ErrorToken), e.ErrorToken.Pos.String())
4646 if e.Err != nil {
4747 fmt.Fprintf(w, ": %+v", e.Err)
22 package parser
33
44 import (
5 "bytes"
65 "fmt"
6 "strings"
77
88 parseError "github.com/awalterschulze/gographviz/internal/errors"
99 "github.com/awalterschulze/gographviz/internal/token"
6565 }
6666
6767 func (s *stack) String() string {
68 w := new(bytes.Buffer)
68 w := new(strings.Builder)
6969 fmt.Fprintf(w, "stack:\n")
7070 for i, st := range s.state {
7171 fmt.Fprintf(w, "\t%d: %d , ", i, st)
1414 package gographviz
1515
1616 import (
17 "fmt"
1718 "sort"
1819 )
1920
3233 // NewNodes creates a new set of Nodes.
3334 func NewNodes() *Nodes {
3435 return &Nodes{make(map[string]*Node), make([]*Node, 0)}
36 }
37
38 // Remove removes a node
39 func (nodes *Nodes) Remove(name string) error {
40 for i := 0; i < len(nodes.Nodes); i++ {
41 if nodes.Nodes[i].Name != name {
42 continue
43 }
44
45 nodes.Nodes = append(nodes.Nodes[:i], nodes.Nodes[i+1:]...)
46 delete(nodes.Lookup, name)
47
48 return nil
49 }
50
51 return fmt.Errorf("node %s not found", name)
3552 }
3653
3754 // Add adds a Node to the set of Nodes, extending the attributes of an already existing node.
4141 relations.ChildToParents[child][parent] = true
4242 }
4343
44 // Remove removes relation
45 func (relations *Relations) Remove(parent string, child string) {
46 if _, ok := relations.ParentToChildren[parent]; ok {
47 delete(relations.ParentToChildren[parent], child)
48 }
49
50 if _, ok := relations.ChildToParents[child]; ok {
51 delete(relations.ChildToParents[child], parent)
52 }
53 }
54
4455 // SortedChildren returns a list of sorted children of the given parent graph.
4556 func (relations *Relations) SortedChildren(parent string) []string {
4657 keys := make([]string, 0)
0 //Copyright 2018 GoGraphviz Authors
1 //
2 //Licensed under the Apache License, Version 2.0 (the "License");
3 //you may not use this file except in compliance with the License.
4 //You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 //Unless required by applicable law or agreed to in writing, software
9 //distributed under the License is distributed on an "AS IS" BASIS,
10 //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 //See the License for the specific language governing permissions and
12 //limitations under the License.
13
14 package gographviz
15
16 import (
17 "testing"
18 )
19
20 func TestRemoveNode(t *testing.T) {
21 g := NewGraph()
22 if err := g.SetName("G"); err != nil {
23 t.Fatal(err)
24 }
25 if err := g.SetDir(true); err != nil {
26 t.Fatal(err)
27 }
28 if err := g.AddNode("G", "Hello", nil); err != nil {
29 t.Fatal(err)
30 }
31 if err := g.AddNode("G", "World", nil); err != nil {
32 t.Fatal(err)
33 }
34 if err := g.AddEdge("Hello", "World", true, nil); err != nil {
35 t.Fatal(err)
36 }
37 if err := g.AddSubGraph("G", "cluster_Core", nil); err != nil {
38 t.Fatal(err)
39 }
40 if err := g.AddNode("cluster_Core", "CoreFunction", nil); err != nil {
41 t.Fatal(err)
42 }
43 if err := g.AddSubGraph("G", "cluster_Supporting", nil); err != nil {
44 t.Fatal(err)
45 }
46 if err := g.AddNode("cluster_Supporting", "SupportingFunction", nil); err != nil {
47 t.Fatal(err)
48 }
49 if err := g.AddSubGraph("G", "cluster_Development", nil); err != nil {
50 t.Fatal(err)
51 }
52 if err := g.AddNode("cluster_Development", "DevelopmentFunction", nil); err != nil {
53 t.Fatal(err)
54 }
55 if err := g.AddPortEdge("DevelopmentFunction", "cluster_Development", "CoreFunction", "cluster_Core", true, nil); err != nil {
56 t.Fatal(err)
57 }
58 if err := g.AddPortEdge("SupportingFunction", "cluster_Supporting", "CoreFunction", "cluster_Core", true, nil); err != nil {
59 t.Fatal(err)
60 }
61 if err := g.AddPortEdge("Hello", "", "CoreFunction", "cluster_Core", true, nil); err != nil {
62 t.Fatal(err)
63 }
64
65 expected := `digraph G {
66 Hello->World;
67 DevelopmentFunction:cluster_Development->CoreFunction:cluster_Core;
68 SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core;
69 Hello->CoreFunction:cluster_Core;
70 subgraph cluster_Core {
71 CoreFunction;
72
73 }
74 ;
75 subgraph cluster_Development {
76 DevelopmentFunction;
77
78 }
79 ;
80 subgraph cluster_Supporting {
81 SupportingFunction;
82
83 }
84 ;
85 Hello;
86 World;
87
88 }
89 `
90
91 if g.String() != expected {
92 t.Fatalf("output is not expected")
93 }
94
95 if err := g.RemoveNode("cluster_Development", "DevelopmentFunction"); err != nil {
96 t.Fatal(err)
97 }
98
99 expected = `digraph G {
100 Hello->World;
101 SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core;
102 Hello->CoreFunction:cluster_Core;
103 subgraph cluster_Core {
104 CoreFunction;
105
106 }
107 ;
108 subgraph cluster_Development {
109
110 }
111 ;
112 subgraph cluster_Supporting {
113 SupportingFunction;
114
115 }
116 ;
117 Hello;
118 World;
119
120 }
121 `
122 if g.String() != expected {
123 t.Fatalf("output is not expected")
124 }
125
126 if err := g.RemoveNode("G", "Hello"); err != nil {
127 t.Fatal(err)
128 }
129 if err := g.RemoveNode("G", "World"); err != nil {
130 t.Fatal(err)
131 }
132
133 expected = `digraph G {
134 SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core;
135 subgraph cluster_Core {
136 CoreFunction;
137
138 }
139 ;
140 subgraph cluster_Development {
141
142 }
143 ;
144 subgraph cluster_Supporting {
145 SupportingFunction;
146
147 }
148 ;
149
150 }
151 `
152 if g.String() != expected {
153 t.Fatalf("output is not expected")
154 }
155
156 if err := g.RemoveNode("cluster_Supporting", "SupportingFunction"); err != nil {
157 t.Fatal(err)
158 }
159
160 expected = `digraph G {
161 subgraph cluster_Core {
162 CoreFunction;
163
164 }
165 ;
166 subgraph cluster_Development {
167
168 }
169 ;
170 subgraph cluster_Supporting {
171
172 }
173 ;
174
175 }
176 `
177
178 if g.String() != expected {
179 t.Fatalf("output is not expected")
180 }
181
182 if err := g.RemoveNode("cluster_Core", "CoreFunction"); err != nil {
183 t.Fatal(err)
184 }
185
186 expected = `digraph G {
187 subgraph cluster_Core {
188
189 }
190 ;
191 subgraph cluster_Development {
192
193 }
194 ;
195 subgraph cluster_Supporting {
196
197 }
198 ;
199
200 }
201 `
202
203 if g.String() != expected {
204 t.Fatalf("output is not expected")
205 }
206 }
207
208 func TestRemoveSubGraph(t *testing.T) {
209 g := NewGraph()
210 if err := g.SetName("G"); err != nil {
211 t.Fatal(err)
212 }
213 if err := g.SetDir(true); err != nil {
214 t.Fatal(err)
215 }
216 if err := g.AddNode("G", "Hello", nil); err != nil {
217 t.Fatal(err)
218 }
219 if err := g.AddNode("G", "World", nil); err != nil {
220 t.Fatal(err)
221 }
222 if err := g.AddEdge("Hello", "World", true, nil); err != nil {
223 t.Fatal(err)
224 }
225 if err := g.AddSubGraph("G", "cluster_Core", map[string]string{
226 "label": "Core",
227 }); err != nil {
228 t.Fatal(err)
229 }
230 if err := g.AddNode("cluster_Core", "CoreFunction", nil); err != nil {
231 t.Fatal(err)
232 }
233 if err := g.AddSubGraph("G", "cluster_Supporting", map[string]string{
234 "label": "Supporting",
235 }); err != nil {
236 t.Fatal(err)
237 }
238 if err := g.AddNode("cluster_Supporting", "SupportingFunction", nil); err != nil {
239 t.Fatal(err)
240 }
241 if err := g.AddSubGraph("G", "cluster_Development", map[string]string{
242 "label": "Development",
243 }); err != nil {
244 t.Fatal(err)
245 }
246 if err := g.AddNode("cluster_Development", "DevelopmentFunction", nil); err != nil {
247 t.Fatal(err)
248 }
249 if err := g.AddPortEdge("DevelopmentFunction", "cluster_Development", "CoreFunction", "cluster_Core", true, nil); err != nil {
250 t.Fatal(err)
251 }
252 if err := g.AddPortEdge("SupportingFunction", "cluster_Supporting", "CoreFunction", "cluster_Core", true, nil); err != nil {
253 t.Fatal(err)
254 }
255 if err := g.AddPortEdge("Hello", "", "CoreFunction", "cluster_Core", true, nil); err != nil {
256 t.Fatal(err)
257 }
258 if err := g.AddSubGraph("G", "cluster_FooBar", nil); err != nil {
259 t.Fatal(err)
260 }
261 if err := g.AddEdge("Hello", "cluster_FooBar", true, nil); err != nil {
262 t.Fatal(err)
263 }
264
265 expected := `digraph G {
266 Hello->World;
267 DevelopmentFunction:cluster_Development->CoreFunction:cluster_Core;
268 SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core;
269 Hello->CoreFunction:cluster_Core;
270 Hello->cluster_FooBar;
271 subgraph cluster_Core {
272 label=Core;
273 CoreFunction;
274
275 }
276 ;
277 subgraph cluster_Development {
278 label=Development;
279 DevelopmentFunction;
280
281 }
282 ;
283 subgraph cluster_FooBar {
284
285 }
286 ;
287 subgraph cluster_Supporting {
288 label=Supporting;
289 SupportingFunction;
290
291 }
292 ;
293 Hello;
294 World;
295
296 }
297 `
298 if g.String() != expected {
299 t.Fatalf("output is not expected")
300 }
301
302 if err := g.RemoveSubGraph("G", "cluster_Development"); err != nil {
303 t.Fatal(err)
304 }
305
306 expected = `digraph G {
307 Hello->World;
308 SupportingFunction:cluster_Supporting->CoreFunction:cluster_Core;
309 Hello->CoreFunction:cluster_Core;
310 Hello->cluster_FooBar;
311 subgraph cluster_Core {
312 label=Core;
313 CoreFunction;
314
315 }
316 ;
317 subgraph cluster_FooBar {
318
319 }
320 ;
321 subgraph cluster_Supporting {
322 label=Supporting;
323 SupportingFunction;
324
325 }
326 ;
327 Hello;
328 World;
329
330 }
331 `
332 if g.String() != expected {
333 t.Fatalf("output is not expected")
334 }
335
336 if err := g.RemoveSubGraph("G", "cluster_Supporting"); err != nil {
337 t.Fatal(err)
338 }
339
340 expected = `digraph G {
341 Hello->World;
342 Hello->CoreFunction:cluster_Core;
343 Hello->cluster_FooBar;
344 subgraph cluster_Core {
345 label=Core;
346 CoreFunction;
347
348 }
349 ;
350 subgraph cluster_FooBar {
351
352 }
353 ;
354 Hello;
355 World;
356
357 }
358 `
359 if g.String() != expected {
360 t.Fatalf("output is not expected")
361 }
362
363 if err := g.RemoveSubGraph("G", "cluster_Core"); err != nil {
364 t.Fatal(err)
365 }
366
367 expected = `digraph G {
368 Hello->World;
369 Hello->cluster_FooBar;
370 subgraph cluster_FooBar {
371
372 }
373 ;
374 Hello;
375 World;
376
377 }
378 `
379 if g.String() != expected {
380 t.Fatalf("output is not expected")
381 }
382
383 if err := g.RemoveSubGraph("G", "cluster_FooBar"); err != nil {
384 t.Fatal(err)
385 }
386
387 expected = `digraph G {
388 Hello->World;
389 Hello;
390 World;
391
392 }
393 `
394 if g.String() != expected {
395 t.Fatalf("output is not expected")
396 }
397 }
4848 }
4949 }
5050
51 // Remove removes a subgraph
52 func (subgraphs *SubGraphs) Remove(name string) {
53 delete(subgraphs.SubGraphs, name)
54 }
55
5156 // Sorted returns a sorted list of SubGraphs.
5257 func (subgraphs *SubGraphs) Sorted() []*SubGraph {
5358 keys := make([]string, 0)
0 These test graphs have been copied from the graphviz gallery found here http://www.graphviz.org/Gallery.php
0 These test graphs have been copied from the graphviz gallery found here http://www.graphviz.org/gallery/