org.gwoptics.graphics.graph2D
Class Axis2D

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

public class Axis2D
extends Renderable
implements processing.core.PConstants

Axis2D is a straight forward object for drawing 2D axes. It has all the functionality for tick marks, minimum and maximum values, colour and size, tick labels and axis labels.

Once an axis object has been created it is down the the user to specify the necessary rotations of labels to make it readable. All the functions beginning with set should be used to alter the axis.

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

Nested Class Summary
static class Axis2D.Alignment
          Encapsulates the 3 alignment constants already present in the PConstants interface.
 
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
Axis2D(processing.core.PApplet parent, int length)
          Axis2D constructor accepting the parent PApplet and the length of the axis in pixels
 
Method Summary
 void draw()
           
 int getLength()
          returns the length of the axis in world space.
 java.lang.Integer[] getMajorTickPositions()
           
 float getMajorTickSpacing()
          Gets the number of major ticks on the axis
 float getMaxValue()
          returns the maximum value of the axis range
 java.lang.Integer[] getMinorTickPositions()
           
 float getMinValue()
          returns the minimum value of the axis range
 float positionToValue(int pixel)
          For a given number of pixels along the axis, the value it represents is returned
 void pre()
           
 void setAxesDirection(processing.core.PVector uv)
          Sets the direction in which the axis is drawn
 void setAxisColour(GWColour c)
          Sets the axis line colour from a Colour object
 void setAxisColour(int R, int G, int B)
          Sets the axis line colour from RGB values
 void setAxisLabel(java.lang.String lbl)
          Sets the label of the axis
 void setAxisLabelPos(LabelPos lblpos)
          Sets the position of the axis label along the axis
 void setDrawAxisLabel(boolean value)
          Sets whether or not to draw the axis label
 void setDrawTickLabels(boolean value)
          Sets whether or not to draw the tick major tick labels
 void setDrawTicks(boolean value)
          Sets whether or not to draw the tick marks on the axis
 void setFontColour(GWColour c)
          Sets the labels font colour from a Colour object
 void setFontColour(int R, int G, int B)
          Sets the labels font colour from RGB values
 void setLabelDirection(processing.core.PVector vlbl)
          Sets the direction as a PVector, of which way the ticks and labels should be from the main axis line.
 void setLabelOffset(float val)
          Sets an offset that is to be applied to the axis label.
 void setLabelRotation(float val)
          Sets the rotation to be applied to the main axis label
 void setMajorTickLength(int val)
          Sets the length of the major ticks, using a negative length extends ticks into the graph rather than to the labels
 void setMaxValue(float val)
          Sets the maximum value to show on the axis
 void setMinorTickLength(int val)
          Sets the length of the minor ticks, using a negative length extends ticks into the graph rather than to the labels
 void setMinorTicks(int t)
          Sets the number of minor ticks to show
 void setMinValue(float val)
          Sets the minimum value to show on the axis
 void setOffsetLabelByTickLength(boolean value)
          Sets whether to offset the label by the longest tick label that has been rendered.
 void setTickLabelAccuracy(int v)
          Sets the number of decimal places to display in each tick label.
 void setTickLabelAlignment(Axis2D.Alignment a)
          Sets the alignment of the major tick labels, from the Alignment enum
 void setTickLabelOffset(int val)
          Sets an offset that is to be applied to the major tick labels.
 void setTickLabelRotation(float val)
          Sets the rotation to be applied to each tick label
 void setTickLabelType(ValueType v)
          Sets the type of number to display on the graph
 void setTickSpacing(float spacing)
          Sets the spacing between each tick in graph space
 int valueToPosition(double value)
           
 int valueToPosition(float value)
          For a given graph value it provides the position it is on the axis to the nearest pixel
 
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

Axis2D

public Axis2D(processing.core.PApplet parent,
              int length)
Axis2D constructor accepting the parent PApplet and the length of the axis in pixels

Method Detail

setAxisColour

public void setAxisColour(int R,
                          int G,
                          int B)
Sets the axis line colour from RGB values


setAxisColour

