-
Notifications
You must be signed in to change notification settings - Fork 657
internal/graph: Escape tag labels correctly for dot #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -519,6 +519,7 @@ func (g *Graph) TrimTree(kept NodePtrSet) { | |
| g.RemoveRedundantEdges() | ||
| } | ||
|
|
||
| // joinLabels returns the labels as they should be displayed to the user (not escaped). | ||
| func joinLabels(s *profile.Sample) string { | ||
| if len(s.Label) == 0 { | ||
| return "" | ||
|
|
@@ -531,7 +532,8 @@ func joinLabels(s *profile.Sample) string { | |
| } | ||
| } | ||
| sort.Strings(labels) | ||
| return strings.Join(labels, `\n`) | ||
| // join labels with a newline: this can be a bit confusing for labels with newlines | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please make comments full sentences (titlecase, trailing dot). Also here and in other places please make comments fit 80 columns, like the rest of the pprof codebase.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay! I've edited this since it needs to change a bit to accommodate the escaping change you mentioned below. |
||
| return strings.Join(labels, "\n") | ||
| } | ||
|
|
||
| // isNegative returns true if the node is considered as "negative" for the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| digraph "testtitle" { | ||
| node [style=filled fillcolor="#f8f8f8"] | ||
| subgraph cluster_L { "label1" [shape=box fontsize=16 label="label1\llabel2\llabel3: \"foo\"\l" tooltip="testtitle"] } | ||
| N1 [label="src\n10 (10.00%)\nof 25 (25.00%)" id="node1" fontsize=22 shape=box tooltip="src (25)" color="#b23c00" fillcolor="#edddd5"] | ||
| N1_0 [label = "label\"quote\"\lline2" id="N1_0" fontsize=8 shape=box3d tooltip="10"] | ||
| N1 -> N1_0 [label=" 10" weight=100 tooltip="10" labeltooltip="10"] | ||
| NN1_0 [label = "numeric\"quote\"" id="NN1_0" fontsize=8 shape=box3d tooltip="20"] | ||
| N1 -> NN1_0 [label=" 20" weight=100 tooltip="20" labeltooltip="20"] | ||
| N2 [label="dest\n15 (15.00%)\nof 25 (25.00%)" id="node2" fontsize=24 shape=box tooltip="dest (25)" color="#b23c00" fillcolor="#edddd5"] | ||
| N1 -> N2 [label=" 10" weight=11 color="#b28559" tooltip="src -> dest (10)" labeltooltip="src -> dest (10)" minlen=2] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would expect the current behavior to be preserved - centered tags.
I'd also expect any non-printable characters like newlines to be rendered as their C escaped version, so that the tag value is always one line when rendered. Same for function names. The escaping was initially added in #557 for graph legend labels that come from the profile comments field and for that we did support newlines to render newlines from comments as newlines since some comments intentionally use that kind of formatting. I think for function names and tag values it should be different and we shouldn't allow any formatting sequences in those strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a significant change to how escapeForDot works. Previously, if an input contains newlines, it returns an output that will be displayed on separate lines on the dot graph. However, it could be that this is a better definition: it will now return an escaped string that will be displayed on a single
The challenge is now:
escapeForDoton them.[]stringfor labels instead ofstring.My hack was to change the definition of
joinLabelsto return a string escaped for dot. I think the final output is actually a good improvement, but I wish the escaping was only applied at the very end.