Package org.opentrafficsim.draw.graphs
Class AbstractPlot
java.lang.Object
org.opentrafficsim.draw.graphs.AbstractPlot
- All Implemented Interfaces:
Dataset,org.opentrafficsim.base.Identifiable
- Direct Known Subclasses:
AbstractBoundedPlot
public abstract class AbstractPlot
extends Object
implements org.opentrafficsim.base.Identifiable, 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-2023 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final TimeInitial upper bound for the time scale.static final org.djutils.event.EventTypeThe (regular, not timed) event type for pub/sub indicating the addition of a graph.static final org.djutils.event.EventTypeThe (regular, not timed) event type for pub/sub indicating the removal of a graph. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractPlot(org.opentrafficsim.core.dsol.OtsSimulatorInterface simulator, String caption, Duration updateInterval, Duration delay) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddChangeListener(DatasetChangeListener listener) byte[]encodeAsPng(int width, int height, double fontSize) Returns the chart as a byte array representing a png image.Retrieve the caption.final JFreeChartgetChart()Returns the chart.abstract GraphTypeReturn the graph type for transceiver.final DatasetGroupgetGroup()final StringgetId()org.opentrafficsim.core.dsol.OtsSimulatorInterfaceRetrieve the simulator.abstract StringgetStatusLabel(double domainValue, double rangeValue) Returns the status label when the mouse is over the given location.final TimeReturns time until which data should be plotted.protected abstract voidincreaseTime(Time time) Increase the simulated time span.final voidNotify all change listeners.final voidremoveChangeListener(DatasetChangeListener listener) voidsetAutoBoundDomain(XYPlot plot) Overridable; activates auto bounds on domain axis from user input.voidsetAutoBoundRange(XYPlot plot) Overridable; activates auto bounds on range axis from user input.protected voidsetChart(JFreeChart chart) Sets the chart and adds menus and listeners.final voidsetGroup(DatasetGroup group) final voidsetUpdateInterval(Duration interval) Sets a new update interval.protected voidupdate()Redraws the plot and schedules the next update.
-
Field Details
-
GRAPH_ADD_EVENT
public static final org.djutils.event.EventType GRAPH_ADD_EVENTThe (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 org.djutils.event.EventType GRAPH_REMOVE_EVENTThe (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
Initial upper bound for the time scale.
-
-
Constructor Details
-
AbstractPlot
public AbstractPlot(org.opentrafficsim.core.dsol.OtsSimulatorInterface simulator, String caption, Duration updateInterval, Duration delay) Constructor.- Parameters:
simulator- OtsSimulatorInterface; simulatorcaption- String; captionupdateInterval- Duration; regular update interval (simulation time)delay- Duration; amount of time that chart runs behind simulation to prevent gaps in the charted data
-
-
Method Details
-
setChart
Sets the chart and adds menus and listeners.- Parameters:
chart- JFreeChart; chart
-
encodeAsPng
Returns the chart as a byte array representing a png image.- Parameters:
width- int; widthheight- int; heightfontSize- double; font size (16 is the original on screen size)- Returns:
- byte[]; the chart as a byte array representing a png image
- Throws:
IOException- on IO exception
-
getGroup
-
setGroup
-
setAutoBoundDomain
Overridable; activates auto bounds on domain axis from user input. This class does not force the use ofXYPlots, but the auto bounds command comes from theChartPanelthat this class creates. In case the used plot is aXYPlot, this method is then invoked. Sub classes with auto domain bounds that work with anXYPlotshould implement this. The method is not abstract as the use ofXYPlotis not obligated.- Parameters:
plot- XYPlot; plot
-
setAutoBoundRange
Overridable; activates auto bounds on range axis from user input. This class does not force the use ofXYPlots, but the auto bounds command comes from theChartPanelthat this class creates. In case the used plot is aXYPlot, this method is then invoked. Sub classes with auto range bounds that work with anXYPlotshould implement this. The method is not abstract as the use ofXYPlotis not obligated.- Parameters:
plot- XYPlot; plot
-
getGraphType
Return the graph type for transceiver.- Returns:
- GraphType; the graph type.
-
getStatusLabel
Returns the status label when the mouse is over the given location.- Parameters:
domainValue- double; domain value (x-axis)rangeValue- double; range value (y-axis)- Returns:
- String; status label when the mouse is over the given location
-
increaseTime
Increase the simulated time span.- Parameters:
time- Time; time to increase to
-
notifyPlotChange
public final void notifyPlotChange()Notify all change listeners. -
getChart
Returns the chart.- Returns:
- JFreeChart; chart
-
getId
- Specified by:
getIdin interfaceorg.opentrafficsim.base.Identifiable
-
addChangeListener
- Specified by:
addChangeListenerin interfaceDataset
-
removeChangeListener
- Specified by:
removeChangeListenerin interfaceDataset
-
getSimulator
public org.opentrafficsim.core.dsol.OtsSimulatorInterface getSimulator()Retrieve the simulator.- Returns:
- OtsSimulatorInterface; the simulator
-
setUpdateInterval
Sets a new update interval.- Parameters:
interval- Duration; update interval
-
getUpdateTime
Returns time until which data should be plotted.- Returns:
- Time; time until which data should be plotted
-
update
protected void update()Redraws the plot and schedules the next update. -
getCaption
Retrieve the caption.- Returns:
- String; the caption of the plot
-