Venice 0.751beta

nz.org.venice.chart.graph
Interface Graph

All Known Implementing Classes:
AbstractGraph, AdvanceDeclineGraph

public interface Graph

Provides a common interface to allow the charting module to support a variety of graphs. Classes that implement this interface will be able to render the graph onto the chart and provide axes information. Each graph can have its own user interface to allow the user to set user-definable parameters.

Author:
Andrew Leppard
See Also:
AbstractGraph, GraphUI, GraphSource

Field Summary
static int TOOL_TIP_BUFFER
          Maximum distance between the mouse pointer and the graph which will still make the tooltip come up
 
Method Summary
 boolean dataAvailable(java.util.Vector xRange)
          Return whether the graph has a price for range xRange Is trivially true for all graphs apart from the PointAndFigure graph as P&F is the only graph type where price data does not map one to one to date.
 double[] getAcceptableMajorDeltas()
          Return an array of acceptable major deltas for the vertical axis.
 double[] getAcceptableMinorDeltas()
          Return an array of acceptable minor deltas for the vertical axis.
 java.lang.Comparable getEndX()
          Get the last X value that this graph will draw.
 double getHighestY(java.util.List xRange)
          Return the highest Y value in the given X range.
 double getLowestY(java.util.List xRange)
          Return the loweset Y value in the given X range.
 java.lang.String getName()
          Return the name of the graph we are graphing, e.g.
 java.util.HashMap getSettings()
          Return the graph's current settings.
 java.lang.String getSourceName()
          Return the name of the source data that we are graphing, e.g.
 int getSourceType()
          Return the type of the source data that we are graphing, e.g.
 java.lang.Comparable getStartX()
          Get the first X value that this graph will draw.
 java.lang.String getToolTipText(java.lang.Comparable x, int y, int yoffset, double verticalScale, double bottomLineValue)
          Get the tool tip text for the given X value and y coordinate.
 GraphUI getUI(java.util.HashMap settings)
          Return the graph's user interface to allow the user to modify its settings.
 java.util.Set getXRange()
          Get all X values that this graph will draw.
 java.lang.Double getY(java.lang.Comparable xRange)
          Return the Y value for the given X value.
 java.lang.String getYLabel(double value)
          Convert the Y value to a label to be displayed in the vertical axis.
 boolean isPrimary()
          Return whether the graph is a primary graph.
 void render(java.awt.Graphics g, java.awt.Color colour, int xoffset, int yoffset, double horizontalScale, double verticalScale, double topLineValue, double bottomLineValue, java.util.List xRange, boolean vertOrientation)
          Draw the graph.
 void setSettings(java.util.HashMap settings)
          Set the graph's user definable settings.
 

Field Detail

TOOL_TIP_BUFFER

public static final int TOOL_TIP_BUFFER
Maximum distance between the mouse pointer and the graph which will still make the tooltip come up

See Also:
Constant Field Values
Method Detail

render

public void render(java.awt.Graphics g,
                   java.awt.Color colour,
                   int xoffset,
                   int yoffset,
                   double horizontalScale,
                   double verticalScale,
                   double topLineValue,
                   double bottomLineValue,
                   java.util.List xRange,
                   boolean vertOrientation)
Draw the graph.

Parameters:
g - the Graphics object to render to
colour - the colour the graph should be rendered in; override this if the graph should be drawn in a certain colour - such as a Moving Average graph
xoffset - the x offset in the graphics object where the graph starts
yoffset - the y offset in the graphics object where the graph starts
horizontalScale - horizontal scale factor; use this to convert between X value in the xRange to a cartesian coordinate x
verticalScale - vertical scale factor; use this to convert between Y value to a cartesian coordinate y
topLineValue - the Y value of the lowest line in the graph
bottomLineValue - the Y value of the lowest line in the graph
xRange - a List of Comparable that contain the X values to plot
vertOrientation - true if increasing y values mean decreasing Y values

getToolTipText

public java.lang.String getToolTipText(java.lang.Comparable x,
                                       int y,
                                       int yoffset,
                                       double verticalScale,
                                       double bottomLineValue)
