0

I am unable to get a graphviz node label to be right justified when joining strings from a list. If I attach '\n' and '\r' to either end, the justification works, but it still shows the list elements (brakcets & quotes):

label_list = ['car','button','cloth']
label = ['\n' + s + '\r' for s in label_list]

enter image description here

If I use join, the right-justification is lost:

label_list = ['car','button','cloth']
label = ['\n' + s '\r' for s in label_list]
label = ''.join(label)

enter image description here

Per sroush comment, removing '\n' gives:

enter image description here(or something similar to first example if join is not used).

What I'd like is simply:

enter image description here

Ben
  • 53
  • 9
  • the best reference I could find: https://stackoverflow.com/questions/65162650/graphviz-left-justify-edge-label-text – Ben Feb 02 '22 at 14:20
  • Think of '\r' as including a '\n' also. So remove the '\n' from your program and see what happens. – sroush Feb 02 '22 at 17:34
  • @sroush thanks, I updated the question with this recommendation; still no solution. – Ben Feb 02 '22 at 17:45
  • 1
    I assume that under the hood a `dot file is generated, can't you see what the content of this file is? (from this probably you can draw conclusions like the needed number of backslashes , might be you need `\\n` – albert Feb 03 '22 at 16:30

2 Answers2

0

Here is a Graphviz-only (no Python) solution:

graph j {  
 A [label="car\rbutton\rcloth\rmuch more\r"]  
}

Giving:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11
  • This is similar to my first comment above. I do need a python solution. Thanks! – Ben Feb 02 '22 at 21:27
0

By converting the list to a string and removing each of the list elements (brackets, commas, etc), I get the desired result.

label_list = ['car','button','cloth']
label = [s + '\r' for s in label_list]
label = str(label)[1:-1].replace(',','').replace("'",'')
Ben
  • 53
  • 9