Class GraphvizExporter<L extends Label>

java.lang.Object
org.variantsync.diffdetective.variation.diff.serialize.GraphvizExporter<L>
All Implemented Interfaces:
Exporter<L>

public class GraphvizExporter<L extends Label> extends Object implements Exporter<L>
Exporter for the Graphviz dot format. Using this exporter the Graphviz application can be used to layout a VariationDiff for visualisation. Currently only basic layout relevant information is exported, so if the result is rendered directly by Graphviz no styling is applied.
  • Field Details

    • quotePattern

      private static final Pattern quotePattern
    • graphvizNodePattern

      public static final Pattern graphvizNodePattern
    • format

      private Format<? super L extends Label> format
  • Constructor Details

    • GraphvizExporter

      public GraphvizExporter(Format<? super L> format)
  • Method Details

    • exportVariationDiff

      public <La extends L> void exportVariationDiff(VariationDiff<La> variationDiff, OutputStream destination) throws IOException
      Export variationDiff as Graphviz graph into destination. The exported graph is unstyled, but includes all necessary layout information.
      Specified by:
      exportVariationDiff in interface Exporter<L extends Label>
      Parameters:
      variationDiff - to be exported
      destination - where the result should be written
      Throws:
      IOException
    • computeGraphvizLayout

      public <La extends L> InputStream computeGraphvizLayout(VariationDiff<La> variationDiff, GraphvizExporter.LayoutAlgorithm algorithm, GraphvizExporter.OutputFormat outputFormat) throws IOException
      Runs the Graphviz dot program returning its result.
      Parameters:
      variationDiff - is the tree to be layouted by Graphviz.
      algorithm - the layout algorithm used by Graphviz
      outputFormat - is the requested format which is passed to the dot program with the -T flag.
      Returns:
      a buffered InputStream of the Graphviz output
      Throws:
      IOException
    • escape

      private static String escape(List<String> label)
      Replaces all special characters with uninterpreted escape codes. The Graphviz parser for strings interprets some characters specially. The result of this function can be used in Graphviz strings (surrounded by double quotes) resulting in all characters appearing literally in the output. Note that some backends of Graphviz may still interpret some strings specially, most commonly strings containing HTML tags.
      Parameters:
      label - a list of lines to be used as verbatim label
      Returns:
      a single string which produces the lines of label verbatim
    • layoutNodesIn

      public static <L extends Label> void layoutNodesIn(VariationDiff<L> variationDiff, Format<? super L> format, GraphvizExporter.LayoutAlgorithm algorithm, TriConsumer<Integer,Double,Double> positionNode) throws IOException
      Throws:
      IOException