@@ -33,6 +33,7 @@ func NewMermaidWriter(opts ...MermaidOption) *MermaidWriter {
33
33
m := & MermaidWriter {
34
34
MinEdgeName : minEdgeName ,
35
35
SpecifiedPackageName : specifiedPackageName ,
36
+ UseV0Semantics : true ,
36
37
}
37
38
38
39
for _ , opt := range opts {
@@ -53,9 +54,9 @@ func WithSpecifiedPackageName(specifiedPackageName string) MermaidOption {
53
54
}
54
55
}
55
56
56
- func WithV0Semantics () MermaidOption {
57
+ func WithV0Semantics (useV0Semantics bool ) MermaidOption {
57
58
return func (o * MermaidWriter ) {
58
- o .UseV0Semantics = true
59
+ o .UseV0Semantics = useV0Semantics
59
60
}
60
61
}
61
62
@@ -131,7 +132,8 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
131
132
}
132
133
133
134
var deprecatedPackage string
134
- deprecatedChannels := []string {}
135
+ deprecatedChannelIDs := []string {}
136
+ decoratedBundleIDs := map [string ][]string {"deprecated" : {}, "skipped" : {}, "deprecatedskipped" : {}}
135
137
linkID := 0
136
138
skippedLinkIDs := []string {}
137
139
@@ -154,7 +156,7 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
154
156
}
155
157
156
158
if depByChannel .Has (filteredChannel .Name ) {
157
- deprecatedChannels = append (deprecatedChannels , channelID )
159
+ deprecatedChannelIDs = append (deprecatedChannelIDs , channelID )
158
160
}
159
161
160
162
// sort edges by decreasing version
@@ -169,29 +171,44 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
169
171
170
172
skippedEntities := sets.Set [string ]{}
171
173
174
+ const (
175
+ captureNewEntry = true
176
+ processExisting = false
177
+ )
178
+ handleSemantics := func (edge string , linkID int , captureNew bool ) {
179
+ if writer .UseV0Semantics {
180
+ if captureNew {
181
+ if skippedEntities .Has (edge ) {
182
+ skippedLinkIDs = append (skippedLinkIDs , fmt .Sprintf ("%d" , linkID ))
183
+ } else {
184
+ skippedEntities .Insert (edge )
185
+ }
186
+ } else {
187
+ if skippedEntities .Has (edge ) {
188
+ skippedLinkIDs = append (skippedLinkIDs , fmt .Sprintf ("%d" , linkID ))
189
+ }
190
+ }
191
+ }
192
+ }
193
+
172
194
for _ , ce := range sortedEntries {
173
- bundleDecoration := ""
195
+ entryID := fmt .Sprintf ("%s-%s" , channelID , ce .Name )
196
+
197
+ // mermaid allows specification of only a single decoration class, so any combinations must be independently represented
174
198
switch {
175
199
case depByBundle .Has (ce .Name ) && skippedEntities .Has (ce .Name ):
176
- bundleDecoration = ":::depandskip"
200
+ decoratedBundleIDs [ "deprecatedskipped" ] = append ( decoratedBundleIDs [ "deprecatedskipped" ], entryID )
177
201
case depByBundle .Has (ce .Name ):
178
- bundleDecoration = "::: deprecated"
202
+ decoratedBundleIDs [ "deprecated" ] = append ( decoratedBundleIDs [ " deprecated"], entryID )
179
203
case skippedEntities .Has (ce .Name ):
180
- bundleDecoration = "::: skipped"
204
+ decoratedBundleIDs [ "skipped" ] = append ( decoratedBundleIDs [ " skipped"], entryID )
181
205
}
182
206
183
- entryID := fmt .Sprintf ("%s-%s" , channelID , ce .Name )
184
- fmt .Fprintf (pkgBuilder , " %s[%q]%s\n " , entryID , ce .Name , bundleDecoration )
185
-
186
207
if len (ce .Skips ) > 0 {
187
208
for _ , s := range ce .Skips {
188
209
skipsID := fmt .Sprintf ("%s-%s" , channelID , s )
189
210
fmt .Fprintf (pkgBuilder , " %s[%q]-- %s --> %s[%q]\n " , skipsID , s , "skip" , entryID , ce .Name )
190
- if skippedEntities .Has (s ) {
191
- skippedLinkIDs = append (skippedLinkIDs , fmt .Sprintf ("%d" , linkID ))
192
- } else {
193
- skippedEntities .Insert (s )
194
- }
211
+ handleSemantics (s , linkID , captureNewEntry )
195
212
linkID ++
196
213
}
197
214
}
@@ -202,9 +219,7 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
202
219
if skipRange (versionMap [edgeName .Name ]) {
203
220
skipRangeID := fmt .Sprintf ("%s-%s" , channelID , edgeName .Name )
204
221
fmt .Fprintf (pkgBuilder , " %s[%q]-- \" %s(%s)\" --> %s[%q]\n " , skipRangeID , edgeName .Name , "skipRange" , ce .SkipRange , entryID , ce .Name )
205
- if skippedEntities .Has (ce .Name ) {
206
- skippedLinkIDs = append (skippedLinkIDs , fmt .Sprintf ("%d" , linkID ))
207
- }
222
+ handleSemantics (ce .Name , linkID , processExisting )
208
223
linkID ++
209
224
}
210
225
}
@@ -216,9 +231,7 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
216
231
if len (ce .Replaces ) > 0 {
217
232
replacesID := fmt .Sprintf ("%s-%s" , channelID , ce .Replaces )
218
233
fmt .Fprintf (pkgBuilder , " %s[%q]-- %s --> %s[%q]\n " , replacesID , ce .Replaces , "replace" , entryID , ce .Name )
219
- if skippedEntities .Has (ce .Name ) {
220
- skippedLinkIDs = append (skippedLinkIDs , fmt .Sprintf ("%d" , linkID ))
221
- }
234
+ handleSemantics (ce .Name , linkID , processExisting )
222
235
linkID ++
223
236
}
224
237
}
@@ -229,7 +242,7 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
229
242
_ , _ = out .Write ([]byte ("graph LR\n " ))
230
243
_ , _ = out .Write ([]byte (" classDef deprecated fill:#E8960F\n " ))
231
244
_ , _ = out .Write ([]byte (" classDef skipped stroke:#FF0000,stroke-width:4px\n " ))
232
- _ , _ = out .Write ([]byte (" classDef depandskip fill:#E8960 ,stroke:#FF0000,stroke-width:4px\n " ))
245
+ _ , _ = out .Write ([]byte (" classDef deprecatedskipped fill:#E8960F ,stroke:#FF0000,stroke-width:4px\n " ))
233
246
pkgNames := []string {}
234
247
for pname := range pkgs {
235
248
pkgNames = append (pkgNames , pname )
@@ -248,12 +261,19 @@ func (writer *MermaidWriter) WriteChannels(cfg DeclarativeConfig, out io.Writer)
248
261
_ , _ = out .Write ([]byte (fmt .Sprintf ("style %s fill:#989695\n " , deprecatedPackage )))
249
262
}
250
263
251
- if len (deprecatedChannels ) > 0 {
252
- for _ , deprecatedChannel := range deprecatedChannels {
264
+ if len (deprecatedChannelIDs ) > 0 {
265
+ for _ , deprecatedChannel := range deprecatedChannelIDs {
253
266
_ , _ = out .Write ([]byte (fmt .Sprintf ("style %s fill:#DCD0FF\n " , deprecatedChannel )))
254
267
}
255
268
}
256
269
270
+ // express the decoration classes
271
+ for key := range decoratedBundleIDs {
272
+ if len (decoratedBundleIDs [key ]) > 0 {
273
+ _ , _ = out .Write ([]byte (fmt .Sprintf ("class %s %s\n " , strings .Join (decoratedBundleIDs [key ], "," ), key )))
274
+ }
275
+ }
276
+
257
277
if len (skippedLinkIDs ) > 0 {
258
278
_ , _ = out .Write ([]byte ("linkStyle " + strings .Join (skippedLinkIDs , "," ) + " stroke:#FF0000,stroke-width:3px,stroke-dasharray:5;" ))
259
279
}
0 commit comments