de.erichseifert.gral.plots
Class AbstractPlot
- java.lang.Object
-
- de.erichseifert.gral.graphics.AbstractDrawable
-
- de.erichseifert.gral.graphics.DrawableContainer
-
- de.erichseifert.gral.plots.AbstractPlot
-
- All Implemented Interfaces:
- DataListener, Container, Drawable, Plot, java.io.Serializable, java.lang.Iterable<Drawable>
public abstract class AbstractPlot extends DrawableContainer implements Plot, DataListener
Basic implementation of a plot that can listen to changes of data sources and settings.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description AbstractPlot(DataSource... series)Initializes a newAbstractPlotinstance with the specified data series.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(DataSource source)Adds a new data series to the plot which is visible by default.voidadd(DataSource source, boolean visible)Adds a new data series to the plot.voidadd(int index, DataSource source, boolean visible)Inserts the specified data series to the plot at a specified position.voidautoscaleAxis(java.lang.String axisName)Tries to automatically set the ranges of the axes specified by the name if it is set to auto-scale.voidclear()Removes all data series from this plot.booleancontains(DataSource source)Returns whether the plot contains the specified data series.voiddataAdded(DataSource source, DataChangeEvent... events)Method that is invoked when data has been added.voiddataRemoved(DataSource source, DataChangeEvent... events)Method that is invoked when data has been removed.voiddataUpdated(DataSource source, DataChangeEvent... events)Method that is invoked when data has been updated.voiddraw(DrawingContext context)Draws theDrawablewith the specified drawing context.DataSourceget(int index)Returns the data series at a specified index.java.util.Collection<java.lang.String>getAxesNames()Returns a collection of all names of the axes stored in this plot.AxisgetAxis(java.lang.String name)Returns the axis with the specified name.AxisRenderergetAxisRenderer(java.lang.String axisName)Returns the renderer for the axis with the specified name.java.awt.PaintgetBackground()Returns the paint which is used to fill the background of the plot.java.awt.PaintgetBorderColor()Returns the paint which is used to fill the border of the plot.java.awt.StrokegetBorderStroke()Returns the stroke which is used to paint the border of the plot.java.util.List<DataSource>getData()Returns a list of all data series stored in the plot.java.awt.FontgetFont()Returns the base font used by the plot.LegendgetLegend()Returns the legend component.doublegetLegendDistance()Returns the spacing between the plot area and the legend.LocationgetLegendLocation()Returns the current positioning of the legend inside the plot.java.lang.String[]getMapping(DataSource source)Returns the mapping of data source columns to axis names.PlotAreagetPlotArea()Returns the drawing area of this plot.LabelgetTitle()Returns the title component of this plot.java.util.List<DataSource>getVisibleData()Returns a list of all visible data series stored in the plot.booleanisLegendVisible()Returns whether the legend is shown.booleanisVisible(DataSource source)Returns whether the specified data series is drawn.voidlayout()Recalculates this container's layout.booleanremove(DataSource source)Deletes the specified data series from the plot.voidremoveAxis(java.lang.String name)Removes the axis with the specified name.voidsetAxis(java.lang.String name, Axis axis)Sets the axis with the specified name and the associatedAxisRenderer.voidsetAxisRenderer(java.lang.String axisName, AxisRenderer renderer)Sets the renderer for the axis with the specified name.voidsetBackground(java.awt.Paint background)Sets the paint which will be used to fill the background of the plot.voidsetBorderColor(java.awt.Paint color)Sets the paint which will be used to fill the border of the plot.voidsetBorderStroke(java.awt.Stroke border)Sets the stroke which will be used to paint the border of the plot.voidsetFont(java.awt.Font font)Sets the base font that will be used by the plot.voidsetLegendDistance(double distance)Sets the spacing between the plot area and the legend.voidsetLegendLocation(Location location)Sets the positioning of the legend inside the plot.voidsetLegendVisible(boolean legendVisible)Sets whether the legend will be shown.voidsetMapping(DataSource source, java.lang.String... axisNames)Sets the mapping of data source columns to axis names.voidsetVisible(DataSource source, boolean visible)Changes the visibility of the specified data series.-
Methods inherited from class de.erichseifert.gral.graphics.DrawableContainer
add, add, contains, getConstraints, getDrawables, getDrawablesAt, getInsets, getLayout, getPreferredSize, iterator, remove, setBounds, setBounds, setInsets, setLayout, size
-
Methods inherited from class de.erichseifert.gral.graphics.AbstractDrawable
getBounds, getHeight, getWidth, getX, getY, setPosition
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.erichseifert.gral.graphics.Drawable
getBounds, getHeight, getPreferredSize, getWidth, getX, getY, setBounds, setBounds, setPosition
-
Methods inherited from interface de.erichseifert.gral.graphics.Container
add, add, contains, getBounds, getConstraints, getDrawables, getDrawablesAt, getInsets, getLayout, remove, setBounds, setInsets, setLayout, size
-
-
-
-
Constructor Detail
-
AbstractPlot
public AbstractPlot(DataSource... series)
Initializes a newAbstractPlotinstance with the specified data series. The series will be visible by default.- Parameters:
series- Initial data series to be displayed.
-
-
Method Detail
-
draw
public void draw(DrawingContext context)
Draws theDrawablewith the specified drawing context.- Specified by:
drawin interfaceDrawable- Overrides:
drawin classDrawableContainer- Parameters:
context- Environment used for drawing
-
layout
public void layout()
Description copied from class:DrawableContainerRecalculates this container's layout.- Specified by:
layoutin interfaceContainer- Overrides:
layoutin classDrawableContainer
-
getAxis
public Axis getAxis(java.lang.String name)
Returns the axis with the specified name.
-
setAxis
public void setAxis(java.lang.String name, Axis axis)Sets the axis with the specified name and the associatedAxisRenderer.
-
removeAxis
public void removeAxis(java.lang.String name)
Removes the axis with the specified name.- Specified by:
removeAxisin interfacePlot- Parameters:
name- Name of the axis to be removed.
-
getAxesNames
public java.util.Collection<java.lang.String> getAxesNames()
Returns a collection of all names of the axes stored in this plot.- Specified by:
getAxesNamesin interfacePlot- Returns:
- The names of all axes stored in this plot.
-
autoscaleAxis
public void autoscaleAxis(java.lang.String axisName)
Tries to automatically set the ranges of the axes specified by the name if it is set to auto-scale.- Specified by:
autoscaleAxisin interfacePlot- Parameters:
axisName- Name of the axis that should be scaled.- See Also:
Axis.setAutoscaled(boolean)
-
getAxisRenderer
public AxisRenderer getAxisRenderer(java.lang.String axisName)
Returns the renderer for the axis with the specified name.- Specified by:
getAxisRendererin interfacePlot- Parameters:
axisName- Axis name.- Returns:
- Instance that renders the axis.
-
setAxisRenderer
public void setAxisRenderer(java.lang.String axisName, AxisRenderer renderer)Sets the renderer for the axis with the specified name.- Specified by:
setAxisRendererin interfacePlot- Parameters:
axisName- Name of the axis to be rendered.renderer- Instance to render the axis.
-
getPlotArea
public PlotArea getPlotArea()
Returns the drawing area of this plot.- Specified by:
getPlotAreain interfacePlot- Returns:
PlotArea2D.
-
getTitle
public Label getTitle()
Returns the title component of this plot.
-
getLegend
public Legend getLegend()
Returns the legend component.
-
getBackground
public java.awt.Paint getBackground()
Description copied from interface:PlotReturns the paint which is used to fill the background of the plot.- Specified by:
getBackgroundin interfacePlot- Returns:
- Paint which is used to fill the background of the plot.
-
setBackground
public void setBackground(java.awt.Paint background)
Description copied from interface:PlotSets the paint which will be used to fill the background of the plot.- Specified by:
setBackgroundin interfacePlot- Parameters:
background- Paint which will be used to fill the background of the plot.
-
getBorderStroke
public java.awt.Stroke getBorderStroke()
Description copied from interface:PlotReturns the stroke which is used to paint the border of the plot.- Specified by:
getBorderStrokein interfacePlot- Returns:
- Stroke which is used to paint the border of the plot.
-
setBorderStroke
public void setBorderStroke(java.awt.Stroke border)
Description copied from interface:PlotSets the stroke which will be used to paint the border of the plot.- Specified by:
setBorderStrokein interfacePlot- Parameters:
border- Stroke which will be used to paint the border of the plot.
-
getBorderColor
public java.awt.Paint getBorderColor()
Description copied from interface:PlotReturns the paint which is used to fill the border of the plot.- Specified by:
getBorderColorin interfacePlot- Returns:
- Paint which is used to fill the border of the plot.
-
setBorderColor
public void setBorderColor(java.awt.Paint color)
Description copied from interface:PlotSets the paint which will be used to fill the border of the plot.- Specified by:
setBorderColorin interfacePlot- Parameters:
color- Paint which will be used to fill the border of the plot.
-
getFont
public java.awt.Font getFont()
Description copied from interface:PlotReturns the base font used by the plot.
-
setFont
public void setFont(java.awt.Font font)
Description copied from interface:PlotSets the base font that will be used by the plot.
-
isLegendVisible
public boolean isLegendVisible()
Description copied from interface:PlotReturns whether the legend is shown.- Specified by:
isLegendVisiblein interfacePlot- Returns:
trueif the legend is shown,falseif the legend is hidden.
-
setLegendVisible
public void setLegendVisible(boolean legendVisible)
Description copied from interface:PlotSets whether the legend will be shown.- Specified by:
setLegendVisiblein interfacePlot- Parameters:
legendVisible-trueif the legend should be shown,falseif the legend should be hidden.
-
getLegendLocation
public Location getLegendLocation()
Description copied from interface:PlotReturns the current positioning of the legend inside the plot.- Specified by:
getLegendLocationin interfacePlot- Returns:
- Current positioning of the legend inside the plot.
-
setLegendLocation
public void setLegendLocation(Location location)
Description copied from interface:PlotSets the positioning of the legend inside the plot.- Specified by:
setLegendLocationin interfacePlot- Parameters:
location- Positioning of the legend inside the plot.
-
getLegendDistance
public double getLegendDistance()
Description copied from interface:PlotReturns the spacing between the plot area and the legend.- Specified by:
getLegendDistancein interfacePlot- Returns:
- Spacing between the plot area and the legend relative to font height.
-
setLegendDistance
public void setLegendDistance(double distance)
Description copied from interface:PlotSets the spacing between the plot area and the legend. The distance is defined in font height.- Specified by:
setLegendDistancein interfacePlot- Parameters:
distance- Spacing between the plot area and the legend relative to font height.
-
add
public void add(DataSource source)
Adds a new data series to the plot which is visible by default.
-
add
public void add(DataSource source, boolean visible)
Adds a new data series to the plot.
-
add
public void add(int index, DataSource source, boolean visible)Inserts the specified data series to the plot at a specified position.
-
contains
public boolean contains(DataSource source)
Returns whether the plot contains the specified data series.
-
get
public DataSource get(int index)
Returns the data series at a specified index.
-
remove
public boolean remove(DataSource source)
Deletes the specified data series from the plot.
-
clear
public void clear()
Removes all data series from this plot.
-
getMapping
public java.lang.String[] getMapping(DataSource source)
Returns the mapping of data source columns to axis names. The elements of returned array equal the column indexes, i.e. the first element (axis name) matches the first column ofsource. If no mapping existsnullwill be stored in the array.- Specified by:
getMappingin interfacePlot- Parameters:
source- Data source.- Returns:
- Array containing axis names in the order of the columns,
or
nullif no mapping exists for the column.
-
setMapping
public void setMapping(DataSource source, java.lang.String... axisNames)
Sets the mapping of data source columns to axis names. The column index is taken from the order of the axis names, i.e. the first column ofsourcewill be mapped to first element ofaxisNames. Axis names with valuenullwill be ignored.- Specified by:
setMappingin interfacePlot- Parameters:
source- Data source.axisNames- Sequence of axis names in the order of the columns.
-
getData
public java.util.List<DataSource> getData()
Returns a list of all data series stored in the plot.
-
getVisibleData
public java.util.List<DataSource> getVisibleData()
Returns a list of all visible data series stored in the plot.- Specified by:
getVisibleDatain interfacePlot- Returns:
- List of all visible data series.
-
isVisible
public boolean isVisible(DataSource source)
Returns whether the specified data series is drawn.
-
setVisible
public void setVisible(DataSource source, boolean visible)
Changes the visibility of the specified data series.- Specified by:
setVisiblein interfacePlot- Parameters:
source- Data series.visible-trueif the series should be visible,falseotherwise.
-
dataAdded
public void dataAdded(DataSource source, DataChangeEvent... events)
Method that is invoked when data has been added. This method is invoked by objects that provide support forDataListeners and should not be called manually.- Specified by:
dataAddedin interfaceDataListener- Parameters:
source- Data source that has been changed.events- Optional event object describing the data values that have been added.
-
dataUpdated
public void dataUpdated(DataSource source, DataChangeEvent... events)
Method that is invoked when data has been updated. This method is invoked by objects that provide support forDataListeners and should not be called manually.- Specified by:
dataUpdatedin interfaceDataListener- Parameters:
source- Data source that has been changed.events- Optional event object describing the data values that have been updated.
-
dataRemoved
public void dataRemoved(DataSource source, DataChangeEvent... events)
Method that is invoked when data has been removed. This method is invoked by objects that provide support forDataListeners and should not be called manually.- Specified by:
dataRemovedin interfaceDataListener- Parameters:
source- Data source that has been changed.events- Optional event object describing the data values that have been removed.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG