16.3.8 Graphical Output with DaVinci

It is often useful to output a picture of a graph rather then the list of its nodes and edges. For instance, one might want to draw constraint graphs or its solution trees. A quite simple way to do so is to use a professional tree drawing tool such as DaVinci which was develloped at the University of Bremen in Germany.

Of course, you have to install DaVinci on your local machine if you want to run an applet based on DaVinci. The only problem might be that DaVinci does not run on your platform. For instance, DaVinci is not provided for Windows.

There also exists a simple interface from Oz to DaVinci. This interface is provided by the authors in terms of two Mozart-functors which are made available at the following URL:

http://www.ps.uni-sb.de/~niehren/DaVinci/Version.3.2/graph.ozf
http://www.ps.uni-sb.de/~niehren/DaVinci/Version.3.2/pipe.ozf

The version number concernes the Pickle version of functors used by your Oz system. An example for the usage of the Oz-DaVinci-Interface can be found at:

  
http://www.ps.uni-sb.de/~niehren/DaVinci/example.oz

If you want to use the interface then you have to define a graph and the layout parameters for the nodes and edges of the graph. As a typical example we consider the following graph - the graph of the dominance constraints for 'Every man loves a woman'

<Example Graph>=
Graph = [node(id:1
              edges:[edge(to:2)]
              label:label('OBJECT':'X1:'#forall#' '#men))
         node(id:2
              edges:[edge(kind:dom to:5)]
              label:label('OBJECT':'X2'))
         node(id:3
              edges:[edge(to:4)]
              label:label('OBJECT':'X3:'#exists#' '#woman))
         node(id:4
              edges:[edge(kind:dom to:5)]
              label:label('OBJECT':'X4'))
         node(id:5
              edges:nil
              label:label('OBJECT':'X5:'#loves))
        ]

The above graph definition already uses layout parameters to be defined. These parameters are used by the DaVinci interface in order to determine the attributes of nodes and edges to be drawn by DaVinci. We define the layout parameters as follows:

<Layout Parameter>=
LayoutParameter =
unit(edge:unit(default:edge(to:default
                            'EDGECOLOR':black
                            'EDGEPATTERN':solid
                            '_DIR':none
                            'HEAD':arrow)
               dom:edge('EDGECOLOR':blue
                        'EDGEPATTERN':dotted)
               void:edge('EDGEPATTERN':none)
              )
     label: unit(default:label('COLOR':white
                               '_GO':text
                               'OBJECT':default)
                )
    )

We are now in the position to draw the graph given above. First, you have to specify the path at which your executable DaVinci is situated.

<DaVinci Path>=
%% The value of   DaVinciPath   has to be adapted to be  
%% the path where to find the executable DaVinci-binaries
 
DaVinciPath= "/export/global/ps/soft/daVinci_V2.1/linux-i486/daVinci"

Next, you have to specfy the pickle version that your Mozart system requires.

<Pickle Version>=
%% The value of Version determines the pickle version
%% required by your Oz System. Mozart 1.0.1 requires
%% version 1.5 and Mozart 1.1.0 needs version 2.0.
 
Version = 'Version.3.2'

Next, you have the combine the above graph and layout parameter with the DaVinci Interface.

<Draw the Example Graph>=
%% this file contains an example for the Oz-DaVinci-Interface
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% the following constants have to be adapted.
%%
 
declare 
<DaVinci Path> 
<Pickle Version> 
 
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
%% the following constants remain unchanged.
 
URL = 'http://www.ps.uni-sb.de/~niehren/DaVinci' 
GraphOzf = '/'#Version#'/graph.ozf' 
PipeOzf  = '/'#Version#'/pipe.ozf' 
     
[Mod1 Mod2] = {Module.link [URL#GraphOzf URL#PipeOzf]}
 
MakeDaVinciGraph = {Mod1.daVinciGraph LayoutParameter}
MakeDaVinciEdges = {Mod1.daVinciEdges LayoutParameter}
NewDaVinci = {Mod2.makeNewDaVinci DaVinciPath}
 
<Layout Parameter> 
<Example Graph> 
 
DVG = {MakeDaVinciGraph Graph} {Browse DVG}
DaVinci = {NewDaVinci}  
{DaVinci.graph DVG}


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)