Class graph.Graph2D
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class graph.Graph2D

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----graph.Graph2D

public class Graph2D
extends Canvas
This is the main plotting class. It partitions the canvas to contain the specified axes with the remaining space taken with the plotting region. Axes are packed against the walls of the canvas. The paint and update methods of this class handle all the drawing operations of the graph. This means that independent components like Axis and DataSets must be registered with this class to be incorporated into the plot.
Version:
1.12, 1996/09/24 05:23:41
Author:
Leigh Brookshaw

Variable Index

 o axis
A vector list of All the axes attached
 o borderBottom
The width of the border at the bottom of the canvas.
 o borderLeft
The width of the border at the left of the canvas.
 o borderRight
The width of the border at the right of the canvas.
 o borderTop
The width of the border at the top of the canvas.
 o clearAll
If set true (the default) the canvas will be set to the background color (erasing the plot) when the update method is called.
 o DataBackground
The background color for the data window
 o datarect
The rectangle that the data will be plotted within.
 o dataset
A vector list of All the DataSets attached
 o drawgrid
If set true (the default) a grid will be drawn over the data window.
 o drawzero
If set true (the default) a grid line will be drawn across the data window at the zeros of the innermost axes.
 o frame
If set true a frame will be drawn around the data window.
 o framecolor
The color of the frame to be drawn
 o gridcolor
The color of the grid to be drawn
 o lastText
Text to be painted Last onto the Graph Canvas.
 o load_thread
The blinking "data loading" thread
 o loadingData
If this is greater than zero it means that data loading threads are active so the message "loading data" is flashed on the plot canvas.
 o markers
The markers that may have been loaded
 o paintAll
If set true (the default) everything associated with the plot will be drawn when the update method or paint method are called.
 o square
Modify the position of the axis and the range of the axis so that the aspect ratio of the major tick marks are 1 and the plot is square on the screen
 o zerocolor
The color of the zero grid lines.

Constructor Index

 o Graph2D()

Method Index

 o attachAxis(Axis)
Attach a previously created Axis.
 o attachDataSet(DataSet)
Attach a DataSet to the graph.
 o createAxis(int)
Create and attach an Axis to the graph.
 o detachAxes()
Detach All attached Axes.
 o detachAxis(Axis)
Detach a previously attached Axis.
 o detachDataSet(DataSet)
Detach the DataSet from the class.
 o detachDataSets()
Detach All the DataSets from the class.
 o drawAxis(Graphics, Rectangle)
Draw the Axis.
 o drawFrame(Graphics, int, int, int, int)
 o finishedloading()
Decrement the loading Data counter by one.
 o ForceSquare(Graphics, Rectangle)
Force the plot to have an aspect ratio of 1 by forcing the axes to have the same range.
 o getDataRectangle(Graphics, Rectangle)
Calculate the rectangle occupied by the data
 o getMarkers()
Get the markers
 o getXmax()
Get the Maximum X value of all attached DataSets.
 o getXmin()
Get the Minimum X value of all attached DataSets.
 o getYmax()
Get the Maximum Y value of all attached DataSets.
 o getYmin()
Get the Minimum Y value of all attached DataSets.
 o keyDown(Event, int)
Handle keyDown events.
 o loadDataSet(double[], int)
Load and Attach a DataSet from an array.
 o loadFile(URL)
Load and Attach a DataSet from a File.
 o loadmessage(String)
Change the message to be flashed on the canvas
 o paint(Graphics)
This paints the entire plot.
 o paintBeforeData(Graphics, Rectangle)
A hook into the Graph2D.paint method.
 o paintFirst(Graphics, Rectangle)
A hook into the Graph2D.paint method.
 o paintLast(Graphics, Rectangle)
A hook into the Graph2D.paint method.
 o setDataBackground(Color)
Set the background color for the data window.
 o setGraphBackground(Color)
Set the background color for the entire canvas.
 o setMarkers(Markers)
Set the markers for the plot.
 o startedloading()
Calling this method pauses the plot and displays a flashing message on the screen.
 o update(Graphics)
This method is called via the Graph2D.repaint() method.

Variables

 o axis
  protected Vector axis
