jwo.utils
Class JWGraph
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Canvas
|
+--jwo.utils.JWCanvas
|
+--jwo.utils.JWGraph
- All Implemented Interfaces:
- Accessible, ComponentListener, EventListener, ImageObserver, MenuContainer, Serializable
- Direct Known Subclasses:
- BlockGraph, Histogram, LineGraph, PolarGraph, ScatterPlot
- public class JWGraph
- extends JWCanvas
Simple graph object. Originally based on the code given
in the tutorial Chart your way to custom graph components
, by Maria Winslow, 1997 (JavaWorld, July, 1997).
See http://www.javaworld.com/javaworld/jw-07-1997/jw-07-step.html
Modified to use Java 1.1 (image rescaling etc.) and
use additional axis labelling.
- Version:
- 1.8.0, 11th December, 1999.
- Author:
- Jo Wood
- See Also:
- Serialized Form
Field Summary |
protected int |
bottom
Bottom position of graph. |
protected int |
centreX
X coord of centre of graph. |
protected int |
centreY
Y coord of centre of graph. |
static int |
INTERVAL
Measurement scale of data. |
protected Vector |
items
Array of graphic items in graph. |
protected int |
left
Left position of graph. |
static int |
NOMINAL
Measurement scale of data. |
static int |
ORDINAL
Measurement scale of data. |
static int |
RATIO
Measurement scale of data. |
protected int |
right
Right position of graph. |
protected int |
top
Top position of graph. |
Constructor Summary |
JWGraph()
Minimal advance graph layout (axes only). |
JWGraph(String title,
float yMin,
float yMax)
Lays out the graph title, labels etc. |
JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax)
Lays out the graph title, labels etc. |
JWGraph(String title,
float rMin,
float rMax,
float thetaMin,
float thetaMax,
boolean polar)
Lays out the graph title, labels etc as a polar plot. |
JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax,
String[] labels)
Lays out the graph title, labels etc. |
JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax,
String[] labels,
int measurementScale)
Lays out the graph title, labels etc. |
JWGraph(String title,
float xMin,
float xMax,
String[] labels,
float yMin,
float yMax)
Lays out the graph title, labels etc. |
JWGraph(String title,
float xMin,
float xMax,
String[] labels,
float yMin,
float yMax,
int measurementScale)
Lays out the graph title, labels etc. |
Method Summary |
void |
addItem(float xValue,
float yValue)
Adds a (default menu text colour) graphical element to the graph. |
void |
addItem(float xValue,
float yValue,
Color col)
Adds a (coloured) graphical element to the graph. |
void |
componentResized(ComponentEvent event)
Overrides the componentResized method for responding to
changes in component size. |
FontMetrics |
getFM()
Reports the font metric used by the graph. |
Dimension |
getPreferredSize()
Overrides the component's getPreferredSize method to
set the initial size of the graph. |
float |
getXMax()
Reports the maximum X value of the graph. |
int |
getXMeasurementScale()
Reports on the measurement scale of the data on the
X-axis. |
float |
getXMin()
Reports the minimum X value of the graph. |
float |
getYMax()
Reports the maximum Y value of the graph. |
int |
getYMeasurementScale()
Reports on the measurement scale of the data on the
Y-axis. |
float |
getYMin()
Reports the minimum Y value of the graph. |
void |
paint(Graphics g)
Overrides the paint method to draw the graph
components. |
void |
removeItem(float xValue,
float yValue)
Removes a graphical element from the graph (identified by x,y values). |
void |
removeItems()
Removes all graphical elements from the graph. |
void |
setXAxis(float min,
float max)
Sets the x-axis to the given range. |
void |
setXMeasurementScale(int scale)
Sets the measurement scale of the data on the
X-axis. |
void |
setYAxis(float min,
float max)
Sets the y-axis to the given range. |
void |
setYMeasurementScale(int scale)
Sets the measurement scale of the data on the
Y-axis. |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
NOMINAL
public static final int NOMINAL
- Measurement scale of data.
- See Also:
- Constant Field Values
ORDINAL
public static final int ORDINAL
- Measurement scale of data.
- See Also:
- Constant Field Values
INTERVAL
public static final int INTERVAL
- Measurement scale of data.
- See Also:
- Constant Field Values
RATIO
public static final int RATIO
- Measurement scale of data.
- See Also:
- Constant Field Values
top
protected int top
- Top position of graph.
bottom
protected int bottom
- Bottom position of graph.
left
protected int left
- Left position of graph.
right
protected int right
- Right position of graph.
centreX
protected int centreX
- X coord of centre of graph.
centreY
protected int centreY
- Y coord of centre of graph.
items
protected Vector items
- Array of graphic items in graph.
JWGraph
public JWGraph()
- Minimal advance graph layout (axes only).
JWGraph
public JWGraph(String title,
float yMin,
float yMax)
- Lays out the graph title, labels etc. Assumes Y range
is known in advance.
- Parameters:
title
- Title of the graph.yMin
- Minimum Y value.yMax
- Maximum Y value.
JWGraph
public JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax)
- Lays out the graph title, labels etc. Assumes both
X and Y range are known in advance.
- Parameters:
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.yMin
- Minimum Y value.yMax
- Maximum Y value.
JWGraph
public JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax,
String[] labels)
- Lays out the graph title, labels etc. Assumes both
X and Y range are known in advance and Y axis contains
nominal scale labels.
- Parameters:
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.yMin
- Minimum Y value.yMax
- Maximum Y value.labels
- Array holding labels for Y axis.
JWGraph
public JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax,
String[] labels,
int measurementScale)
- Lays out the graph title, labels etc. Assumes both
X and Y range are known in advance and Y axis contains
scale labels on the given measurement scale.
- Parameters:
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.yMin
- Minimum Y value.yMax
- Maximum Y value.labels
- Array holding labels for Y axis.measurementScale
- Measurement scale of the labelled axis.
JWGraph
public JWGraph(String title,
float xMin,
float xMax,
String[] labels,
float yMin,
float yMax)
- Lays out the graph title, labels etc. Assumes both
X and Y range are known in advance and X axis contains
nominal scale labels.
- Parameters:
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.labels
- Array holding lables of X axis.yMin
- Minimum Y value.yMax
- Maximum Y value.
JWGraph
public JWGraph(String title,
float xMin,
float xMax,
String[] labels,
float yMin,
float yMax,
int measurementScale)
- Lays out the graph title, labels etc. Assumes both
X and Y range are known in advance and X axis contains
labels on the given measurement scale.
- Parameters:
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.labels
- Array holding lables of X axis.yMin
- Minimum Y value.yMax
- Maximum Y value.measurementScale
- Measurement scale of the labelled axis.
JWGraph
public JWGraph(String title,
float rMin,
float rMax,
float thetaMin,
float thetaMax,
boolean polar)
- Lays out the graph title, labels etc as a polar plot.
Assumes both radius and angular range are known in advance.
- Parameters:
title
- Title of the graph.rMin
- Minimum X value.rMax
- Maximum X value.thetaMin
- Starting angular value.thetaMax
- Ending angular value.polar
- Indicates a polar plot.
addItem
public void addItem(float xValue,
float yValue)
- Adds a (default menu text colour) graphical element to the graph.
- Parameters:
xValue
- x-value associated with item.yValue
- y-value associated with item.
addItem
public void addItem(float xValue,
float yValue,
Color col)
- Adds a (coloured) graphical element to the graph.
- Parameters:
xValue
- x-value associated with item.yValue
- y-value associated with item.col
- Colour of item.
removeItem
public void removeItem(float xValue,
float yValue)
- Removes a graphical element from the graph (identified by x,y values).
- Parameters:
xValue
- x-value associated with item.yValue
- y-value associated with item.
removeItems
public void removeItems()
- Removes all graphical elements from the graph.
getYMin
public float getYMin()
- Reports the minimum Y value of the graph.
- Returns:
- Minimum Y value.
getYMax
public float getYMax()
- Reports the maximum Y value of the graph.
- Returns:
- Maximum Y value.
getXMin
public float getXMin()
- Reports the minimum X value of the graph.
- Returns:
- Minimum X value.
getXMax
public float getXMax()
- Reports the maximum X value of the graph.
- Returns:
- Maximum X value.
getFM
public FontMetrics getFM()
- Reports the font metric used by the graph.
- Returns:
- Font metric.
getXMeasurementScale
public int getXMeasurementScale()
- Reports on the measurement scale of the data on the
X-axis.
- Returns:
- Mesurement scale (NOMINAL, ORDINAL, INTERVAL
or RATIO).
getYMeasurementScale
public int getYMeasurementScale()
- Reports on the measurement scale of the data on the
Y-axis.
- Returns:
- Mesurement scale (NOMINAL, ORDINAL, INTERVAL
or RATIO).
setXMeasurementScale
public void setXMeasurementScale(int scale)
- Sets the measurement scale of the data on the
X-axis.
- Parameters:
scale
- Mesurement scale (NOMINAL, ORDINAL,
INTERVAL or RATIO).
setYMeasurementScale
public void setYMeasurementScale(int scale)
- Sets the measurement scale of the data on the
Y-axis.
- Parameters:
scale
- Mesurement scale (NOMINAL, ORDINAL,
INTERVAL or RATIO).
setXAxis
public void setXAxis(float min,
float max)
- Sets the x-axis to the given range.
- Parameters:
min
- Minimum axis value.max
- Maximum axis value.
setYAxis
public void setYAxis(float min,
float max)
- Sets the y-axis to the given range.
- Parameters:
min
- Minimum axis value.max
- Maximum axis value.
paint
public void paint(Graphics g)
- Overrides the paint method to draw the graph
components.
- Overrides:
paint
in class Canvas
- Parameters:
g
- Graphics context to paint to.
componentResized
public void componentResized(ComponentEvent event)
- Overrides the componentResized method for responding to
changes in component size.
- Specified by:
componentResized
in interface ComponentListener
- Overrides:
componentResized
in class JWCanvas
- Parameters:
event
- Component event to process.
getPreferredSize
public Dimension getPreferredSize()
- Overrides the component's getPreferredSize method to
set the initial size of the graph.
- Overrides:
getPreferredSize
in class Component
- Returns:
- The graph's preferred size.