Search code examples
graphvizpostscriptmetapost

How to use postscripts from metapost as images in graphviz?


I produce two postscript files runing metapost on the file example.mp containing:

beginfig(1);
u=1cm;
draw (2u,2u)--(0,0)--(0,3u)--(3u,0)--(0,0);
pickup pencircle scaled 4pt;
for i=0 upto 2:
for j=0 upto 2: drawdot (i*u,j*u); endfor
endfor
endfig;

beginfig(2);
z0 = (0,0); z1 = (60,40);
z2 = (40,90); z3 = (10,70);
z4 = (30,50);
draw z0..z1..z2..z3..z4
endfig;

end

example.1 content is:

%!PS
%%BoundingBox: -2 -2 86 86 
%%HiResBoundingBox: -1.99252 -1.99252 85.28935 85.28935 
%%Creator: MetaPost 2.00
%%CreationDate: 2023.07.15:2110
%%Pages: 1
%%BeginProlog
%%EndProlog
%%Page: 1 1
 0 0 0 setrgbcolor 0 0.5 dtransform truncate idtransform setlinewidth pop
 [] 0 setdash 1 setlinecap 1 setlinejoin 10 setmiterlimit
newpath 56.6929 56.6929 moveto
0 0 lineto
0 85.03935 lineto
85.03935 0 lineto
0 0 lineto stroke
 0 3.98505 dtransform truncate idtransform setlinewidth pop
newpath 0 0 moveto 0 0 rlineto stroke
newpath 0 28.34645 moveto 0 0 rlineto stroke
newpath 0 56.6929 moveto 0 0 rlineto stroke
newpath 28.34645 0 moveto 0 0 rlineto stroke
newpath 28.34645 28.34645 moveto 0 0 rlineto stroke
newpath 28.34645 56.6929 moveto 0 0 rlineto stroke
newpath 56.6929 0 moveto 0 0 rlineto stroke
newpath 56.6929 28.34645 moveto 0 0 rlineto stroke
newpath 56.6929 56.6929 moveto 0 0 rlineto stroke
showpage
%%EOF

I want to use the results, example.1 and example.2 as node images in a graph.

I run dot -Tps example.dot -o example.ps.

example.dot's content is:

strict graph {
    {
        node [shape=none, label=""];
        1 [image="example.1"];
        2 [image="example.2"];
    }
    1 -- 2;
}

I get warning messages:

Warning: "example.1" was not found as a file or as a shape library member
Warning: No or improper image="example.1" for node "1"
Warning: "example.2" was not found as a file or as a shape library member
Warning: No or improper image="example.2" for node "2"

And the nodes' images are missing in example.ps.

How can I do to manage to see them in the result?


Solution

  • Graphviz seems to not like the format of your 2 Postscript files (even though seemingly quite legal).
    Use Ghostscript to "fix" these files ps2ps example.1 Example.1 or some such, fix the naming of the files, and try again. Worked for me.