public void setAxisColour(GWColour c)
Sets the axis line colour from a Colour object


setFontColour

public void setFontColour(int R,
                          int G,
                          int B)
Sets the labels font colour from RGB values


setFontColour

public void setFontColour(GWColour c)
Sets the labels font colour from a Colour object


setDrawTicks

public void setDrawTicks(boolean value)
Sets whether or not to draw the tick marks on the axis


setDrawTickLabels

public void setDrawTickLabels(boolean value)
Sets whether or not to draw the tick major tick labels


setDrawAxisLabel

public void setDrawAxisLabel(boolean value)
Sets whether or not to draw the axis label


setAxisLabel

public void setAxisLabel(java.lang.String lbl)
Sets the label of the axis


setAxisLabelPos

public void setAxisLabelPos(LabelPos lblpos)
Sets the position of the axis label along the axis

Parameters:
lblpos - position can be START, MIDDLE, END or OUTSIDE

setLabelOffset

public void setLabelOffset(float val)
Sets an offset that is to be applied to the axis label. This offset is applied in the direction of the ticks away from the axis.


setOffsetLabelByTickLength

public void setOffsetLabelByTickLength(boolean value)
Sets whether to offset the label by the longest tick label that has been rendered. This is used in situations with vertical axes and the tick labels vary in length as the values get larger.


setTickLabelOffset

public void setTickLabelOffset(int val)
Sets an offset that is to be applied to the major tick labels. This offset is applied in the direction of the ticks away from the axis.


setTickLabelAlignment

public void setTickLabelAlignment(Axis2D.Alignment a)
Sets the alignment of the major tick labels, from the Alignment enum


setTickLabelRotation

public void setTickLabelRotation(float val)
Sets the rotation to be applied to each tick label


setLabelRotation

public void setLabelRotation(float val)
Sets the rotation to be applied to the main axis label


setLabelDirection

public void setLabelDirection(processing.core.PVector vlbl)
Sets the direction as a PVector, of which way the ticks and labels should be from the main axis line.


setAxesDirection

public void setAxesDirection(processing.core.PVector uv)
Sets the direction in which the axis is drawn


setTickSpacing

public void setTickSpacing(float spacing)
Sets the spacing between each tick in graph space


setMinorTicks

public void setMinorTicks(int t)
Sets the number of minor ticks to show


setTickLabelType

public void setTickLabelType(ValueType v)
Sets the type of number to display on the graph

See Also:
ValueType

setTickLabelAccuracy

public void setTickLabelAccuracy(int v)
Sets the number of decimal places to display in each tick label. Only valid for tick valueTypes of DECIAML or EXPONENT


setMajorTickLength

public void setMajorTickLength(int val)
Sets the length of the major ticks, using a negative length extends ticks into the graph rather than to the labels

Parameters:
val - length of the major ticks

setMinorTickLength

public void setMinorTickLength(int val)
Sets the length of the minor ticks, using a negative length extends ticks into the graph rather than to the labels

Parameters:
val - length of the major ticks

setMaxValue

public void setMaxValue(float val)
Sets the maximum value to show on the axis


setMinValue

public void setMinValue(float val)
Sets the minimum value to show on the axis


getMajorTickSpacing

public float getMajorTickSpacing()
Gets the number of major ticks on the axis


getMaxValue

public float getMaxValue()
returns the maximum value of the axis range


getMinValue

public float getMinValue()
returns the minimum value of the axis range


getLength

public int getLength()
returns the length of the axis in world space.


getMajorTickPositions

public java.lang.Integer[] getMajorTickPositions()

getMinorTickPositions

public java.lang.Integer[] getMinorTickPositions()

pre

public void pre()

draw

public void draw()
Specified by:
draw in interface IRenderable
Specified by:
draw in class Renderable

valueToPosition

public int valueToPosition(float value)
For a given graph value it provides the position it is on the axis to the nearest pixel


valueToPosition

public int valueToPosition(double value)

positionToValue

public float positionToValue(int pixel)
For a given number of pixels along the axis, the value it represents is returned



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