Multiline tooltip for pydot graph
Asked Answered
R

1

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

Rida answered 21/5, 2013 at 14:0 Comment(0)
S
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.
Squint answered 12/12, 2014 at 17:4 Comment(1)
Any reason this isn't the accepted answer @Abhijit? Works for me.Corsica

© 2022 - 2024 — McMap. All rights reserved.