addEdge generates a graph edge in DOT format.
(edge *Edge, from, to int, hasNodelets bool)
| 283 | |
| 284 | // addEdge generates a graph edge in DOT format. |
| 285 | func (b *builder) addEdge(edge *Edge, from, to int, hasNodelets bool) { |
| 286 | var inline string |
| 287 | if edge.Inline { |
| 288 | inline = `\n (inline)` |
| 289 | } |
| 290 | w := b.config.FormatValue(edge.WeightValue()) |
| 291 | attr := fmt.Sprintf(`label=" %s%s"`, w, inline) |
| 292 | if b.config.Total != 0 { |
| 293 | // Note: edge.weight > b.config.Total is possible for profile diffs. |
| 294 | if weight := 1 + int(min64(abs64(edge.WeightValue()*100/b.config.Total), 100)); weight > 1 { |
| 295 | attr = fmt.Sprintf(`%s weight=%d`, attr, weight) |
| 296 | } |
| 297 | if width := 1 + int(min64(abs64(edge.WeightValue()*5/b.config.Total), 5)); width > 1 { |
| 298 | attr = fmt.Sprintf(`%s penwidth=%d`, attr, width) |
| 299 | } |
| 300 | attr = fmt.Sprintf(`%s color="%s"`, attr, |
| 301 | dotColor(float64(edge.WeightValue())/float64(abs64(b.config.Total)), false)) |
| 302 | } |
| 303 | arrow := "->" |
| 304 | if edge.Residual { |
| 305 | arrow = "..." |
| 306 | } |
| 307 | tooltip := fmt.Sprintf(`"%s %s %s (%s)"`, |
| 308 | escapeForDot(edge.Src.Info.PrintableName()), arrow, |
| 309 | escapeForDot(edge.Dest.Info.PrintableName()), w) |
| 310 | attr = fmt.Sprintf(`%s tooltip=%s labeltooltip=%s`, attr, tooltip, tooltip) |
| 311 | |
| 312 | if edge.Residual { |
| 313 | attr = attr + ` style="dotted"` |
| 314 | } |
| 315 | |
| 316 | if hasNodelets { |
| 317 | // Separate children further if source has tags. |
| 318 | attr = attr + " minlen=2" |
| 319 | } |
| 320 | |
| 321 | fmt.Fprintf(b, "N%d -> N%d [%s]\n", from, to, attr) |
| 322 | } |
| 323 | |
| 324 | // dotColor returns a color for the given score (between -1.0 and |
| 325 | // 1.0), with -1.0 colored green, 0.0 colored grey, and 1.0 colored |
no test coverage detected