Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline tooltip for pydot graph

Tags:

graphviz

pydot

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

like image 505
Abhijit Bhattacharya Avatar asked May 21 '13 14:05

Abhijit Bhattacharya


1 Answers

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.
like image 171
David Thompson Avatar answered Sep 28 '22 04:09

David Thompson