Class AbstractPlot

java.lang.Object
org.opentrafficsim.draw.graphs.AbstractPlot
All Implemented Interfaces:
Identifiable, org.jfree.data.general.Dataset
Direct Known Subclasses:
AbstractBoundedPlot

public abstract class AbstractPlot extends Object implements Identifiable, org.jfree.data.general.Dataset
Super class of all plots. This schedules regular updates, creates menus and deals with listeners. There are a number of delegate methods for sub classes to implement.

Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Field Details

    • GRAPH_ADD_EVENT

      public static final EventType GRAPH_ADD_EVENT
      The (regular, not timed) event type for pub/sub indicating the addition of a graph. Not used internally.
      Payload: String graph caption (not an array, just a String)
    • GRAPH_REMOVE_EVENT

      public static final EventType GRAPH_REMOVE_EVENT
      The (regular, not timed) event type for pub/sub indicating the removal of a graph. Not used internally.
      Payload: String Graph caption (not an array, just a String)
    • DEFAULT_INITIAL_UPPER_TIME_BOUND

      public static final Time DEFAULT_INITIAL_UPPER_TIME_BOUND
      Initial upper bound for the time scale.
  • Constructor Details

    • AbstractPlot

      public AbstractPlot(PlotScheduler scheduler, String caption, Duration updateInterval, Duration delay)
      Constructor.
      Parameters:
      scheduler - scheduler.
      caption - caption
      updateInterval - regular update interval (simulation time)
      delay - amount of time that chart runs behind simulation to prevent gaps in the charted data
  • Method Details

    • setChart

      protected void setChart(org.jfree.chart.JFreeChart chart)
      Sets the chart and adds menus and listeners.
      Parameters:
      chart - chart
    • encodeAsPng

      public byte[] encodeAsPng(int width, int height, double fontSize) throws IOException
      Returns the chart as a byte array representing a png image.
      Parameters:
      width - width
      height - height
      fontSize - font size (16 is the original on screen size)
      Returns:
      the chart as a byte array representing a png image
      Throws:
      IOException - on IO exception
    • getGroup

      public final org.jfree.data.general.DatasetGroup getGroup()
      Specified by:
      getGroup in interface org.jfree.data.general.Dataset
    • setGroup

      public final void setGroup(org.jfree.data.general.DatasetGroup group)
      Specified by:
      setGroup in interface org.jfree.data.general.Dataset
    • setAutoBoundDomain

      public void setAutoBoundDomain(org.jfree.chart.plot.XYPlot plot)
      Overridable; activates auto bounds on domain axis from user input. This class does not force the use of XYPlots, but the auto bounds command comes from the ChartPanel that this class creates. In case the used plot is a XYPlot, this method is then invoked. Sub classes with auto domain bounds that work with an XYPlot should implement this. The method is not abstract as the use of XYPlot is not obligated.
      Parameters:
      plot - plot
    • setAutoBoundRange

      public void setAutoBoundRange(org.jfree.chart.plot.XYPlot plot)
      Overridable; activates auto bounds on range axis from user input. This class does not force the use of XYPlots, but the auto bounds command comes from the ChartPanel that this class creates. In case the used plot is a XYPlot, this method is then invoked. Sub classes with auto range bounds that work with an XYPlot should implement this. The method is not abstract as the use of XYPlot is not obligated.
      Parameters:
      plot - plot
    • getGraphType

      public abstract GraphType getGraphType()
      Return the graph type for transceiver.
      Returns:
      the graph type.
    • getStatusLabel

      public abstract String getStatusLabel(double domainValue, double rangeValue)
      Returns the status label when the mouse is over the given location.
      Parameters:
      domainValue - domain value (x-axis)
      rangeValue - range value (y-axis)
      Returns:
      status label when the mouse is over the given location
    • increaseTime

      protected abstract void increaseTime(Duration time)
      Increase the simulated time span.
      Parameters:
      time - time to increase to
    • notifyPlotChange

      public final void notifyPlotChange()
      Notify all change listeners.
    • getChart

      public final org.jfree.chart.JFreeChart getChart()
      Returns the chart.
      Returns:
      chart
    • getId

      public final String getId()
      Specified by:
      getId in interface Identifiable
    • addChangeListener

      public final void addChangeListener(org.jfree.data.general.DatasetChangeListener listener)
      Specified by:
      addChangeListener in interface org.jfree.data.general.Dataset
    • removeChangeListener

      public final void removeChangeListener(org.jfree.data.general.DatasetChangeListener listener)
      Specified by:
      removeChangeListener in interface org.jfree.data.general.Dataset
    • setUpdateInterval

      public final void setUpdateInterval(Duration interval)
      Sets a new update interval.
      Parameters:
      interval - update interval
    • offerUpdateInterval

      public void offerUpdateInterval(Duration interval)
      Offer new update time. This is a Thread-safe method as this update time will only be set once a current update finishes, or no current update is running.
      Parameters:
      interval - update interval
    • getUpdateTime

      public final Duration getUpdateTime()
      Returns time until which data should be plotted.
      Returns:
      time until which data should be plotted
    • update

      public void update()
      Redraws the plot and schedules the next update.
    • getCaption

      public String getCaption()
      Retrieve the caption.
      Returns:
      the caption of the plot