0

Is there any way to create a node in Graphviz that looks like the below? (Placing a hexagon and text side by side inside the node instead of just placing text inside box)

enter image description here

1 Answers1

1

You can't easily embed nodes within other nodes, but you can insert images into nodes. Create an image (or images) with the polygon shape(s) and insert them into an HTML-style node (record-style would probably also work).
Like so:

digraph i{
 {rank=same
  n1 [shape=plaintext,label=<
  <TABLE CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0"> 
  <TR><TD FIXEDSIZE="true" height="20" width="20"><IMG  SRC="cow.png" scale="true"/></TD><TD>some text</TD></TR>
  </TABLE>
  >
  ]

  n2 [shape=plaintext,label=<
  <TABLE CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0" >
  <TR><TD colspan="2" bgcolor="green1">Step</TD></TR>
  <TR><TD FIXEDSIZE="true" height="20" width="20"><IMG  SRC="cow.png" scale="true"/></TD><TD>some text</TD></TR>
  </TABLE>
  >
  ]
  n1 -> n2
  }
} 

Giving:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11
  • I've tried above using an image of size 2.7 kb but I see empty space in place of the image. How do I resolve this? – Vinay Cheguri Sep 02 '22 at 10:13
  • can you please specify the versions of graphviz and d3 you used? – Vinay Cheguri Sep 02 '22 at 11:40
  • I am not using d3, I have Graphviz installed locally. I believe d3 is Javascript-based, and while I am not familiar with its internals, my guess is that it can't read local files (the image file) for security reasons. My Graphviz version is 5.0.1~dev.20220813.1614 (20220813.1614) – sroush Sep 02 '22 at 16:31