org.gwoptics.graphics.graph2D
Class Graph2D

java.lang.Object
  extended by org.gwoptics.graphics.Renderable
      extended by org.gwoptics.graphics.graph2D.Graph2D
All Implemented Interfaces:
IGraph2D, IRenderable, processing.core.PConstants

public class Graph2D
extends Renderable
implements processing.core.PConstants, IGraph2D

Graph2D is a collection of Axis2D objects and IGraphTrace's. It is the basis of a 2D graph and can have multiple traces added to it, with access to various methods to alter the look and feel of the graph axes and layout.

The traces that this graph excepts must conform to the IGraphTrace interface and must fully implement it correctly. The graph also allows full control over the X and Y axes through controls that begin with setXAxis and setYaxis. Also available is the option to display a border and major grid lines.

Since:
0.4.0
Author:
Daniel Brown 13/7/09

Field Summary
 
Fields inherited from class org.gwoptics.graphics.Renderable
position
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
Graph2D(processing.core.PApplet parent, int xLength, int yLength, boolean crossAxesAtZero)
          Graph constructor that requires you to define the dimensions of the graph, whether the axes should cross at the 0 and the parent PApplet object which is rendering the graph.
 
Method Summary
 int addTrace(IGraph2DTrace trace)
          Method to add an object that has implements the IGraphTrace interface.
 void draw()
          Draw method that calls various internal methods to generate each part of the graph.
 void generateTrace(int index)
          Calls the traces generate method to refresh data.
 IGraph2DBackground getGraphBackground()
          Gets a reference to the current Background renderer
 Axis2D getXAxis()
           
 Axis2D getYAxis()
           
 void removeTrace(IGraph2DTrace trace)
          Removes a trace from the graph depending on its index.
 void setAxisColour(GWColour c)
          Sets the colour of the X and Y axes, through a Colour object
 void setAxisColour(int R, int G, int B)
          Sets the colour of the X and Y axes, through RGB values
 void setBackground(IGraph2DBackground bk)
          Sets an IGraph2DBackground to use to fill the graph background
 void setBorderColour(int R, int G, int B)
          Sets the colour of the border surrounding the graph object
 void setFontColour(GWColour c)
          Sets the colour of the X and Y fonts, through a Colour object
 void setFontColour(int R, int G, int B)
          Sets the colour of the X and Y axes fonts, through RGB values
 void setNoBackground()
          Sets the colour of the border surrounding the graph object
 void setNoBorder()
          Removes border
 void setXAxisLabel(java.lang.String s)
          Sets the label that describes the data shown on the X-Axis
 void setXAxisLabelAccuracy(int l)
          Sets the decimal places to show on the X-Axis tick labels
 void setXAxisLabelPos(LabelPos lblpos)
          Sets the label position for the X-Axis
 void setXAxisMax(float val)
          Sets the maximum value to be shown on the X-Axis
 void setXAxisMin(float val)
          Sets the minimum value to be shown on the X-Axis
 void setXAxisMinorTicks(int n)
          Sets number of minor ticks to show on the X-Axis
 void setXAxisTickSpacing(float s)
           
 void setYAxisLabel(java.lang.String s)
          Sets the label that describes the data shown on the Y-Axis
 void setYAxisLabelAccuracy(int l)
          Sets the decimal places to show on the Y-Axis tick labels
 void setYAxisLabelPos(LabelPos lblpos)
          Sets the label position for the Y-Axis
 void setYAxisMax(float val)
          Sets the maximum value to be shown on the Y-Axis
 void setYAxisMin(float val)
          Sets the minimum value to be shown on the Y-Axis
 void setYAxisMinorTicks(int n)
          Sets number of minor ticks to show on the Y-Axis
 void setYAxisTickSpacing(float s)
           
 
Methods inherited from class org.gwoptics.graphics.Renderable
setParent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph2D

public Graph2D(processing.core.PApplet parent,
               int xLength,
               int yLength,
               boolean crossAxesAtZero)
