Custom node shapes

I would like to create and use custom shapes that can be modified with node attr. (e.g. penwidth to modify the custom node lines width) I am trying an already working example from http://rhodesmill.org/brandon/2007/a-database-symbol-for-graphviz/ to experiment and create such kind of nodes, but without much success.

Example 1, the generic example works:
$ dot -Tps2 -l DatabaseShape.ps sample.dot -o sample.ps
$ ps2pdf sample.ps sample.pdf

Example 2:
$ dot -Tps2 -l DatabaseShape.ps sample.dot -Tpng -o sample-ps.png
$ feh sample-ps.png
feh WARNING: sample-ps.png - No Imlib2 loader for that file format
feh: No loadable images specified.
See 'feh --help' or 'man feh' for detailed usage information

When I try to create a png graph relying on a custom postscript node shape, the result is a sample.png file that cannot be open.

Example 3:
$ dot -l DatabaseShape.ps sample.dot -Tpng -o sample-no-ps.png
$ feh sample-ps.png

sample-no-ps.png does not contain the custom DatabaseShape shape.

Example 4:
$ ls
DatabaseShape.ps sample-DFD-infile.pdf sample-image.dot sample.ps
DFD.ps sample-DFD-infile.ps sample-image.pdf sample-ps.png
message.txt sample-DFD.pdf sample-image.ps sample-shape.dot
sample-DFD.dot sample-DFD.ps sample-no-ps.png sample-shape.ps
sample-DFD-infile.dot sample.dot sample.pd

$ pwd
/home/albert/file/dev/test/graphviz/custom-node

$ dot -Tps2 sample-image.dot -o sample-image.ps
Warning: "/home/albert/file/dev/test/graphviz/custom-node/DatabaseShape.ps" was not found as a file or as a shape library member
Warning: No or improper image="/home/albert/file/dev/test/graphviz/custom-node/DatabaseShape.ps" for node "Database"

Example 5:
$ dot -Tps2 sample-image.dot -o sample-image.ps
Warning: "/home/albert/file/dev/test/graphviz/custom-node/DatabaseShape.ps" was not found as a file or as a shape library member
Warning: No or improper image="/home/albert/file/dev/test/graphviz/custom-node/DatabaseShape.ps" for node "Database"

Example 6:
Using DFD.ps from http://www.graphviz.org/wiki/how-create-custom-shapes
$ dot -Tps2 -l DFD.ps sample-DFD.dot -o sample-DFD.ps
$ ps2pdf sample-DFD.ps sample-DFD.pdf

## WORKS ##

Example 7:
$ dot -Tps2 sample-DFD-infile.dot -o sample-DFD-infile.ps
Warning: "/home/albert/file/dev/test/graphviz/custom-node/DFD.ps" was not found as a file or as a shape library member
Warning: No or improper shapefile="/home/albert/file/dev/test/graphviz/custom-node/DFD.ps" for node "Database"

Questions:
How can I include file names in the dot file to have custom shapes?
Is it possible to use shapes from different file formats and output a different file format graph ?

AttachmentSize
DatabaseShape.ps_.txt1.01 KB
DFD.ps_.txt417 bytes
sample-DFD-infile.dot_.txt509 bytes
sample-DFD-infile.pdf2.97 KB
sample-DFD-infile.ps_.txt6.39 KB
sample-DFD.dot_.txt453 bytes
sample-DFD.pdf2.99 KB
sample-DFD.ps_.txt6.87 KB
sample-image.dot_.txt501 bytes
sample-image.pdf2.97 KB
sample-image.ps_.txt6.62 KB
sample-no-ps.png7.27 KB
sample-ps.png7.48 KB
sample-shape.dot_.txt517 bytes
sample-shape.ps_.txt6.2 KB
sample.dot_.txt450 bytes
sample.pdf3.06 KB
sample.ps_.txt7.48 KB

Example 2 doesn't work

Example 2 doesn't work because the command you use

dot -Tps2 -l DatabaseShape.ps sample.dot -Tpng -o sample-ps.png

creates a postscript file because of the -Tps2 flag.

Example 3 doesn't work because the -l option only works with postscript output.

Example 4 doesn't work because DatabaseShape.ps doesn't contain an image, just a postscript function.

Example 5 seems the same as example 4.

Example 7 fails because DFD.ps doesn't contain an image, just a postscript function.

Basicallly, there are two mechanisms. You can specify various shapes as postscript functions, load these using the -l flag, and generate postscript output with -Tps or -Tps2. If  you want the output in a different format, you will need to used some conversion program like ImageMagick or ps2pdf.

The other, and more common, approach is to use images. If you turn off the node peripheries and set margin=0, you get pretty much what you would have gotten using -l except the images and the output can be in any format (almost). Just set a node's image attribute to point to some image file. It has to actually contain an image and the image file must have some mechanism for determing the image size. So a postscript file is not enough; it needs to be encapsulated postscript with the image size specified in the comments.

Two caveats concerning image formats: the range of supported formats depends on how your version of Graphviz was built. It relies on 3rd party libraries like cairo for reading images. If you run dot -v, you'll see a list of supported image formats. The second caveat is that we used to be able to support postscript images, but the ghostscript people took away the feature we relied on, so it is no longer possible to read in a postscript file as an image. We hope to have a replacement mechanism soon. This usually isn't a great problem, as most people nowadays use either bitmap images or svg files.

 

If I would like to be able to

If I would like to be able to modify my included custom shape using attr (e.g. using penwidth), is including an external .ps file containing postscript functions (-l) the only option left?

I believe so.

I believe so.

Recent comments