A vector list of All the axes attached @see Graph2d#attachAxis()
 o dataset
  protected Vector dataset
A vector list of All the DataSets attached @see Graph2d#attachDataSet() @see DataSet
 o markers
  protected Markers markers
The markers that may have been loaded @see Graph2D#setMarkers()
 o load_thread
  protected LoadMessage load_thread
The blinking "data loading" thread
See Also:
startedloading
 o DataBackground
  protected Color DataBackground
The background color for the data window
 o loadingData
  public int loadingData
If this is greater than zero it means that data loading threads are active so the message "loading data" is flashed on the plot canvas. When it is back to zero the plot progresses normally
 o borderTop
  public int borderTop
The width of the border at the top of the canvas. This allows slopover from axis labels, legends etc.
 o borderBottom
  public int borderBottom
The width of the border at the bottom of the canvas. This allows slopover from axis labels, legends etc.
 o borderLeft
  public int borderLeft
The width of the border at the left of the canvas. This allows slopover from axis labels, legends etc.
 o borderRight
  public int borderRight
The width of the border at the right of the canvas. This allows slopover from axis labels, legends etc.
 o frame
  public boolean frame
If set true a frame will be drawn around the data window. Any axes will overlay this frame.
 o framecolor
  public Color framecolor
The color of the frame to be drawn
 o drawgrid
  public boolean drawgrid
If set true (the default) a grid will be drawn over the data window. The grid will align with the major tic marks of the Innermost axes.
 o gridcolor
  public Color gridcolor
The color of the grid to be drawn
 o drawzero
  public boolean drawzero
If set true (the default) a grid line will be drawn across the data window at the zeros of the innermost axes.
 o zerocolor
  public Color zerocolor
The color of the zero grid lines.
 o datarect
  public Rectangle datarect
The rectangle that the data will be plotted within. This is an output variable only.
 o clearAll
  public boolean clearAll
If set true (the default) the canvas will be set to the background color (erasing the plot) when the update method is called. This would only be changed for special effects.
 o paintAll
  public boolean paintAll
If set true (the default) everything associated with the plot will be drawn when the update method or paint method are called. Normally only modified for special effects
 o square
  public boolean square
Modify the position of the axis and the range of the axis so that the aspect ratio of the major tick marks are 1 and the plot is square on the screen
 o lastText
  public TextLine lastText
Text to be painted Last onto the Graph Canvas.

Constructors

 o Graph2D
  public Graph2D()

Methods

 o loadFile
  public DataSet loadFile(URL file)
Load and Attach a DataSet from a File. The method loads the data into a DataSet class and attaches the class to the graph for plotting. The data is assumed to consist (at this stage) 2 ASCII columns of numbers x, y. As always blank lines are ignored and everything following # is ignored as a comment. @param file The URL of the data file to read. @return The DataSet constructed containing the data read.
 o loadDataSet
  public DataSet loadDataSet(double data[],
                             int n)
Load and Attach a DataSet from an array. The method loads the data into a DataSet class and attaches the class to the graph for plotting. The data is assumed to be stored in the form x,y,x,y,x,y.... A local copy of the data is made. @param data The data to be loaded in the form x,y,x,y,... @param n The number of (x,y) data points. This means that the minimum length of the data array is 2*n. @return The DataSet constructed containing the data read.
 o attachDataSet
  public void attachDataSet(DataSet d)
Attach a DataSet to the graph. By attaching the data set the class can draw the data through its paint method.
 o detachDataSet
  public void detachDataSet(DataSet d)
Detach the DataSet from the class. Data associated with the DataSet will nolonger be plotted. @param d The DataSet to detach.
 o detachDataSets
  public void detachDataSets()
Detach All the DataSets from the class.
 o createAxis
  public Axis createAxis(int position)
Create and attach an Axis to the graph. The position of the axis is one of Axis.TOP, Axis.BOTTOM, Axis.LEFT or Axis.RIGHT. @param position Position of the axis in the drawing window.
 o attachAxis
  public void attachAxis(Axis a)
Attach a previously created Axis. Only Axes that have been attached will be drawn @param the Axis to attach.
 o detachAxis
  public void detachAxis(Axis a)