Get the tool tip text for the given X value and y coordinate.

Parameters:
x - the X value
y - the y coordinate
yoffset - y offset from top of graph
verticalScale - vertical scale factor
bottomLineValue - the Y value of the lowest line in the graph
Returns:
the tooltip text

getStartX

public java.lang.Comparable getStartX()
Get the first X value that this graph will draw.

Returns:
X value of the first x coordinate in graph

getEndX

public java.lang.Comparable getEndX()
Get the last X value that this graph will draw.

Returns:
X value of the last x coordinate in graph

getXRange

public java.util.Set getXRange()
Get all X values that this graph will draw.

Returns:
List of Comparable X values

getYLabel

public java.lang.String getYLabel(double value)
Convert the Y value to a label to be displayed in the vertical axis.

Parameters:
value - y value
Returns:
the label text

getName

public java.lang.String getName()
Return the name of the graph we are graphing, e.g. Simple Moving Average.

Returns:
the name of the graph

getSourceName

public java.lang.String getSourceName()
Return the name of the source data that we are graphing, e.g. CBA.

Returns:
the name of the source

getSourceType

public int getSourceType()
Return the type of the source data that we are graphing, e.g. Portfolio.

Returns:
the type of the source

getY

public java.lang.Double getY(java.lang.Comparable xRange)
Return the Y value for the given X value.

Parameters:
xRange - value
Returns:
Y value

getHighestY

public double getHighestY(java.util.List xRange)
Return the highest Y value in the given X range.

Parameters:
xRange - range of X values
Returns:
the highest Y value

getLowestY

public double getLowestY(java.util.List xRange)
Return the loweset Y value in the given X range.

Parameters:
xRange - range of X values
Returns:
the lowest Y value

getAcceptableMajorDeltas

public double[] getAcceptableMajorDeltas()
Return an array of acceptable major deltas for the vertical axis. The vertical axis is created in such a way that each horizontal line is placed in the graph at a sensible value, e.g. a graph may have four horizontal lines, each separated by $1.20:
 --------------- $4.80

 -----+==+------ $3.60
     /    \
 ---+------+---- $2.40
   /        \---
 -+------------- $1.20
 
Here the values of the horizontal lines are $1.20, $2.40, $3.60 & $4.80. These are sensible values, values such as $1.36, $2.72, $4.08 & $5.44 are not as sensible. All the allowable values are calculated by the cross product of Major Deltas x Minor Deltas.

Returns:
an array of doubles representing the major deltas

getAcceptableMinorDeltas

public double[] getAcceptableMinorDeltas()
Return an array of acceptable minor deltas for the vertical axis.

Returns:
an array of doubles representing the minor deltas
See Also:
getAcceptableMajorDeltas()

getSettings

public java.util.HashMap getSettings()
Return the graph's current settings. Each graph must contain its user definable settings in a hashmap. If a graph does not have any user definable settings, then it can just return an empty hashmap here.

Returns:
settings

setSettings

public void setSettings(java.util.HashMap settings)
Set the graph's user definable settings.

Parameters:
settings - the new settings

getUI

public GraphUI getUI(java.util.HashMap settings)
Return the graph's user interface to allow the user to modify its settings. Pass the initial settings or an empty hashmap to use the graph's default settings. If the graph does not have any user-definable settings, then it should not have a user interface and should return null here.

Parameters:
settings - initial settings
Returns:
user interface or null

isPrimary

public boolean isPrimary()
Return whether the graph is a primary graph. Primary graphs will appear together in the top chart. Secondary graphs appear in their own charts which are added below. The day close graph is primary; while the day close graph is secondary.

Returns:
true if the graph is a primary graph

dataAvailable

public boolean dataAvailable(java.util.Vector xRange)
Return whether the graph has a price for range xRange Is trivially true for all graphs apart from the PointAndFigure graph as P&F is the only graph type where price data does not map one to one to date.

Parameters:
xRange - Range of X values
Returns:
True if data is available for range xRange.

Venice 0.751beta