8

I would like to add multiline tool-tip for the nodes in the graph I am generating using pydot. Here is what I am doing:

node = pydot.Node('abc', style='filled', fillcolor='#CCFF00', fontsize=12)
txt = 'foo' + '\n' + 'test'
node.set_tooltip(txt)

The tool tip that I get to see appears as "foo\ntest'

I will appreciate any help.

Thanks Abhijit

1 Answers1

15

It seems the new line character is supported for labels and names (Newline in node label in dot (graphviz) language), but tool tips are put directly into the resultant HTML, which does not see "\n" as a special character.

Using direct character codes is an alternative. (see Formatting & ASCII Control Codes)

node = pydot.Node('abc', style='filled', fillcolor='#CCFF00', fontsize=12)

# specify HTML Carriage Return (\r) and/or Line Feed (\n) characters directly
txt = 'foo' + '
' + test'

node.set_tooltip(txt)

Or some simple pre-processing would allow you to keep the '\n' form:

node.set_tooltip(txt.replace('\n', '
'))
  • Note that for HTML-Like Labels, using the above replace-with-entity in the only way to have multiline-tooltips.
ankostis
  • 8,579
  • 3
  • 47
  • 61
David Thompson
  • 1,111
  • 1
  • 8
  • 8