Graph constructor that requires you to define the dimensions of the graph, whether the axes should cross at the 0 and the parent PApplet object which is rendering the graph.

Parameters:
parent -
xLength -
yLength -
crossAxesAtZero -
Method Detail

setXAxisTickSpacing

public void setXAxisTickSpacing(float s)

setYAxisTickSpacing

public void setYAxisTickSpacing(float s)

setXAxisMin

public void setXAxisMin(float val)
Sets the minimum value to be shown on the X-Axis


setXAxisMax

public void setXAxisMax(float val)
Sets the maximum value to be shown on the X-Axis


setYAxisMin

public void setYAxisMin(float val)
Sets the minimum value to be shown on the Y-Axis


setYAxisMax

public void setYAxisMax(float val)
Sets the maximum value to be shown on the Y-Axis


setXAxisLabel

public void setXAxisLabel(java.lang.String s)
Sets the label that describes the data shown on the X-Axis


setYAxisLabel

public void setYAxisLabel(java.lang.String s)
Sets the label that describes the data shown on the Y-Axis


setXAxisLabelPos

public void setXAxisLabelPos(LabelPos lblpos)
Sets the label position for the X-Axis


setYAxisLabelPos

public void setYAxisLabelPos(LabelPos lblpos)
Sets the label position for the Y-Axis


setXAxisLabelAccuracy

public void setXAxisLabelAccuracy(int l)
Sets the decimal places to show on the X-Axis tick labels


setYAxisLabelAccuracy

public void setYAxisLabelAccuracy(int l)
Sets the decimal places to show on the Y-Axis tick labels


setXAxisMinorTicks

public void setXAxisMinorTicks(int n)
Sets number of minor ticks to show on the X-Axis


setYAxisMinorTicks

public void setYAxisMinorTicks(int n)
Sets number of minor ticks to show on the Y-Axis


setAxisColour

public void setAxisColour(int R,
                          int G,
                          int B)
Sets the colour of the X and Y axes, through RGB values


setAxisColour

public void setAxisColour(GWColour c)
Sets the colour of the X and Y axes, through a Colour object


setFontColour

public void setFontColour(int R,
                          int G,
                          int B)
Sets the colour of the X and Y axes fonts, through RGB values


setFontColour

public void setFontColour(GWColour c)
Sets the colour of the X and Y fonts, through a Colour object


getGraphBackground

public IGraph2DBackground getGraphBackground()
Description copied from interface: IGraph2D
Gets a reference to the current Background renderer

Specified by:
getGraphBackground in interface IGraph2D

getXAxis

public Axis2D getXAxis()
Specified by:
getXAxis in interface IGraph2D

getYAxis

public Axis2D getYAxis()
Specified by:
getYAxis in interface IGraph2D

setNoBorder

public void setNoBorder()
Removes border


setNoBackground

public void setNoBackground()
Sets the colour of the border surrounding the graph object


setBorderColour

public void setBorderColour(int R,
                            int G,
                            int B)
Sets the colour of the border surrounding the graph object


setBackground

public void setBackground(IGraph2DBackground bk)
Sets an IGraph2DBackground to use to fill the graph background


addTrace

public int addTrace(IGraph2DTrace trace)
Method to add an object that has implements the IGraphTrace interface. Throws exception if trace is null. Returns an integer which represents the index of the array the trace is stored in.

Parameters:
trace - IGraphTrace
Returns:
int Index that the trace is stored in the control

removeTrace

public void removeTrace(IGraph2DTrace trace)
Removes a trace from the graph depending on its index. Index of trace increase from 0 by 1 for each trace added.

Parameters:
trace -

generateTrace

public void generateTrace(int index)
Calls the traces generate method to refresh data. Trace is identified by its index.

Parameters:
index -

draw

public void draw()
Draw method that calls various internal methods to generate each part of the graph. Normally called from draw loop

Specified by:
draw in interface IRenderable
Specified by:
draw in class Renderable


processing library gwoptics by Daniel Brown and Andreas Freise. (c) 2009 onwards