Class TikzExporter

java.lang.Object
it.univr.di.cstnu.gui.export.TikzExporter
All Implemented Interfaces:
VectorSink

public final class TikzExporter extends Object implements VectorSink
Emits a temporal graph as TikZ (PGF/TikZ LaTeX). The coordinate space is converted from pixels (model units) to centimetres via PIXELS_PER_CM and the Y axis is inverted (TikZ grows upwards while the screen grows downwards). Edge geometry is taken verbatim from EdgeGeometry: curved edges are emitted with their exact control point (.. controls (cx,cy) ..), never re-approximated with to[bend].

The styles are emitted once at the top as a \tikzset block with the names tnnode, tnnode-contingent, tnnode-observer, tnedge-requirement, tnedge-contingent, tnedge-derived, tnedge-wait and tn-negative-cycle, so that all figures of an article stay homogeneous and the author can redefine them in his own preamble. In standaloneDocument mode a compilable standalone document is emitted; otherwise only the tikzpicture environment. Both modes open with a comment listing the required packages.

Labels are LaTeX-escaped (see the escaping table in the report); node identifiers are sanitized so that TikZ accepts them while the visible label keeps the original text.

This class implements VectorSink and is driven by VectorTraversal; use export(TemporalConstraintGraph, NodePositions, GraphStyle, ExportOptions, CurvatureSource, Writer) to export a whole graph.

Author:
posenato
  • Field Details

    • PIXELS_PER_CM

      public static final double PIXELS_PER_CM
      Conversion factor from pixels (model units) to centimetres: 96 dpi per inch, 2.54 cm per inch.
      See Also:
  • Method Details

    • export

      public static void export(@Nonnull TemporalConstraintGraph<?> graph, @Nonnull NodePositions positions, @Nonnull GraphStyle style, @Nonnull ExportOptions options, @Nonnull CurvatureSource curvatures, @Nonnull Writer out) throws IOException
      Exports graph as TikZ to out.
      Parameters:
      graph - the graph to export, not null
      positions - the node positions, not null
      style - the visual style, not null
      options - the export options, not null
      curvatures - the source of explicit per-edge curvature factors, not null; pass CurvatureSource.none() when no explicit curvature is available
      out - the destination writer, not null; it is flushed but not closed by this method
      Throws:
      IOException - if an I/O error occurs while writing
    • beginDocument

      public void beginDocument(@Nonnull Rectangle2D modelBounds, @Nonnull ExportOptions options)
      Description copied from interface: VectorSink
      Called once before any node or edge.
      Specified by:
      beginDocument in interface VectorSink
      Parameters:
      modelBounds - the bounding box, in model space, of the whole drawing (node circles grown by their outline stroke, every edge curve grown by its stroke width, arrow heads and edge labels), not null
      options - the export options in effect, not null
    • node

      public void node(@Nonnull LabeledNode node, double centerX, double centerY, double radius, @Nonnull String label, @Nonnull Paint fill, @Nonnull Paint outline)
      Description copied from interface: VectorSink
      Emits a single node.
      Specified by:
      node in interface VectorSink
      Parameters:
      node - the node, not null
      centerX - the x coordinate of the node centre in model space
      centerY - the y coordinate of the node centre in model space
      radius - the node radius in model space
      label - the text label to emit, not null (maybe empty)
      fill - the fill paint (already resolved for the export, i.e. selection never applied), not null
      outline - the outline paint (already resolved for the export, negative-cycle highlighting applied only if requested by the options), not null
    • edge

      public void edge(@Nonnull Edge edge, @Nonnull EdgeGeometry.EdgeShape shape, @Nonnull String label, @Nonnull Paint paint, @Nonnull Stroke stroke)
      Description copied from interface: VectorSink
      Emits a single directed edge.
      Specified by:
      edge in interface VectorSink
      Parameters:
      edge - the edge, not null
      shape - the edge geometry as computed by EdgeGeometry, not null; the sink must use it as-is and never recompute it
      label - the text label to emit, not null (maybe empty)
      paint - the paint for the edge (already resolved for the export, selection never applied), not null
      stroke - the stroke for the edge, not null
    • annotation

      public void annotation(@Nonnull GraphAnnotation annotation)
      Description copied from interface: VectorSink
      Emits a graph annotation. Sinks which do not support annotations may leave this callback at its default no-op implementation.
      Specified by:
      annotation in interface VectorSink
      Parameters:
      annotation - the annotation, not null
    • endDocument

      public void endDocument()
      Description copied from interface: VectorSink
      Called once after every node and edge has been emitted.
      Specified by:
      endDocument in interface VectorSink