Jump to: navigation, search

Difference between revisions of "Zest/DOT"

m (Progress: Added milestone 5 download link and updated status)
m (Graphviz DOT as a DSL for Zest moved to Zest/DOT: Consistency with other Zest documentation (Zest, Zest/Cloudio))
(33 intermediate revisions by one other user not shown)
Line 1: Line 1:
This is the wiki page for a [[Google Summer of Code 2009]] project.
+
[[Image:DotForZest.png|right|thumb|Graphviz DOT as a DSL for Zest]]
  
<table border="0" cellspacing="3" cellpadding="2" width="100%">
+
''Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in [http://wiki.eclipse.org/Graphviz_DOT_as_a_DSL_for_Zest the original wiki page]''
<tr align="center" bgcolor="#595791">
+
                <td><font color="#FFFFFF"><b> Title </b></font></td>
+
<td><font color="#FFFFFF"><b> Student </b></font></td>
+
<td><font color="#FFFFFF"><b> Mentor </b></font></td>
+
<td><font color="#FFFFFF"><b> Eclipse Project</b></font></td>
+
<td><font color="#FFFFFF"><b> Google Page</b></font></td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
                <td>Graphviz DOT as a DSL for Zest</td>
+
<td>[[User:Steeg.netcologne.de|Fabian Steeg]] (IRC: fsteeg)</td>
+
<td>Ian Bull</td>
+
<td>[[GEF]] (component: [[GEF Zest Visualization|Zest]])</td>
+
                <td>[http://socghop.appspot.com/student_project/show/google/gsoc2009/eclipse/t124022230869 Student Project]</td>
+
</tr>
+
</table>
+
  
The goal of this project is to implement the [http://www.graphviz.org/ Graphviz] [http://www.graphviz.org/doc/info/lang.html DOT language] as a domain-specific language (DSL) for [http://www.eclipse.org/gef/zest/ Zest: The Eclipse Visualization Toolkit], both as an input and output format. In other words, the goal is to transform both DOT graphs to Zest visualizations (to be used in Java SWT applications), and Zest visualizations to DOT graphs (to be rendered as image files with Graphviz).  
+
This Eclipse feature provides support for the [http://www.graphviz.org/ Graphviz] [http://www.graphviz.org/doc/info/lang.html DOT language] in [http://www.eclipse.org/gef/zest/ Zest: The Eclipse Visualization Toolkit], both as an input and output format. It provides API und UI elements to transform both DOT graphs to Zest visualizations (to be used in Java SWT applications), and Zest visualizations to DOT graphs (to be rendered as image files with Graphviz).
  
==Resources==
+
== User Documentation ==
  
[[Image:DotZestBundles.png|thumb|right|350px|Bundles and dependencies]]
+
=== Installation ===
  
The main bug for this project is {{bug|277380}}. View a [https://bugs.eclipse.org/bugs/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__all__&product=GEF&content=%5Bdot4zest%5D complete list] of related bugs. If you have suggestions for this project you can [https://bugs.eclipse.org/bugs/enter_bug.cgi?bug_file_loc=http%3A%2F%2Fwiki.eclipse.org%2FGraphviz_DOT_as_a_DSL_for_Zest&bug_severity=enhancement&bug_status=NEW&comment=&component=Zest&contenttypeentry=&contenttypemethod=autodetect&contenttypeselection=text%2Fplain&data=&description=&flag_type-1=X&flag_type-2=X&flag_type-6=X&form_name=enter_bug&maketemplate=Remember%20values%20as%20bookmarkable%20template&op_sys=All&priority=P3&product=GEF&rep_platform=All&short_desc=%5Bdot4zest%5D%20New%20request%20summary&version=unspecified file a new bug]. The CVS repository for this project is located at ''cvs.dot4zest.berlios.de:/cvsroot/dot4zest''; [http://developer.berlios.de/cvs/?group_id=10849 access info]. You can also [http://download.berlios.de/cvstarballs/dot4zest-cvsroot.tar.gz download nightly CVS snapshots].
+
This feature is part of Zest 2. See further information on [[Zest#Zest_2.x|Zest 2]].
  
To run the current work in progress code, check out the bundles from the CVS repository above in Eclipse 3.5 (Galileo) and install the Zest and JET features (which are available from the Galileo update site; you have to uncheck 'group items by category' to see the Zest features).
+
=== GUI ===
  
You also need to install the oAW 4.3.1 Graphviz feature from the oAW update site at ''http://oawbranch.pluginbuilder.org/releases/p2-updateSite/''.
+
This feature adds a DOT editor and a Zest graph view to the UI:
  
Run the ''*Suite.java'' test suites of the individual bundles (in src-test/) as JUnit tests to get an impression of the current implementation state. To test the UI components, run an Eclipse application configured with org.eclipse.zest.dot.ui and required plugins. See details on usage in the milestone sections below.
+
[[Image:DotZestViewSelection.png]]
  
==Progress==
+
==== Zest Graph View ====
  
===Milestone 5===
+
The Zest Graph view can visualize DOT graphs in *.dot files or embedded in other files in the workspace. The view draws the DOT graphs using Zest and allows for image export of the current Zest graph. When automatic updating is enabled (see below), and a *.dot file or embedded DOT content is added to the workspace or altered in an editor, the Zest graph view is updated with the graph created from the DOT input. For instance, consider a file with the .dot extension, containing the following DOT graph definition:
  
[https://bugs.eclipse.org/bugs/attachment.cgi?id=141378 Milestone 5] adds a basic Graphviz-compatible animation DSL for Zest ({{bug|277402}}) by adding animation support to the DOT-to-Zest transformations, representing animation steps as subgraphs in the DOT input (which if rendered with Graphviz results in a static description of the animation).
+
digraph s{
 +
  n1[label="Node 1"]; n2[label="Node 2"];
 +
  n1 -> n2[style=dotted label="A dotted edge"]
 +
}
 +
 
 +
The view will display:
  
[[Image:DotZestM5Screenshot1.png|right|150px]]
+
[[Image:DotZestGraphView.png|200px]]
[[Image:DotZestM5Screenshot2.png|right|150px]]
+
  
For instance, for the input below a Zest animation is created in which the single steps can be executed by clicking the button below the graph (see screenshots on the right for the first step and the final state of the graph):
+
The view contains buttons to toggle automatic updates, to load a specific file containing a DOT graph, and to layout the current graph. To export the current Zest graph as an image file by calling the ''dot'' executable, the view contains buttons to re-select the directory containing the ''dot'' executable, to enable export of the original DOT input, and to export as an image file (from left to right). When the image export button is selected, a PDF for the current graph is saved in the directory containing the file with the DOT input, and opened with the associated external editor, if one is available. In this example, the export looks like this:
  
<pre>
+
[[Image:DotZestM2Rendered.png]]
digraph SampleAnimation {
+
/* We can specify a Zest layout for the animation here: */
+
layout=tree // = TreeLayoutAlgorithm
+
/* Global attributes can be defined for edges and nodes: */
+
  node[label="Node"]
+
  edge[label="Edge" style=dotted]
+
1;2;3;4;5
+
/* The single animation steps are marked by numbers: */
+
subgraph cluster_0{ 1 -> 2 [label="Dashed" style=dashed]}
+
subgraph cluster_1{ 1 -> 3 }
+
/* The final animation step needs to be marked with "end": */
+
subgraph cluster_2_end{ 3 -> 4; 3 -> 5}
+
}
+
</pre>
+
  
See the included [http://cvs.berlios.de/cgi-bin/viewvc.cgi/dot4zest/org.eclipse.zest.dot.import/resources/tests/ test files] and the graph wizard for further samples. The example above is automatically created when a Zest project is created with the wizard (see milesotne 4 below).
+
This provides a Zest-based DOT authoring environment. If a *.dot file or embedded DOT is edited, it will be visualized in the Zest Graph view (e.g. during editing), and can be exported as a PDF with Graphviz.
  
===Milestone 4===
+
At the same time the view provides a simple way to visualize *.dot file output of any kind of program, e.g. to visualize and debug internal data structures, results, etc: if a program running in Eclipse outputs any *.dot file in the workspace and the workspace is refreshed, the view will be updated with the corresponding Zest graph (if automatic updating is enabled, see above).
  
[https://bugs.eclipse.org/bugs/attachment.cgi?id=140320 Milestone 4] adds a Zest project type with Graphviz support ({{bug|277400}}) by implementing a Zest project nature, builder, and wizard. The project created by the wizard has a 'templates' folder containing a sample DOT file. The DOT files in the 'templates' folder are compiled to Zest graph subclasses by the builder. These can be launched as Java applications to view the Zest Graph:
+
==== Editing ====
  
[[Image:DotZestM4Screenshot.png]]
+
The Zest view can be used with the included DOT editor to visualize a DOT file:
  
Effectively this implements a basic Zest authoring environment using DOT as a DSL, as upon saving the DOT file, the same Zest application can be relaunched, showing the updated Zest graph created from the changed DOT file.
+
[[Image:DotZestEditor.png|400px]]
  
===Milestone 3===
+
Additionally, the Zest view also displays embedded DOT in other files, e.g. [http://fsteeg.wordpress.com/2010/01/07/visual-textual-documentation-with-dot-and-zest-in-eclipse/ in source code comments] or [http://fsteeg.wordpress.com/2010/02/07/diagrams-in-wiki-markup-with-mylyn-wikitext-dot-and-zest/ in wiki markup]:
  
[https://bugs.eclipse.org/bugs/attachment.cgi?id=139816 Milestone 3] adds a Zest wizard for Graphviz import ({{bug|277399}}) that generates a new Zest graph implementation class (which supports DOT export), based on customizable DOT templates or direct input in the wizard.
+
[[Image:DotZestWikiText.png|400px]]
  
[[Image:DotZestM3Screenshot.png|300px]]
+
=== API ===
  
For detailed usage instructions see the included documentation (org.eclipse.zest.dot.ui/documentation.html).
+
Via the API, DOT can be imported to Zest graph instances, and Zest graph instances can be exported to DOT.
  
===Milestone 2===
+
To use the API, create a new Plug-in project, add ''org.eclipse.zest.dot.core'' to the MANIFEST.MF dependencies, paste the code below into the source folder of the created project, and select ''Run As > Java Application'':
  
[https://bugs.eclipse.org/bugs/attachment.cgi?id=138738 Milestone 2] adds basic Graphviz export for Zest ({{bug|277398}}) by generating a DOT file or string from a Zest graph instance:
+
  import org.eclipse.swt.SWT;
 +
  import org.eclipse.swt.layout.FillLayout;
 +
  import org.eclipse.swt.widgets.Display;
 +
  import org.eclipse.swt.widgets.Shell;
 +
  import org.eclipse.zest.dot.DotGraph;
 +
 
 +
  public class SampleUsage {
 +
 
 +
    public static void main(String[] args) {
 +
      Shell shell = new Shell();
 +
      DotGraph graph = new DotGraph("digraph{ 1->2 }", shell, SWT.NONE);
 +
      graph.add("2->3").add("2->4");
 +
      graph.add("node[label=zested]; edge[style=dashed]; 3->5; 4->6");
 +
      open(shell);
 +
      System.out.println(graph.toDot());
 +
    }
 +
 
 +
    private static void open(final Shell shell) {
 +
      shell.setText(DotGraph.class.getSimpleName());
 +
      shell.setLayout(new FillLayout());
 +
      shell.setSize(600, 300);
 +
      shell.open();
 +
      Display display = shell.getDisplay();
 +
      while (!shell.isDisposed())
 +
        if (!display.readAndDispatch())
 +
          display.sleep();
 +
      display.dispose();
 +
    }
 +
   
 +
  }
  
[[Image:DotZestM2.png|200px]]
+
The complete sample usage is [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gef/test/org.eclipse.zest.dot.tests/src/org/eclipse/zest/tests/dot/SampleUsage.java?root=Tools_Project&view=markup available in the repository], as well as working [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gef/test/org.eclipse.zest.dot.tests/resources/tests/?root=Tools_Project DOT input samples].
  
For instance, the input and the result can look as follows:
+
=== Layouts ===
  
[[Image:DotZestM2Rendered.png|thumb|135px|right|Graphviz-rendered export]]
+
==== DOT import ====
  
<pre>
+
During import of DOT graphs into Zest, the DOT layout specified in the input is mapped to the most suitable Zest layout algorithm - e.g. for the following DOT graph:
/* Set up a directed Zest graph with a single connection: */
+
Graph graph = new Graph(shell, SWT.NONE);
+
graph.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
+
GraphConnection edge = new GraphConnection(graph, SWT.NONE,
+
        new GraphNode(graph, SWT.NONE, "Node 1"),
+
        new GraphNode(graph, SWT.NONE, "Node 2"));
+
edge.setText("A dotted edge");
+
edge.setLineStyle(SWT.LINE_DOT);
+
/* Export the Zest graph to a DOT string or a DOT file: */
+
System.out.println(DotExport.exportZestGraph(graph));
+
DotExport.exportZestGraph(graph, new File("src-gen/DirectSample.dot"));
+
</pre>
+
  
See the included [http://cvs.berlios.de/cgi-bin/viewvc.cgi/dot4zest/org.eclipse.zest.dot.export/src-test/org/eclipse/zest/DotExportSample.java?view=markup sample] (from above), [http://cvs.berlios.de/cgi-bin/viewvc.cgi/dot4zest/org.eclipse.zest.dot.export/src-test/org/eclipse/zest/dot/test_data test files], and documentation for further information.
+
graph { 1--2--3; 2--4--5 }
  
 +
If the graph defines a Graphviz layout, it is mapped to a Zest layout as below:
  
===Milestone 1===
+
graph[layout=dot];
  
[https://bugs.eclipse.org/bugs/attachment.cgi?id=137800 Milestone 1] implements basic Graphviz import for Zest ({{bug|277397}}) by generating a Zest Graph subclass from a DOT description:
+
[[Image:Zest2-dot-zest.png|150px]]
  
[[Image:DotZestM1.png|200px]]
+
graph[layout=fdp];
  
For instance, the input and output can look as follows:
+
[[Image:Zest2-fdp-zest.png|150px]]
  
[[Image:DotZestM1Screenshot.png|right]]
+
graph[layout=twopi];
  
<pre>
+
[[Image:Zest2-twopi-zest.png|150px]]
digraph SampleGraph{
+
/* Specify the Zest layout algorithm to use: */
+
layout=grid
+
/* Global attributes can be defined for edges and nodes: */
+
edge[label="Edge" style=dashed]
+
node[label="Node"]
+
1; 2
+
/* Override node attributes from above: */
+
3[label="Leaf1"]
+
4[label="Leaf2"]
+
1->2
+
2->3
+
/* Override edge attributes from above: */
+
2->4[label="Dotted" style=dotted]
+
}
+
</pre>
+
  
See the included [http://cvs.berlios.de/cgi-bin/viewvc.cgi/dot4zest/org.eclipse.zest.dot.import/resources/tests/ test files] and documentation for further samples.
+
graph[layout=osage];
  
===Timeline===
+
[[Image:Zest2-osage-zest.png|150px]]
  
<div style="clear: right; border: solid #aaa 1px; margin: 0 0 1em 1em; font-size: 90%; background: #f9f9f9; width: 180px; padding: 4px; text-align: left; float: right;"> [[Image:Glass.gif]] Pending [[Image:Progress.gif]] Active [[Image:Ok_green.gif]] Done </div>
+
==== DOT export ====
  
The intended timeline consists of 6 core and 2 optional milestones. This should ensure providing the core functionality described below even if things take longer than expected, and very flexible, integrated and complete (realizing and using all the connections in the figure below) support for existing Eclipse visualization technology if all works out as planned.
+
When Zest graphs are exported to DOT (whether created from DOT or not), the most suitable Graphviz layout is choosen, e.g.:
  
<table border="0" cellspacing="3" cellpadding="2" width="100%">
+
graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(), false); graph.toDot();
<tr align="center" bgcolor="#595791">
+
<td><font color="#FFFFFF"><b>Milestone</b></font></td>
+
<td><font color="#FFFFFF"><b>Weeks</b></font></td>
+
<td><font color="#FFFFFF"><b>Date</b></font></td>
+
<td><font color="#FFFFFF"><b>What</b></font></td>
+
<td><font color="#FFFFFF"><b>How</b></font></td>
+
        <td><font color="#FFFFFF"><b>Planned Bundle</b></font></td>
+
        <td><font color="#FFFFFF"><b>Bugs</b></font></td>
+
        <td><font color="#FFFFFF"><b>Status</b></font></td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
<td>M1</td>
+
<td>1</td>
+
<td>2009-05-31</td>
+
<td>Core Graphviz import to create standalone Zest</td>
+
<td>Generate basic Zest code from a DOT meta model instance
+
(using Xpand)</td>
+
        <td>org.eclipse.zest.dot.import (dep.: org.openarchitectureware.graphviz and Zest)</td>
+
        <td>{{bug|277397}}</td>
+
        <td>[[Image:Ok_green.gif]]</td>
+
</tr>
+
<tr align="center" bgcolor="#e0d0e6">
+
<td>M2</td>
+
<td>2</td>
+
<td>2009-06-14</td>
+
<td>Core Graphviz export for standalone Zest</td>
+
<td>Generate DOT output from a Zest graph instance (using JET)</td>
+
        <td>org.eclipse.zest.dot.export (dep.: Zest only)</td>
+
        <td>{{bug|277398}}</td>
+
        <td>[[Image:Ok_green.gif]]</td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
<td>M3</td>
+
<td>1</td>
+
<td>2009-06-21</td>
+
<td>UI for initial Graphviz to Zest import</td>
+
<td>Wizard for a new Zest Graph with DOT export based on a DOT
+
file or direct input (based on M1 and M2)</td>
+
        <td>org.eclipse.zest.dot.ui (dep.: org.eclipse.zest.dot.import, org.eclipse.ui)</td>
+
        <td>{{bug|277399}}</td>
+
        <td>[[Image:Ok_green.gif]]</td>
+
</tr>
+
<tr align="center" bgcolor="#e0d0e6">
+
<td>M4</td>
+
<td>1</td>
+
<td>2009-06-28</td>
+
<td>UI for maintaining Graphviz representations of Zest
+
visualizations</td>
+
<td>Project builder, wizard and nature for Zest projects that
+
create Zest graphs from Graphviz DOT files placed in a dedicated folder (based on M1 and M2)</td>
+
        <td>org.eclipse.zest.dot.ui (see above)</td>
+
        <td>{{bug|277400}}</td>
+
        <td>[[Image:Ok_green.gif]]</td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
<td>M5</td>
+
<td>2</td>
+
<td>2009-07-12</td>
+
<td>Basic form of a Graphviz-compatible animation DSL for
+
Zest</td>
+
<td>Animation support for the DOT to Zest transformations,
+
representing animation steps as subgraphs (based on M1)</td>
+
        <td>org.eclipse.zest.dot.import (see above)</td>
+
        <td>{{bug|277402}}</td>
+
        <td>[[Image:Ok_green.gif]]</td>
+
</tr>
+
<tr align="center" bgcolor="#e0d0e6">
+
<td>(Mid-term)</td>
+
<td>-</td>
+
<td>2009-07-13</td>
+
<td>-</td>
+
<td>-</td>
+
        <td>-</td>
+
        <td>-</td>
+
        <td>-</td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
<td>M6</td>
+
<td>1</td>
+
<td>2009-07-19</td>
+
<td>Support for the Zest-based EMF model visualizer view</td>
+
<td>Transformation from DOT meta model instances to the EMF model
+
visualizer language (using Xpand)</td>
+
        <td>TBD</td>
+
        <td>-</td>
+
        <td>[[Image:Glass.gif]]</td>
+
</tr>
+
<tr align="center" bgcolor="#e0d0e6">
+
<td>M7 (optional)</td>
+
<td>1.5</td>
+
<td>2009-07-30</td>
+
<td><i>optional:</i> Standalone Zest and DOT export for the EMF model visualizer language</td>
+
<td>Transformation from EMF model visualizer language meta model instances
+
to the DOT language (using Xpand)</td>
+
        <td>TBD</td>
+
        <td>-</td>
+
        <td>-</td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
<td>M8 (optional)</td>
+
<td>1.5</td>
+
<td>2009-08-09</td>
+
<td><i>optional:</i> Support for exporting Zest graphs to image files directly</td>
+
<td>Use the existing Xpand transformation from oAW which creates a
+
command-line script that calls a local Graphviz installation</td>
+
        <td>TBD</td>
+
        <td>-</td>
+
        <td>-</td>
+
</tr>
+
<tr align="center" bgcolor="#e0d0e6">
+
<td>RC</td>
+
<td>1</td>
+
<td>2009-08-16</td>
+
<td>Wrap up</td>
+
<td>Complete and polish documentation, samples, tests and packaging (update site)</td>
+
<td>-</td>
+
        <td>-</td>
+
        <td>-</td>
+
</tr>
+
<tr align="center" bgcolor="#faf7fb">
+
<td>(Pencils down)</td>
+
<td>-</td>
+
<td>2009-08-17</td>
+
<td>-</td>
+
                <td>-</td>
+
<td>-</td>
+
        <td>-</td>
+
        <td>-</td>
+
</tr>
+
</table>
+
  
==Motivation==
+
[[Image:Zest2-dot-graphviz.png|100px]]
  
I believe both Graphviz input and output for Zest would make a lot of sense: Graphviz is a very popular tool and its DOT language is widely used. Support for it could make using Zest very easy for many people who are familiar with DOT.  
+
graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(), false); graph.toDot();
  
It would also be useful for existing Eclipse tools that are based on Graphviz, like [http://abstratt.com/textuml/ TextUML] or [http://eclipsegraphviz.wiki.sourceforge.net/ EclipseGraphviz], and possibly others, for instance in the [http://tasktop.com/blog/eclipse/rich-editing-for-tasks-via-mylyn-wikitext Mylyn rich task editor] (for embedding DOT graphs in the wiki text markup, visualized with Zest).
+
[[Image:Zest2-fdp-graphviz.png|150px]]
  
On the output side, Zest could benefit from Graphviz output as it provides a way to produce high-quality export into different file formats, e.g. for printing Zest visualizations, or using them in  digital publications.
+
graph.setLayoutAlgorithm(new RadialLayoutAlgorithm(), false); graph.toDot();
  
As Graphviz supports many different node shapes, edge styles, layouts etc. the goal of this project is not to provide support for all Graphviz features (or even as many as possible), but to set up initial basic support (directed and undirected graphs, edge and node labels, edge styles, basic layout support) and focus on the infrastructure to make these transformations usable instead (see user interface section below), which will hopefully create a solid foundation for future expansion (see section on future ideas below).
+
[[Image:Zest2-twopi-graphviz.png|150px]]
  
==Implementation==
+
graph.setLayoutAlgorithm(new GridLayoutAlgorithm(), false); graph.toDot();
  
I plan to implement the desired functionality based on [http://www.eclipse.org/modeling/ Eclipse Modeling] technologies, in particular [http://wiki.eclipse.org/Xtext Xtext] (part of [http://www.eclipse.org/modeling/tmf TMF]) and [http://wiki.eclipse.org/Xpand Xpand] (part of [http://www.eclipse.org/modeling/m2t M2T]) for the input part (parse DOT, generate Zest) and [http://wiki.eclipse.org/M2T-JET JET] for the output (see details below). The sketched approach (see figure on the right) depends on Eclipse components only (Xtext, Xpand, JET, and oAW).
+
[[Image:Zest2-osage-graphviz.png|150px]]
  
[[Image:DotZestOverview.png|thumb|275px|right|Implementing Graphviz DOT input and output for Zest using Eclipse modeling technology (solid arrows represent existing components)]]
+
=== Subgraphs ===
  
===DOT to Zest===
+
Cluster subgraphs imported to a Zest Graph instance are rendered as Zest graph containers, e.g.:
  
An Xtext grammar, parser and Xpand generators for Graphviz DOT already exist in openArchitectureWare (oAW) 4.3 (the relevant bundles org.openarchitectureware.graphviz.*, are now part of the [http://code.google.com/p/emfmodelvisualizer/ EMF model visualizer project]).
+
digraph subgraphs {
 +
  subgraph cluster1 { 1 -> 2; 2 -> 3; 2 -> 4 }
 +
  subgraph cluster2 { a -> b; a -> c; a -> d }
 +
}
  
Based on this, my plan is to implement an Xpand generator that transforms Graphviz DOT descriptions into Java code that creates an equivalent Zest visualization (see figure on the right and M1 in the timeline below). I also want to provide a way to define Zest animations using the DOT language (by representing animation steps as subgraphs in DOT, see M5 in the timeline).
+
[[Image:DotZestSubgraphs1.png|400px]]
  
===Zest to DOT===
+
Cluster subgraphs can be labeled and can define their own layouts, e.g.:
  
To transform Zest graph instances to the Graphviz DOT language I intend to use [http://wiki.eclipse.org/M2T-JET JET] (see figure on the right and M2 in the timeline).
+
digraph agent {
 +
  subgraph cluster1 { label = "the agent likes martinis"
 +
    S -> NP; NP -> the; NP -> agent; S -> VP; VP -> likes; VP -> martinis
 +
  }
 +
  subgraph cluster2 { label = "martinis"; rankdir = LR
 +
    martinis -> pos; martinis -> number; martinis -> semantics; martinis -> grammar
 +
    pos -> noun; number -> plural; semantics -> patient; grammar -> object
 +
  }
 +
}
  
There are two reasons I plan to use JET instead of Xpand here. First, I'd like to be able to transform any Zest graph instance to DOT directly (not only those for which we have a DOT meta model instance that could act as the input to Xpand). Second, even if we had a DOT meta model instance (which we could create from the Zest graph), using Xpand would introduce a runtime dependency on the [http://wiki.eclipse.org/Modeling_Workflow_Engine_(MWE) Modeling Workflow Engine], whereas with JET we only introduce a dependency on a single class (the generator class JET created from the template).
+
[[Image:DotZestSubgraphs2.png|400px]]
  
===User Interface===
+
== Developer Documentation ==
  
To make these transformations available to the user, my general plan is to make the DOT to Zest transformations (which depend on Eclipse modeling technology at runtime) available as part of the workbench, while the generated Zest graph classes and the DOT output  can be used directly and without (or with very little, see above) additional runtime dependencies, e.g. in pure Zest SWT applications.
+
The goal of this feature is to implement the [http://www.graphviz.org/ Graphviz] [http://www.graphviz.org/doc/info/lang.html DOT language] as a domain-specific language (DSL) for [http://www.eclipse.org/gef/zest/ Zest: The Eclipse Visualization Toolkit], both as an input and output format. In other words, the goal is to transform both DOT graphs to Zest visualizations (to be used in Java SWT applications), and Zest visualizations to DOT graphs (to be rendered as image files with Graphviz).
  
To generate Zest from DOT, I intend to implement a wizard that creates a Zest graph subclass and basic sample usage code (see examples below) from a Graphviz DOT file or from direct DOT input inside the wizard (see M3 in the timeline). I imagine offering different DOT templates to the user (e.g. ''simple directed graph'', ''simple animation''), which can be edited in the wizard, with a live preview of what the Zest graph is going to look like next to it.
+
This feature started as a [http://socghop.appspot.com/student_project/show/google/gsoc2009/eclipse/t124022230869 project] in the [[Google Summer of Code 2009]] by [[User:Steeg.netcologne.de|Fabian Steeg]], mentored by Ian Bull, for [[GEF Zest Visualization|Zest]]. It is included in [[Zest#Zest_2.x|Zest 2]].
  
Extending this kind of functionality, I'd like to implement a Zest project type where the DOT files are placed in a special folder (and can be edited conveniently using the DOT editor from oAW). Using a project builder, the corresponding Zest Graph implementation classes will be generated, which can be used from other parts of the project's code, similar to JET templates and generators (see M4 in the timeline).
+
=== Resources  ===
  
To provide visualization of DOT graphs using Zest in a workbench, I want to create Xpand generators which provide compatibility with the EMF model visualizer language and its Zest-based visualization view (see dotted arrows in the figure above and M6 in the timeline).
+
[[Image:DotZestBundles.png|thumb|right|350px|Bundles and dependencies]]
  
==Examples==
+
The main bug for this feature is {{bug|277380}}. View a [https://bugs.eclipse.org/bugs/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__all__&product=GEF&content=%5Bdot4zest%5D complete list] of related bugs. If you have suggestions for this feature you can [https://bugs.eclipse.org/bugs/enter_bug.cgi?bug_file_loc=http%3A%2F%2Fwiki.eclipse.org%2FGraphviz_DOT_as_a_DSL_for_Zest&bug_severity=enhancement&bug_status=NEW&comment=&component=Zest&contenttypeentry=&contenttypemethod=autodetect&contenttypeselection=text%2Fplain&data=&description=&flag_type-1=X&flag_type-2=X&flag_type-6=X&form_name=enter_bug&maketemplate=Remember%20values%20as%20bookmarkable%20template&op_sys=All&priority=P3&product=GEF&rep_platform=All&short_desc=%5Bdot4zest%5D%20New%20request%20summary&version=unspecified file a new bug]. The code for this feature is part of the Zest 2.0 Git repository. The dot4zest bundles are named ''org.eclipse.zest.dot.*''. See the general instructions for [[Zest#Setup|setting up Zest 2.0]].
  
Below are two examples to concretize what the input could look like and what I in principle plan to generate from that input.
+
After changes to the Xtext grammar, run (Run As -&gt; MWE2 workflow) the ''GenerateDot.mwe2'' in the ''/src/org/eclipse/zest/internal/dot/parser'' folder of the core bundle. Make sure to set the project or workspace encoding to UTF-8.
  
===Minimal===
+
Run the ''All*.java'' test suites of the test bundle (''org.eclipse.zest.tests'') as JUnit or JUnit Pug-in tests to get an impression of the current implementation state. To use the UI components, run an Eclipse application configured with ''org.eclipse.zest.dot.ui'' and required plugins. See details on usage in the user documentation above.
  
[[Image:DotZestSimpleGraphviz.png|right|65px|"digraph simple { 1 -> 2 }"]]
+
===Motivation===
  
As a first example, consider the following minimal DOT graph and how it renders with Graphviz:
+
Graphviz is a very popular tool and its DOT language is widely used. Support for it could make using Zest very easy for many people who are familiar with DOT.
  
<pre>
+
DOT integration for Zest could also be useful for existing Eclipse tools that are based on Graphviz, like [http://abstratt.com/textuml/ TextUML] or [http://eclipsegraphviz.wiki.sourceforge.net/ EclipseGraphviz], and others, for instance in the [http://tasktop.com/blog/eclipse/rich-editing-for-tasks-via-mylyn-wikitext Mylyn rich task editor] (for [http://fsteeg.wordpress.com/2010/02/07/diagrams-in-wiki-markup-with-mylyn-wikitext-dot-and-zest/ embedding DOT graphs in wiki text markup, visualized with Zest]).
digraph simple { 1 -> 2 }
+
</pre>
+
  
From this, roughly the code below should be generated (comments to be generated omitted here). It's a Zest Graph subclass which is populated with the specified objects on construction, and includes export to DOT via a generator class generated by JET (commented out here to make the example compile). It also contains some sample usage code in a main method to make it runnable as a plain Java SWT application, which renders as shown in the image on the right.
+
On the output side, Zest can benefit from Graphviz output as it provides a way to produce high-quality export into different file formats, e.g. for printing Zest visualizations, or using them in digital publications.
+
[[Image:DotZestSimple.png|right|150px]]
+
  
<pre>
+
===Implementation===
/** Zest Graph to be generated from "digraph simple { 1 -> 2 }" */
+
public class SimpleDirectedGraph extends Graph {
+
    public SimpleDirectedGraph(Composite parent, int style) {
+
        super(parent, style);
+
        setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
+
        GraphNode n1 = new GraphNode(this, SWT.NONE, "1");
+
        GraphNode n2 = new GraphNode(this, SWT.NONE, "2");
+
        new GraphConnection(this, SWT.NONE, n1, n2);
+
        setLayoutAlgorithm(new TreeLayoutAlgorithm(
+
                LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
+
    }
+
    public String toString() {
+
        return super.toString(); // new GraphTemplate().generate(this);
+
    }
+
    public static void main(String[] args) {
+
        Display d = new Display();
+
        Shell shell = new Shell(d);
+
        shell.setText(SimpleDirectedGraph.class.getSimpleName());
+
        shell.setLayout(new FillLayout());
+
        shell.setSize(100, 150);
+
        new SimpleDirectedGraph(shell, SWT.NONE);
+
        shell.open();
+
        while (!shell.isDisposed()) {
+
            while (!d.readAndDispatch()) { d.sleep(); }
+
        }
+
    }
+
}
+
</pre>
+
  
===Animation===
+
The dot4zest functionality is implemented based on [http://www.eclipse.org/modeling/ Eclipse Modeling] technologies, in particular [http://wiki.eclipse.org/Xtext Xtext] (part of [http://www.eclipse.org/modeling/tmf TMF]) for the input part (parse DOT, generate Zest) and [http://wiki.eclipse.org/M2T-JET JET] for the output (see details below).
  
[[Image:DotZestAnimationGraphviz.png|right|150px]]
+
[[Image:DotZestOverview.png|thumb|175px|right|Implementation of Graphviz DOT input and output for Zest using Eclipse modeling technology]]
  
In contrast to Graphviz, which only provides static graph visualization, Zest supports animations. By combining the Graphviz DOT language with Zest in a similar manner as described above, creating simple animations with Zest could become very easy.
+
====DOT to Zest====
  
For instance, defining an animation could be done by specifying the individual animation steps as subgraphs (with every subgraph defining how the current graph should be altered in the animation). Subgraphs render in individual boxes with Graphviz:
+
Based on an Xtext grammar, dot4zest interprets the parsed DOT EMF model using the generated Xtext switch API to dynamically create Zest graphs. The Zest graph view uses this to display DOT with Zest (see above).
  
<pre>
+
====Zest to DOT====
digraph simple_animation {
+
    subgraph cluster_0{ 1 -> 2 }
+
    subgraph cluster_1{ 1 -> 3 }
+
}
+
</pre>
+
  
When converted to Zest, such an input could result in generated code as below (comments to be generated again omitted here). When executed, this application renders as on the first image on the right. After clicking the button it changes to the second image.
+
To transform Zest graph instances to the Graphviz DOT language dot4zest uses [http://wiki.eclipse.org/M2T-JET JET].  
  
[[Image:DotZestAnimation1.png|right|200px]]
+
There are two reasons to use JET instead of Xpand here. First, this allows us to transform any Zest graph instance to DOT directly (not only those for which we have a DOT meta model instance that could act as the input to Xpand).  
[[Image:DotZestAnimation2.png|right|200px]]
+
  
<pre>
+
Second, even if we had a DOT meta model instance (which we could create from the Zest graph), using Xpand would introduce a runtime dependency on the [http://wiki.eclipse.org/Modeling_Workflow_Engine_(MWE) Modeling Workflow Engine], whereas with JET we only introduce a dependency on a single class (the generator class JET created from the template).
public class SimpleAnimationGraph extends Graph {
+
    public SimpleAnimationGraph(Composite parent, int style) {
+
        super(parent, style);
+
        setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
+
        setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
+
        final GraphNode n1 = new GraphNode(this, SWT.NONE, "1");
+
        final GraphNode n2 = new GraphNode(this, SWT.NONE, "2");
+
        new GraphConnection(this, SWT.NONE, n1, n2);
+
    }
+
    public String toString() {
+
        return super.toString(); // new GraphTemplate().generate(this);
+
    }
+
    static class AnimationRunner implements Runnable {
+
        private Graph g;
+
        public AnimationRunner(Graph g) { this.g = g; }
+
        public void run() {
+
            Animation.markBegin();
+
            new GraphConnection(g, SWT.NONE, (GraphNode) g.getNodes().get(0),
+
                    new GraphNode(g, SWT.NONE, "3"));
+
            g.applyLayout();
+
            Animation.run(1000);
+
        }
+
    }
+
    public static void main(String[] args) {
+
        Display d = new Display();
+
        final Shell shell = new Shell(d);
+
        shell.setText(SimpleAnimationGraph.class.getSimpleName());
+
        shell.setLayout(new GridLayout(1,false));
+
        shell.setSize(200, 200);
+
        Button b1 = new Button(shell, SWT.PUSH);
+
        b1.setText("Go");
+
        final Graph g = new SimpleAnimationGraph(shell, SWT.NONE);
+
        g.setLayoutData(new GridData(GridData.FILL_BOTH));
+
        b1.addSelectionListener(new SelectionListener() {
+
            public void widgetDefaultSelected(SelectionEvent e) {}
+
            public void widgetSelected(SelectionEvent e) { new AnimationRunner(g).run(); }
+
        });
+
        shell.open();
+
        while (!shell.isDisposed()) {
+
            while (!d.readAndDispatch()) { d.sleep(); }
+
        }
+
    }
+
}
+
</pre>
+
  
Required imports for these examples (omitted above for better readability):
+
===Future Ideas===
 
+
<pre>
+
import org.eclipse.draw2d.Animation;
+
import org.eclipse.swt.SWT;
+
import org.eclipse.swt.events.SelectionEvent;
+
import org.eclipse.swt.events.SelectionListener;
+
import org.eclipse.swt.layout.GridData;
+
import org.eclipse.swt.layout.GridLayout;
+
import org.eclipse.swt.widgets.Button;
+
import org.eclipse.swt.widgets.Composite;
+
import org.eclipse.swt.widgets.Display;
+
import org.eclipse.swt.widgets.Shell;
+
import org.eclipse.zest.core.widgets.Graph;
+
import org.eclipse.zest.core.widgets.GraphConnection;
+
import org.eclipse.zest.core.widgets.GraphNode;
+
import org.eclipse.zest.core.widgets.ZestStyles;
+
import org.eclipse.zest.layouts.LayoutStyles;
+
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
+
</pre>
+
 
+
==Future Plans==
+
 
+
Possible extensions of this project which are probably out of scope for the SOC period include:
+
  
 
* Add support for different Graphviz shapes through [http://eclipsesource.com/blogs/2009/03/20/just-in-time-for-eclipsecon-custom-figures-in-zest/ Zest custom figures], e.g. for UML class diagrams
 
* Add support for different Graphviz shapes through [http://eclipsesource.com/blogs/2009/03/20/just-in-time-for-eclipsecon-custom-figures-in-zest/ Zest custom figures], e.g. for UML class diagrams
 
* Add support to visualize Graphviz subgraphs as separate Zest graphs that can be accessed from the main graph
 
* Add support to visualize Graphviz subgraphs as separate Zest graphs that can be accessed from the main graph
 
* Look into possible ways of supporting Graphviz edge decorators (open or closed arrows, diamonds, etc.)
 
* Look into possible ways of supporting Graphviz edge decorators (open or closed arrows, diamonds, etc.)
* Evaluate possible integration as an actual part of the Zest API, e.g.:  
+
* Map all graph, node and edge attributed from DOT input to corresponding Zest widget data (currently supported for graph attributes)
<pre>
+
* Add animation support using something like ''subgraph cluster_animation_1 { label = "Step 1"; 1->2 }'' etc., where animation steps are represented as subgraphs in the DOT input (which if rendered with Graphviz results in a static description of the animation)
graph.add("1->2"); // use DOT snippets to build the Zest graph
+
 
graph.load("graph.dot"); // load an entire DOT graph into an existing Zest graph
+
For instance, for the input below a Zest animation could be created that changes like this (this is an experimental illustation of the idea):
</pre>
+
 
 +
digraph SampleAnimation {
 +
  /* We can specify a Zest layout for the animation here: */
 +
  layout=tree // = TreeLayoutAlgorithm
 +
  /* Global attributes can be defined for edges and nodes: */
 +
  node[label="Node"]
 +
  edge[label="Edge" style=dotted]
 +
  1;2;3;4;5
 +
  /* The single animation steps are marked by numbers: */
 +
  subgraph cluster_animation_0{ 1 -> 2 [label="Dashed" style=dashed]}
 +
  subgraph cluster_animation_1{ 1 -> 3 }
 +
  subgraph cluster_animation_2{ 3 -> 4; 3 -> 5}
 +
}
 +
 
 +
After the first step:
 +
 
 +
[[Image:DotZestM5Screenshot1.png|200px]]
 +
 
 +
And the final state of the graph:
 +
 
 +
[[Image:DotZestM5Screenshot2.png|200px]]
 +
 
 +
The same input file, exported with Graphviz, shows the animation steps as subgraphs:
 +
 
 +
[[Image:DotZestAnimatedExport.png|200px]]
 +
 
 +
A possible use case for defining such animations with DOT is to easily create animated documentation, e.g. to explain data structures. The same file defining the animation could be used to export a PDF illustrating the steps in a static way.
  
 
[[Category:SOC]]
 
[[Category:SOC]]
 
[[Category:GEF]]
 
[[Category:GEF]]

Revision as of 09:05, 6 September 2011

Graphviz DOT as a DSL for Zest

Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in the original wiki page

This Eclipse feature provides support for the Graphviz DOT language in Zest: The Eclipse Visualization Toolkit, both as an input and output format. It provides API und UI elements to transform both DOT graphs to Zest visualizations (to be used in Java SWT applications), and Zest visualizations to DOT graphs (to be rendered as image files with Graphviz).

User Documentation

Installation

This feature is part of Zest 2. See further information on Zest 2.

GUI

This feature adds a DOT editor and a Zest graph view to the UI:

DotZestViewSelection.png

Zest Graph View

The Zest Graph view can visualize DOT graphs in *.dot files or embedded in other files in the workspace. The view draws the DOT graphs using Zest and allows for image export of the current Zest graph. When automatic updating is enabled (see below), and a *.dot file or embedded DOT content is added to the workspace or altered in an editor, the Zest graph view is updated with the graph created from the DOT input. For instance, consider a file with the .dot extension, containing the following DOT graph definition:

digraph s{ 
 n1[label="Node 1"]; n2[label="Node 2"]; 
 n1 -> n2[style=dotted label="A dotted edge"]
}
 

The view will display:

DotZestGraphView.png

The view contains buttons to toggle automatic updates, to load a specific file containing a DOT graph, and to layout the current graph. To export the current Zest graph as an image file by calling the dot executable, the view contains buttons to re-select the directory containing the dot executable, to enable export of the original DOT input, and to export as an image file (from left to right). When the image export button is selected, a PDF for the current graph is saved in the directory containing the file with the DOT input, and opened with the associated external editor, if one is available. In this example, the export looks like this:

DotZestM2Rendered.png

This provides a Zest-based DOT authoring environment. If a *.dot file or embedded DOT is edited, it will be visualized in the Zest Graph view (e.g. during editing), and can be exported as a PDF with Graphviz.

At the same time the view provides a simple way to visualize *.dot file output of any kind of program, e.g. to visualize and debug internal data structures, results, etc: if a program running in Eclipse outputs any *.dot file in the workspace and the workspace is refreshed, the view will be updated with the corresponding Zest graph (if automatic updating is enabled, see above).

Editing

The Zest view can be used with the included DOT editor to visualize a DOT file:

DotZestEditor.png

Additionally, the Zest view also displays embedded DOT in other files, e.g. in source code comments or in wiki markup:

DotZestWikiText.png

API

Via the API, DOT can be imported to Zest graph instances, and Zest graph instances can be exported to DOT.

To use the API, create a new Plug-in project, add org.eclipse.zest.dot.core to the MANIFEST.MF dependencies, paste the code below into the source folder of the created project, and select Run As > Java Application:

 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.zest.dot.DotGraph;
 
 public class SampleUsage {
 
   public static void main(String[] args) {
     Shell shell = new Shell();
     DotGraph graph = new DotGraph("digraph{ 1->2 }", shell, SWT.NONE);
     graph.add("2->3").add("2->4");
     graph.add("node[label=zested]; edge[style=dashed]; 3->5; 4->6");
     open(shell);
     System.out.println(graph.toDot());
   }
 
   private static void open(final Shell shell) {
     shell.setText(DotGraph.class.getSimpleName());
     shell.setLayout(new FillLayout());
     shell.setSize(600, 300);
     shell.open();
     Display display = shell.getDisplay();
     while (!shell.isDisposed())
       if (!display.readAndDispatch())
         display.sleep();
     display.dispose();
   }
   
 }

The complete sample usage is available in the repository, as well as working DOT input samples.

Layouts

DOT import

During import of DOT graphs into Zest, the DOT layout specified in the input is mapped to the most suitable Zest layout algorithm - e.g. for the following DOT graph:

graph { 1--2--3; 2--4--5 }

If the graph defines a Graphviz layout, it is mapped to a Zest layout as below:

graph[layout=dot];

Zest2-dot-zest.png

graph[layout=fdp];

Zest2-fdp-zest.png

graph[layout=twopi];

Zest2-twopi-zest.png

graph[layout=osage];

Zest2-osage-zest.png

DOT export

When Zest graphs are exported to DOT (whether created from DOT or not), the most suitable Graphviz layout is choosen, e.g.:

graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(), false); graph.toDot();

Zest2-dot-graphviz.png

graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(), false); graph.toDot();

Zest2-fdp-graphviz.png

graph.setLayoutAlgorithm(new RadialLayoutAlgorithm(), false); graph.toDot();

Zest2-twopi-graphviz.png

graph.setLayoutAlgorithm(new GridLayoutAlgorithm(), false); graph.toDot();

Zest2-osage-graphviz.png

Subgraphs

Cluster subgraphs imported to a Zest Graph instance are rendered as Zest graph containers, e.g.:

digraph subgraphs {
  subgraph cluster1 { 1 -> 2; 2 -> 3; 2 -> 4 }
  subgraph cluster2 { a -> b; a -> c; a -> d }
}

DotZestSubgraphs1.png

Cluster subgraphs can be labeled and can define their own layouts, e.g.:

digraph agent {
  subgraph cluster1 { label = "the agent likes martinis"
    S -> NP; NP -> the; NP -> agent; S -> VP; VP -> likes; VP -> martinis
  }
  subgraph cluster2 { label = "martinis"; rankdir = LR
    martinis -> pos; martinis -> number; martinis -> semantics; martinis -> grammar
    pos -> noun; number -> plural; semantics -> patient; grammar -> object
  }
}

DotZestSubgraphs2.png

Developer Documentation

The goal of this feature is to implement the Graphviz DOT language as a domain-specific language (DSL) for Zest: The Eclipse Visualization Toolkit, both as an input and output format. In other words, the goal is to transform both DOT graphs to Zest visualizations (to be used in Java SWT applications), and Zest visualizations to DOT graphs (to be rendered as image files with Graphviz).

This feature started as a project in the Google Summer of Code 2009 by Fabian Steeg, mentored by Ian Bull, for Zest. It is included in Zest 2.

Resources

Bundles and dependencies

The main bug for this feature is bug 277380. View a complete list of related bugs. If you have suggestions for this feature you can file a new bug. The code for this feature is part of the Zest 2.0 Git repository. The dot4zest bundles are named org.eclipse.zest.dot.*. See the general instructions for setting up Zest 2.0.

After changes to the Xtext grammar, run (Run As -> MWE2 workflow) the GenerateDot.mwe2 in the /src/org/eclipse/zest/internal/dot/parser folder of the core bundle. Make sure to set the project or workspace encoding to UTF-8.

Run the All*.java test suites of the test bundle (org.eclipse.zest.tests) as JUnit or JUnit Pug-in tests to get an impression of the current implementation state. To use the UI components, run an Eclipse application configured with org.eclipse.zest.dot.ui and required plugins. See details on usage in the user documentation above.

Motivation

Graphviz is a very popular tool and its DOT language is widely used. Support for it could make using Zest very easy for many people who are familiar with DOT.

DOT integration for Zest could also be useful for existing Eclipse tools that are based on Graphviz, like TextUML or EclipseGraphviz, and others, for instance in the Mylyn rich task editor (for embedding DOT graphs in wiki text markup, visualized with Zest).

On the output side, Zest can benefit from Graphviz output as it provides a way to produce high-quality export into different file formats, e.g. for printing Zest visualizations, or using them in digital publications.

Implementation

The dot4zest functionality is implemented based on Eclipse Modeling technologies, in particular Xtext (part of TMF) for the input part (parse DOT, generate Zest) and JET for the output (see details below).

Implementation of Graphviz DOT input and output for Zest using Eclipse modeling technology

DOT to Zest

Based on an Xtext grammar, dot4zest interprets the parsed DOT EMF model using the generated Xtext switch API to dynamically create Zest graphs. The Zest graph view uses this to display DOT with Zest (see above).

Zest to DOT

To transform Zest graph instances to the Graphviz DOT language dot4zest uses JET.

There are two reasons to use JET instead of Xpand here. First, this allows us to transform any Zest graph instance to DOT directly (not only those for which we have a DOT meta model instance that could act as the input to Xpand).

Second, even if we had a DOT meta model instance (which we could create from the Zest graph), using Xpand would introduce a runtime dependency on the Modeling Workflow Engine, whereas with JET we only introduce a dependency on a single class (the generator class JET created from the template).

Future Ideas

  • Add support for different Graphviz shapes through Zest custom figures, e.g. for UML class diagrams
  • Add support to visualize Graphviz subgraphs as separate Zest graphs that can be accessed from the main graph
  • Look into possible ways of supporting Graphviz edge decorators (open or closed arrows, diamonds, etc.)
  • Map all graph, node and edge attributed from DOT input to corresponding Zest widget data (currently supported for graph attributes)
  • Add animation support using something like subgraph cluster_animation_1 { label = "Step 1"; 1->2 } etc., where animation steps are represented as subgraphs in the DOT input (which if rendered with Graphviz results in a static description of the animation)

For instance, for the input below a Zest animation could be created that changes like this (this is an experimental illustation of the idea):

digraph SampleAnimation {
 /* We can specify a Zest layout for the animation here: */
 layout=tree // = TreeLayoutAlgorithm
 /* Global attributes can be defined for edges and nodes: */
 node[label="Node"]
 edge[label="Edge" style=dotted]
 1;2;3;4;5
 /* The single animation steps are marked by numbers: */
 subgraph cluster_animation_0{ 1 -> 2 [label="Dashed" style=dashed]}
 subgraph cluster_animation_1{ 1 -> 3 }
 subgraph cluster_animation_2{ 3 -> 4; 3 -> 5}
}

After the first step:

DotZestM5Screenshot1.png

And the final state of the graph:

DotZestM5Screenshot2.png

The same input file, exported with Graphviz, shows the animation steps as subgraphs:

DotZestAnimatedExport.png

A possible use case for defining such animations with DOT is to easily create animated documentation, e.g. to explain data structures. The same file defining the animation could be used to export a PDF illustrating the steps in a static way.