Package org.jfree.chart.plot.flow
Class FlowPlot
- java.lang.Object
-
- org.jfree.chart.plot.Plot
-
- org.jfree.chart.plot.flow.FlowPlot
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,AnnotationChangeListener
,AxisChangeListener
,MarkerChangeListener
,LegendItemSource
,PublicCloneable
,DatasetChangeListener
public class FlowPlot extends Plot implements java.lang.Cloneable, PublicCloneable, java.io.Serializable
A plot for visualising flows defined in aFlowDataset
. This enables the production of a type of Sankey chart. The example shown here is produced by theFlowPlotDemo1.java
program included in the JFreeChart Demo Collection:- Since:
- 1.5.3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private FlowDataset
dataset
The source of data.private java.awt.Color
defaultNodeColor
The default node color if nothing is defined in the nodeColorMap.private java.awt.Font
defaultNodeLabelFont
private java.awt.Paint
defaultNodeLabelPaint
private double
flowMargin
The percentage of the plot width to assign to a gap between the nodes and the flow representation.private java.util.Map<NodeKey,java.awt.Color>
nodeColorMap
Stores colors for specific nodes - if there isn't a color in here for the node, the default node color will be used (unless the color swatch is active).private java.util.List<java.awt.Color>
nodeColorSwatch
private int
nodeColorSwatchPointer
A pointer into the color swatch.private VerticalAlignment
nodeLabelAlignment
private double
nodeLabelOffsetX
The x-offset for node labels.private double
nodeLabelOffsetY
The y-offset for node labels.private double
nodeMargin
The gap between nodes (expressed as a percentage of the plot height).private double
nodeWidth
The node width in Java 2D user-space units.private FlowLabelGenerator
toolTipGenerator
The tool tip generator - if null, no tool tips will be displayed.-
Fields inherited from class org.jfree.chart.plot.Plot
DEFAULT_BACKGROUND_ALPHA, DEFAULT_BACKGROUND_PAINT, DEFAULT_FOREGROUND_ALPHA, DEFAULT_INSETS, DEFAULT_LEGEND_ITEM_BOX, DEFAULT_LEGEND_ITEM_CIRCLE, DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, MINIMUM_HEIGHT_TO_DRAW, MINIMUM_WIDTH_TO_DRAW, ZERO
-
-
Constructor Summary
Constructors Constructor Description FlowPlot(FlowDataset dataset)
Creates a new instance that will source data from the specified dataset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Returns an independent copy of thisFlowPlot
instance (note, however, that the dataset is NOT cloned).void
draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.awt.geom.Point2D anchor, PlotState parentState, PlotRenderingInfo info)
Draws the flow plot within the specified area of the supplied graphics targetg2
.boolean
equals(java.lang.Object obj)
Tests this plot for equality with an arbitrary object.FlowDataset
getDataset()
Returns a reference to the dataset.java.awt.Color
getDefaultNodeColor()
Returns the default node color.java.awt.Font
getDefaultNodeLabelFont()
Returns the default font used to display labels for the source and destination nodes.java.awt.Paint
getDefaultNodeLabelPaint()
Returns the default paint used to display labels for the source and destination nodes.double
getFlowMargin()
Returns the flow margin.java.util.List<java.awt.Color>
getNodeColorSwatch()
Returns the list of colors that will be used to auto-populate the node colors when they are first rendered.java.awt.Color
getNodeFillColor(NodeKey nodeKey)
Returns the fill color for the specified node.VerticalAlignment
getNodeLabelAlignment()
Returns the vertical alignment of the node labels relative to the node.double
getNodeLabelOffsetX()
Returns the x-offset for the node labels.double
getNodeLabelOffsetY()
Returns the y-offset for the node labels.double
getNodeMargin()
Returns the node margin (expressed as a percentage of the available plotting space) which is the gap between nodes (sources or destinations).double
getNodeWidth()
Returns the width of the source and destination nodes, expressed in Java2D user-space units.java.lang.String
getPlotType()
Returns a string identifying the plot type.FlowLabelGenerator
getToolTipGenerator()
Returns the tool tip generator that creates the strings that are displayed as tool tips for the flows displayed in the plot.int
hashCode()
Returns a hashcode for this instance.private double
labelY(java.awt.geom.Rectangle2D r)
Computes the y-coordinate for a node label taking into account the current alignment settings.protected java.awt.Color
lookupNodeColor(NodeKey nodeKey)
Performs a lookup on the color for the specified node.void
setDataset(FlowDataset dataset)
Sets the dataset for the plot and sends a change notification to all registered listeners.void
setDefaultNodeColor(java.awt.Color color)
Sets the default node color and sends a change event to registered listeners.void
setDefaultNodeLabelFont(java.awt.Font font)
Sets the default font used to display labels for the source and destination nodes and sends a change notification to all registered listeners.void
setDefaultNodeLabelPaint(java.awt.Paint paint)
Sets the default paint used to display labels for the source and destination nodes and sends a change notification to all registered listeners.void
setFlowMargin(double margin)
Sets the flow margin and sends a change notification to all registered listeners.void
setNodeColorSwatch(java.util.List<java.awt.Color> colors)
Sets the color swatch for the plot.void
setNodeFillColor(NodeKey nodeKey, java.awt.Color color)
Sets the fill color for the specified node and sends a change notification to all registered listeners.void
setNodeLabelAlignment(VerticalAlignment alignment)
Sets the vertical alignment of the node labels and sends a change notification to all registered listeners.void
setNodeLabelOffsetX(double offsetX)
Sets the x-offset for the node labels and sends a change notification to all registered listeners.void
setNodeLabelOffsetY(double offsetY)
Sets the y-offset for the node labels and sends a change notification to all registered listeners.void
setNodeMargin(double margin)
Sets the node margin and sends a change notification to all registered listeners.void
setNodeWidth(double width)
Sets the width for the source and destination nodes and sends a change notification to all registered listeners.void
setToolTipGenerator(FlowLabelGenerator generator)
Sets the tool tip generator and sends a change notification to all registered listeners.-
Methods inherited from class org.jfree.chart.plot.Plot
addChangeListener, annotationChanged, axisChanged, canEqual, createAndAddEntity, datasetChanged, drawBackground, drawBackgroundImage, drawNoDataMessage, drawOutline, fetchElementHintingFlag, fillBackground, fillBackground, fireChangeEvent, getBackgroundAlpha, getBackgroundImage, getBackgroundImageAlignment, getBackgroundImageAlpha, getBackgroundPaint, getChart, getDatasetGroup, getDrawingSupplier, getForegroundAlpha, getInsets, getLegendItems, getNoDataMessage, getNoDataMessageFont, getNoDataMessagePaint, getOutlinePaint, getOutlineStroke, getParent, getRectX, getRectY, getRootPlot, handleClick, isNotify, isOutlineVisible, isSubplot, markerChanged, notifyListeners, removeChangeListener, resolveDomainAxisLocation, resolveRangeAxisLocation, setBackgroundAlpha, setBackgroundImage, setBackgroundImageAlignment, setBackgroundImageAlpha, setBackgroundPaint, setChart, setDatasetGroup, setDrawingSupplier, setDrawingSupplier, setForegroundAlpha, setInsets, setInsets, setNoDataMessage, setNoDataMessageFont, setNoDataMessagePaint, setNotify, setOutlinePaint, setOutlineStroke, setOutlineVisible, setParent, zoom
-
-
-
-
Field Detail
-
dataset
private FlowDataset dataset
The source of data.
-
nodeWidth
private double nodeWidth
The node width in Java 2D user-space units.
-
nodeMargin
private double nodeMargin
The gap between nodes (expressed as a percentage of the plot height).
-
flowMargin
private double flowMargin
The percentage of the plot width to assign to a gap between the nodes and the flow representation.
-
nodeColorMap
private java.util.Map<NodeKey,java.awt.Color> nodeColorMap
Stores colors for specific nodes - if there isn't a color in here for the node, the default node color will be used (unless the color swatch is active).
-
nodeColorSwatch
private java.util.List<java.awt.Color> nodeColorSwatch
-
nodeColorSwatchPointer
private int nodeColorSwatchPointer
A pointer into the color swatch.
-
defaultNodeColor
private java.awt.Color defaultNodeColor
The default node color if nothing is defined in the nodeColorMap.
-
defaultNodeLabelFont
private java.awt.Font defaultNodeLabelFont
-
defaultNodeLabelPaint
private java.awt.Paint defaultNodeLabelPaint
-
nodeLabelAlignment
private VerticalAlignment nodeLabelAlignment
-
nodeLabelOffsetX
private double nodeLabelOffsetX
The x-offset for node labels.
-
nodeLabelOffsetY
private double nodeLabelOffsetY
The y-offset for node labels.
-
toolTipGenerator
private FlowLabelGenerator toolTipGenerator
The tool tip generator - if null, no tool tips will be displayed.
-
-
Constructor Detail
-
FlowPlot
public FlowPlot(FlowDataset dataset)
Creates a new instance that will source data from the specified dataset.- Parameters:
dataset
- the dataset.
-
-
Method Detail
-
getPlotType
public java.lang.String getPlotType()
Returns a string identifying the plot type.- Specified by:
getPlotType
in classPlot
- Returns:
- A string identifying the plot type.
-
getDataset
public FlowDataset getDataset()
Returns a reference to the dataset.- Returns:
- A reference to the dataset (possibly
null
).
-
setDataset
public void setDataset(FlowDataset dataset)
Sets the dataset for the plot and sends a change notification to all registered listeners.- Parameters:
dataset
- the dataset (null
permitted).
-
getNodeMargin
public double getNodeMargin()
Returns the node margin (expressed as a percentage of the available plotting space) which is the gap between nodes (sources or destinations). The initial (default) value is0.01
(1 percent).- Returns:
- The node margin.
-
setNodeMargin
public void setNodeMargin(double margin)
Sets the node margin and sends a change notification to all registered listeners.- Parameters:
margin
- the margin (expressed as a percentage).
-
getFlowMargin
public double getFlowMargin()
Returns the flow margin. This determines the gap between the graphic representation of the nodes (sources and destinations) and the curved flow representation. This is expressed as a percentage of the plot width so that it remains proportional as the plot is resized. The initial (default) value is0.005
(0.5 percent).- Returns:
- The flow margin.
-
setFlowMargin
public void setFlowMargin(double margin)
Sets the flow margin and sends a change notification to all registered listeners.- Parameters:
margin
- the margin (must be 0.0 or higher).
-
getNodeWidth
public double getNodeWidth()
Returns the width of the source and destination nodes, expressed in Java2D user-space units. The initial (default) value is20.0
.- Returns:
- The width.
-
setNodeWidth
public void setNodeWidth(double width)
Sets the width for the source and destination nodes and sends a change notification to all registered listeners.- Parameters:
width
- the width.
-
getNodeColorSwatch
public java.util.List<java.awt.Color> getNodeColorSwatch()
Returns the list of colors that will be used to auto-populate the node colors when they are first rendered. If the list is empty, no color will be assigned to the node so, unless it is manually set, the default color will apply. This method returns a copy of the list, modifying the returned list will not affect the plot.- Returns:
- The list of colors (possibly empty, but never
null
).
-
setNodeColorSwatch
public void setNodeColorSwatch(java.util.List<java.awt.Color> colors)
Sets the color swatch for the plot.- Parameters:
colors
- the list of colors (null
not permitted).
-
getNodeFillColor
public java.awt.Color getNodeFillColor(NodeKey nodeKey)
Returns the fill color for the specified node.- Parameters:
nodeKey
- the node key (null
not permitted).- Returns:
- The fill color (possibly
null
).
-
setNodeFillColor
public void setNodeFillColor(NodeKey nodeKey, java.awt.Color color)
Sets the fill color for the specified node and sends a change notification to all registered listeners.- Parameters:
nodeKey
- the node key (null
not permitted).color
- the fill color (null
permitted).
-
getDefaultNodeColor
public java.awt.Color getDefaultNodeColor()
Returns the default node color. This is used when no specific node color has been specified. The initial (default) value isColor.GRAY
.- Returns:
- The default node color (never
null
).
-
setDefaultNodeColor
public void setDefaultNodeColor(java.awt.Color color)
Sets the default node color and sends a change event to registered listeners.- Parameters:
color
- the color (null
not permitted).
-
getDefaultNodeLabelFont
public java.awt.Font getDefaultNodeLabelFont()
Returns the default font used to display labels for the source and destination nodes. The initial (default) value isFont(Font.DIALOG, Font.BOLD, 12)
.- Returns:
- The default font (never
null
).
-
setDefaultNodeLabelFont
public void setDefaultNodeLabelFont(java.awt.Font font)
Sets the default font used to display labels for the source and destination nodes and sends a change notification to all registered listeners.- Parameters:
font
- the font (null
not permitted).
-
getDefaultNodeLabelPaint
public java.awt.Paint getDefaultNodeLabelPaint()
Returns the default paint used to display labels for the source and destination nodes. The initial (default) value isColor.BLACK
.- Returns:
- The default paint (never
null
).
-
setDefaultNodeLabelPaint
public void setDefaultNodeLabelPaint(java.awt.Paint paint)
Sets the default paint used to display labels for the source and destination nodes and sends a change notification to all registered listeners.- Parameters:
paint
- the paint (null
not permitted).
-
getNodeLabelAlignment
public VerticalAlignment getNodeLabelAlignment()
Returns the vertical alignment of the node labels relative to the node. The initial (default) value isVerticalAlignment.CENTER
.- Returns:
- The alignment (never
null
).
-
setNodeLabelAlignment
public void setNodeLabelAlignment(VerticalAlignment alignment)
Sets the vertical alignment of the node labels and sends a change notification to all registered listeners.- Parameters:
alignment
- the new alignment (null
not permitted).
-
getNodeLabelOffsetX
public double getNodeLabelOffsetX()
Returns the x-offset for the node labels.- Returns:
- The x-offset for the node labels.
-
setNodeLabelOffsetX
public void setNodeLabelOffsetX(double offsetX)
Sets the x-offset for the node labels and sends a change notification to all registered listeners.- Parameters:
offsetX
- the node label x-offset in Java2D units.
-
getNodeLabelOffsetY
public double getNodeLabelOffsetY()
Returns the y-offset for the node labels.- Returns:
- The y-offset for the node labels.
-
setNodeLabelOffsetY
public void setNodeLabelOffsetY(double offsetY)
Sets the y-offset for the node labels and sends a change notification to all registered listeners.- Parameters:
offsetY
- the node label y-offset in Java2D units.
-
getToolTipGenerator
public FlowLabelGenerator getToolTipGenerator()
Returns the tool tip generator that creates the strings that are displayed as tool tips for the flows displayed in the plot.- Returns:
- The tool tip generator (possibly
null
).
-
setToolTipGenerator
public void setToolTipGenerator(FlowLabelGenerator generator)
Sets the tool tip generator and sends a change notification to all registered listeners. If the generator is set tonull
, no tool tips will be displayed for the flows.- Parameters:
generator
- the new generator (null
permitted).
-
draw
public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.awt.geom.Point2D anchor, PlotState parentState, PlotRenderingInfo info)
Draws the flow plot within the specified area of the supplied graphics targetg2
.
-
lookupNodeColor
protected java.awt.Color lookupNodeColor(NodeKey nodeKey)
Performs a lookup on the color for the specified node.- Parameters:
nodeKey
- the node key (null
not permitted).- Returns:
- The node color.
-
labelY
private double labelY(java.awt.geom.Rectangle2D r)
Computes the y-coordinate for a node label taking into account the current alignment settings.- Parameters:
r
- the node rectangle.- Returns:
- The y-coordinate for the label.
-
equals
public boolean equals(java.lang.Object obj)
Tests this plot for equality with an arbitrary object. Note that, for the purposes of this equality test, the dataset is ignored.
-
hashCode
public int hashCode()
Returns a hashcode for this instance.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns an independent copy of thisFlowPlot
instance (note, however, that the dataset is NOT cloned).- Specified by:
clone
in interfacePublicCloneable
- Overrides:
clone
in classPlot
- Returns:
- A close of this instance.
- Throws:
java.lang.CloneNotSupportedException
-
-