Detach a previously attached Axis. @param the Axis to dettach.
 o detachAxes
  public void detachAxes()
Detach All attached Axes.
 o getXmax
  public double getXmax()
Get the Maximum X value of all attached DataSets. @return The maximum value
 o getYmax
  public double getYmax()
Get the Maximum Y value of all attached DataSets. @return The maximum value
 o getXmin
  public double getXmin()
Get the Minimum X value of all attached DataSets. @return The minimum value
 o getYmin
  public double getYmin()
Get the Minimum Y value of all attached DataSets. @return The minimum value
 o setMarkers
  public void setMarkers(Markers m)
Set the markers for the plot. @param m Marker class containing the defined markers @see Markers
 o getMarkers
  public Markers getMarkers()
Get the markers @return defined Marker class @see Markers
 o setGraphBackground
  public void setGraphBackground(Color c)
Set the background color for the entire canvas.
Parameters:
s - c The color to set the canvas
 o setDataBackground
  public void setDataBackground(Color c)
Set the background color for the data window.
Parameters:
s - c The color to set the data window.
 o paint
  public void paint(Graphics g)
This paints the entire plot. It calls the draw methods of all the attached axis and data sets. The order of drawing is - Axis first, data legends next, data last. @params g Graphics state.
Overrides:
paint in class Canvas
 o paintFirst
  public void paintFirst(Graphics g,
                         Rectangle r)
A hook into the Graph2D.paint method. This is called before anything is plotted. The rectangle passed is the dimension of the canvas minus the border dimensions. @params g Graphics state @params r Rectangle containing the graph
 o paintBeforeData
  public void paintBeforeData(Graphics g,
                              Rectangle r)
A hook into the Graph2D.paint method. This is called before the data is drawn but after the axis. The rectangle passed is the dimension of the data window. @params g Graphics state @params r Rectangle containing the data
 o paintLast
  public void paintLast(Graphics g,
                        Rectangle r)
A hook into the Graph2D.paint method. This is called after everything has been drawn. The rectangle passed is the dimension of the data window. @params g Graphics state @params r Rectangle containing the data
 o update
  public void update(Graphics g)
This method is called via the Graph2D.repaint() method. All it does is blank the canvas (with the background color) before calling paint.
Overrides:
update in class Comonent
 o keyDown
  public boolean keyDown(Event e,
                         int key)
Handle keyDown events. Only one event is handled the pressing of the key 'r' - this will repaint the canvas.
Overrides:
KeyDown in class Comonent
 o startedloading
  public void startedloading()
Calling this method pauses the plot and displays a flashing message on the screen. Mainly used when data is being loaded across the net. Everytime this routine is called a counter is incremented the method Graph2D.finishedloading() decrements the counter. When the counter is back to zero the plotting resumes. @see Graph2D#finishedloading() @see Graph2D#loadmessage() @see LoadMessage
 o finishedloading
  public void finishedloading()
Decrement the loading Data counter by one. When it is zero resume plotting. @see Graph2D#startedloading() @see Graph2D#loadmessage() @see LoadMessage
 o loadmessage
  public void loadmessage(String s)
Change the message to be flashed on the canvas
Parameters:
s - String contining the new message.
See Also:
startedloading, finishedloading, LoadMessage
 o ForceSquare
  protected Rectangle ForceSquare(Graphics g,
                                  Rectangle r)
Force the plot to have an aspect ratio of 1 by forcing the axes to have the same range. If the range of the axes are very different some extremely odd things can occur. All axes are forced to have the same range, so more than 2 axis is pointless.
 o getDataRectangle
  protected Rectangle getDataRectangle(Graphics g,
                                       Rectangle r)
Calculate the rectangle occupied by the data
 o drawAxis
  protected Rectangle drawAxis(Graphics g,
                               Rectangle r)
Draw the Axis. As each axis is drawn and aligned less of the canvas is avaliable to plot the data. The returned Rectangle is the canvas area that the data is plotted in.
 o drawFrame
  protected void drawFrame(Graphics g,
                           int x,
                           int y,
                           int width,
                           int height)

All Packages  Class Hierarchy  This Package  Previous  Next  Index