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.javaprogram included in the JFreeChart Demo Collection:- Since:
- 1.5.3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private FlowDatasetdatasetThe source of data.private java.awt.ColordefaultNodeColorThe default node color if nothing is defined in the nodeColorMap.private java.awt.FontdefaultNodeLabelFontprivate java.awt.PaintdefaultNodeLabelPaintprivate doubleflowMarginThe 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>nodeColorMapStores 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>nodeColorSwatchprivate intnodeColorSwatchPointerA pointer into the color swatch.private VerticalAlignmentnodeLabelAlignmentprivate doublenodeLabelOffsetXThe x-offset for node labels.private doublenodeLabelOffsetYThe y-offset for node labels.private doublenodeMarginThe gap between nodes (expressed as a percentage of the plot height).private doublenodeWidthThe node width in Java 2D user-space units.private FlowLabelGeneratortoolTipGeneratorThe 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.Objectclone()Returns an independent copy of thisFlowPlotinstance (note, however, that the dataset is NOT cloned).voiddraw(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.booleanequals(java.lang.Object obj)Tests this plot for equality with an arbitrary object.FlowDatasetgetDataset()Returns a reference to the dataset.java.awt.ColorgetDefaultNodeColor()Returns the default node color.java.awt.FontgetDefaultNodeLabelFont()Returns the default font used to display labels for the source and destination nodes.java.awt.PaintgetDefaultNodeLabelPaint()Returns the default paint used to display labels for the source and destination nodes.doublegetFlowMargin()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.ColorgetNodeFillColor(NodeKey nodeKey)Returns the fill color for the specified node.VerticalAlignmentgetNodeLabelAlignment()Returns the vertical alignment of the node labels relative to the node.doublegetNodeLabelOffsetX()Returns the x-offset for the node labels.doublegetNodeLabelOffsetY()Returns the y-offset for the node labels.doublegetNodeMargin()Returns the node margin (expressed as a percentage of the available plotting space) which is the gap between nodes (sources or destinations).doublegetNodeWidth()Returns the width of the source and destination nodes, expressed in Java2D user-space units.java.lang.StringgetPlotType()Returns a string identifying the plot type.FlowLabelGeneratorgetToolTipGenerator()Returns the tool tip generator that creates the strings that are displayed as tool tips for the flows displayed in the plot.inthashCode()Returns a hashcode for this instance.private doublelabelY(java.awt.geom.Rectangle2D r)Computes the y-coordinate for a node label taking into account the current alignment settings.protected java.awt.ColorlookupNodeColor(NodeKey nodeKey)Performs a lookup on the color for the specified node.voidsetDataset(FlowDataset dataset)Sets the dataset for the plot and sends a change notification to all registered listeners.voidsetDefaultNodeColor(java.awt.Color color)Sets the default node color and sends a change event to registered listeners.voidsetDefaultNodeLabelFont(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.voidsetDefaultNodeLabelPaint(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.voidsetFlowMargin(double margin)Sets the flow margin and sends a change notification to all registered listeners.voidsetNodeColorSwatch(java.util.List<java.awt.Color> colors)Sets the color swatch for the plot.voidsetNodeFillColor(NodeKey nodeKey, java.awt.Color color)Sets the fill color for the specified node and sends a change notification to all registered listeners.voidsetNodeLabelAlignment(VerticalAlignment alignment)Sets the vertical alignment of the node labels and sends a change notification to all registered listeners.voidsetNodeLabelOffsetX(double offsetX)Sets the x-offset for the node labels and sends a change notification to all registered listeners.voidsetNodeLabelOffsetY(double offsetY)Sets the y-offset for the node labels and sends a change notification to all registered listeners.voidsetNodeMargin(double margin)Sets the node margin and sends a change notification to all registered listeners.voidsetNodeWidth(double width)Sets the width for the source and destination nodes and sends a change notification to all registered listeners.voidsetToolTipGenerator(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:
getPlotTypein 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 (nullpermitted).
-
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 (nullnot permitted).
-
getNodeFillColor
public java.awt.Color getNodeFillColor(NodeKey nodeKey)
Returns the fill color for the specified node.- Parameters:
nodeKey- the node key (nullnot 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 (nullnot permitted).color- the fill color (nullpermitted).
-
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 (nullnot 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 (nullnot 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 (nullnot 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 (nullnot 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 (nullpermitted).
-
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 (nullnot 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.CloneNotSupportedExceptionReturns an independent copy of thisFlowPlotinstance (note, however, that the dataset is NOT cloned).- Specified by:
clonein interfacePublicCloneable- Overrides:
clonein classPlot- Returns:
- A close of this instance.
- Throws:
java.lang.CloneNotSupportedException
-
-