浏览代码

Support URL link from the legend box. (#143)

Fixes #142.
Alexey Alexandrov 7 年前
父节点
当前提交
4dbd915c72

+ 1
- 1
internal/driver/testdata/pprof.cpu.flat.functions.call_tree.dot 查看文件

@@ -1,6 +1,6 @@
1 1
 digraph "testbinary" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "File: testbinary" [shape=box fontsize=16 label="File: testbinary\lType: cpu\lDuration: 10s, Total samples = 1.12s (11.20%)\lShowing nodes accounting for 1.11s, 99.11% of 1.12s total\lDropped 3 nodes (cum <= 0.06s)\l"] }
3
+subgraph cluster_L { "File: testbinary" [shape=box fontsize=16 label="File: testbinary\lType: cpu\lDuration: 10s, Total samples = 1.12s (11.20%)\lShowing nodes accounting for 1.11s, 99.11% of 1.12s total\lDropped 3 nodes (cum <= 0.06s)\l" tooltip="testbinary"] }
4 4
 N1 [label="line1000\n1s (89.29%)" fontsize=24 shape=box tooltip="line1000 (1s)" color="#b20500" fillcolor="#edd6d5"]
5 5
 N1_0 [label = "key1:tag1\nkey2:tag1" fontsize=8 shape=box3d tooltip="1s"]
6 6
 N1 -> N1_0 [label=" 1s" weight=100 tooltip="1s" labeltooltip="1s"]

+ 1
- 1
internal/driver/testdata/pprof.cpu.flat.functions.dot 查看文件

@@ -1,6 +1,6 @@
1 1
 digraph "testbinary" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "File: testbinary" [shape=box fontsize=16 label="File: testbinary\lType: cpu\lDuration: 10s, Total samples = 1.12s (11.20%)\lShowing nodes accounting for 1.12s, 100% of 1.12s total\l"] }
3
+subgraph cluster_L { "File: testbinary" [shape=box fontsize=16 label="File: testbinary\lType: cpu\lDuration: 10s, Total samples = 1.12s (11.20%)\lShowing nodes accounting for 1.12s, 100% of 1.12s total\l" tooltip="testbinary"] }
4 4
 N1 [label="line1000\n1.10s (98.21%)" fontsize=24 shape=box tooltip="line1000 (1.10s)" color="#b20000" fillcolor="#edd5d5"]
5 5
 N1_0 [label = "key1:tag1\nkey2:tag1" fontsize=8 shape=box3d tooltip="1s"]
6 6
 N1 -> N1_0 [label=" 1s" weight=100 tooltip="1s" labeltooltip="1s"]

+ 12
- 3
internal/graph/dotgraph.go 查看文件

