| Refresh | Home EGTry.com

use postscript procedure to define a resizable node shape to be used in graphviz


unlike raster image based custom node shape, a custom shape defined by postscript is vector shape and can be scaled without losing resolution

graphviz image that use a custom node image that is defined by postscript procedure custom shape

graphviz command to use shapes defined in postscript

dot -Tps -l MyShape.ps useShape.gv -o useShape.ps



postscript file that define shape procedure. note: include the procedure definition only. no eps headers

%!

	/xdef {exch def} bind def
	/MyShape {
		10 dict begin
			/fflag xdef %put on local variable
			/sides xdef 


			aload pop  % flat out array
			newpath
			moveto %first point is initial position 
			1 1 sides 
			{
			  setlinewidth 
			  lineto      
      } for
			closepath 

			fflag   % if shape is filled
			{
				fill
			}
			%not filled
			{
			  stroke
      }
			ifelse

		end
	} bind def

  % [100 100   150 100   150 50    100 50     100 100]  4 true MyShape
	% showpage



a sample graphviz dot file that use custom shape defined above

digraph G {
custom[shape=MyShape, label="Custom Shape"];
custom->everything;
}