@@ -42,8 +42,9 @@ type DotNodeAttributes struct {
42 42
 // DotConfig contains attributes about how a graph should be
43 43
 // constructed and how it should look.
44 44
 type DotConfig struct {
45
-	Title  string   // The title of the DOT graph
46
-	Labels []string // The labels for the DOT's legend
45
+	Title     string   // The title of the DOT graph
46
+	LegendURL string   // The URL to link to from the legend.
47
+	Labels    []string // The labels for the DOT's legend
47 48
 
48 49
 	FormatValue func(int64) string         // A formatting function for values
49 50
 	FormatTag   func(int64, string) string // A formatting function for numeric tags
@@ -126,7 +127,15 @@ func (b *builder) addLegend() {
126 127
 	if len(labels) > 0 {
127 128
 		title = labels[0]
128 129
 	}
129
-	fmt.Fprintf(b, `subgraph cluster_L { "%s" [shape=box fontsize=16 label="%s\l"] }`+"\n", title, strings.Join(labels, `\l`))
130
+	fmt.Fprintf(b, `subgraph cluster_L { "%s" [shape=box fontsize=16`, title)
131
+	fmt.Fprintf(b, ` label="%s\l"`, strings.Join(labels, `\l`))
132
+	if b.config.LegendURL != "" {
133
+		fmt.Fprintf(b, ` URL="%s" target="_blank"`, b.config.LegendURL)
134
+	}
135
+	if b.config.Title != "" {
136
+		fmt.Fprintf(b, ` tooltip="%s"`, b.config.Title)
137
+	}
138
+	fmt.Fprintf(b, "] }\n")
130 139
 }
131 140
 
132 141
 // addNode generates a graph node in DOT format.

+ 16
- 0
internal/graph/dotgraph_test.go 查看文件

@@ -150,6 +150,22 @@ func TestComposeWithEmptyGraph(t *testing.T) {
150 150
 	compareGraphs(t, buf.Bytes(), want)
151 151
 }
152 152
 
153
+func TestComposeWithStandardGraphAndURL(t *testing.T) {
154
+	g := baseGraph()
155
+	a, c := baseAttrsAndConfig()
156
+	c.LegendURL = "http://example.com"
157
+
158
+	var buf bytes.Buffer
159
+	ComposeDot(&buf, g, a, c)
160
+
161
+	want, err := ioutil.ReadFile(path + "compose6.dot")
162
+	if err != nil {
163
+		t.Fatalf("error reading test file: %v", err)
164
+	}
165
+
166
+	compareGraphs(t, buf.Bytes(), want)
167
+}
168
+
153 169
 func baseGraph() *Graph {
154 170
 	src := &Node{
155 171
 		Info:        NodeInfo{Name: "src"},

+ 1
- 1
internal/graph/testdata/compose1.dot 查看文件

@@ -1,6 +1,6 @@
1 1
 digraph "testtitle" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l"] }
3
+subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l" tooltip="testtitle"] }
4 4
 N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"]
5 5
 N2 [label="dest\n15 (15.00%)\nof 25 (25.00%)" fontsize=24 shape=box tooltip="dest (25)" color="#b23c00" fillcolor="#edddd5"]
6 6
 N1 -> N2 [label=" 10" weight=11 color="#b28559" tooltip="src -> dest (10)" labeltooltip="src -> dest (10)"]

+ 1
- 1
internal/graph/testdata/compose2.dot 查看文件

@@ -1,6 +1,6 @@
1 1
 digraph "testtitle" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l"] }
3
+subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l" tooltip="testtitle"] }
4 4
 N1 [label="SRC10 (10.00%)\nof 25 (25.00%)" fontsize=24 shape=folder tooltip="src (25)" color="#b23c00" fillcolor="#edddd5" style="bold,filled" peripheries=2 URL="www.google.com" target="_blank"]
5 5
 N2 [label="dest\n0 of 25 (25.00%)" fontsize=8 shape=box tooltip="dest (25)" color="#b23c00" fillcolor="#edddd5"]
6 6
 N1 -> N2 [label=" 10" weight=11 color="#b28559" tooltip="src -> dest (10)" labeltooltip="src -> dest (10)"]

+ 1
- 1
internal/graph/testdata/compose3.dot 查看文件

@@ -1,6 +1,6 @@
1 1
 digraph "testtitle" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l"] }
3
+subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l" tooltip="testtitle"] }
4 4
 N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"]
5 5
 N1_0 [label = "tag1" fontsize=8 shape=box3d tooltip="10"]
6 6
 N1 -> N1_0 [label=" 10" weight=100 tooltip="10" labeltooltip="10"]

+ 1
- 1
internal/graph/testdata/compose4.dot 查看文件

@@ -1,4 +1,4 @@
1 1
 digraph "testtitle" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l"] }
3
+subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l" tooltip="testtitle"] }
4 4
 }

+ 1
- 1
internal/graph/testdata/compose5.dot 查看文件

@@ -1,6 +1,6 @@
1 1
 digraph "testtitle" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l"] }
3
+subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l" tooltip="testtitle"] }
4 4
 N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"]
5 5
 N1_0 [label = "tag1" fontsize=8 shape=box3d tooltip="10"]
6 6
 N1 -> N1_0 [label=" 10" weight=100 tooltip="10" labeltooltip="10"]

+ 7
- 0
internal/graph/testdata/compose6.dot 查看文件

@@ -0,0 +1,7 @@
1
+digraph "testtitle" {
2
+node [style=filled fillcolor="#f8f8f8"]
3
+subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\l" URL="http://example.com" target="_blank" tooltip="testtitle"] }
4
+N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"]
5
+N2 [label="dest\n15 (15.00%)\nof 25 (25.00%)" fontsize=24 shape=box tooltip="dest (25)" color="#b23c00" fillcolor="#edddd5"]
6
+N1 -> N2 [label=" 10" weight=11 color="#b28559" tooltip="src -> dest (10)" labeltooltip="src -> dest (10)"]
7
+}