radtools.graphing
Class GraphicsWrapper

java.lang.Object
  extended by radtools.graphing.GraphicsWrapper

public class GraphicsWrapper
extends Object

Wrapper class for Graphics object, contains outside information to translate applet styled coordinate system to with origin in upper left corner to user-defined coordinate system with origin set by x and y range

TODO: Unit tests, Code review, Javadoc review, Seal/Finalize

Version:
$Revision: 1.1 $
Author:
Lilia Gutnik

Field Summary
(package private)  double cx1
          Rectangle coordinates in traditional Cartesian coordinates of the graph.
(package private)  double cx2
          Rectangle coordinates in traditional Cartesian coordinates of the graph.
(package private)  double cy1
          Rectangle coordinates in traditional Cartesian coordinates of the graph.
(package private)  double cy2
          Rectangle coordinates in traditional Cartesian coordinates of the graph.
protected  Graphics graphics
          Inherent graphics context object that contains the color and spatial information
(package private)  double kx
          Scale factors to take zoom ratio into account when drawing the inset graph within the larger screen
(package private)  double ky
          Scale factors to take zoom ratio into account when drawing the inset graph within the larger screen
(package private)  double ox
          Scaled origin coordinates used to appropriately left/right shift
(package private)  double oy
          Scaled origin coordinates used to appropriately left/right shift
(package private)  int sx1
          Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)
(package private)  int sx2
          Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)
(package private)  int sy1
          Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)
(package private)  int sy2
          Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)
(package private)  int tickHalfWidth
          Number of pixels long of half an axis tick
(package private)  int ticks
          Default number of ticks on an axis
(package private)  int xMargin
          Number of pixels for the margin between the graph and the surrounding border
(package private)  int yMargin
          Number of pixels for the margin between the graph and the surrounding border
 
Constructor Summary
GraphicsWrapper(Graphics _graphics)
          Sets default values for the screen boundaries and the x and y range of the inset graph
 
Method Summary
 void abscissa(String label)
          Draws the x-axis and labels it with input string
 double cx(int x)
          Translate window to Cartesian coordinates
 double cy(int y)
          Translate window to Cartesian coordinates
 void drawFunctionHeat(double[] x_points, double[] y_points, double[] z_points, double colorGradient, int colorSpectrum)
          Draws a three dimensional heat graph given three arrays of doubles The scope of the input determines the color gradient shift Colors are specified by Hue, Saturation and Brightness (ranging from [0,1]) and are converted to RGB values
 void drawFunctionLines(double[] x_points, double[] y_points, int flag)
          Draws a two dimensional line graph given two arrays of doubles
 void drawLine(double x1, double y1, double x2, double y2)
          Translates input Cartesian coordinates for the drawLine inherent to the graphics object and draws it
 void drawPoint(double x, double y)
          Draws defined circles at discrete point (x,y) in current graph context's color
 void drawRect(double x1, double y2, double x2, double y1)
          Draws the rectangle defined by the (x1, y2) and (x2, y1) as opposite corners with the current color of the graphics context translated to the graphics coordinate system
 void drawString(String message, double x, double y, int dx, int dy)
          Draws the text given by the specified string, using this graphics context's current font and color.
 boolean equals(GraphicsWrapper compare)
          Tests the equality based on the inner graphics wrapper
 void fillRect(double x1, double y2, double x2, double y1)
          Fills the rectangle defined by the (x1, y2) and (x2, y1) as opposite corners with the current color of the graphics context translated to the graphics coordinate system
 int hashCode()
          Returns a hash code value for the GraphicsWrapper object, based on the Graphics object
 void insetScreenRect()
          Sets the surrounding screen as a border around the graph with a margin set by xMargin and yMargin
 void insetScreenRect(int dx, int dy)
          Sets the surrounding screen as a border around the graph with a margin set by input parameters dx, dy
 void ordinate(String label)
          Draws the y-axis and labels it with the input string
 void setScreenRect(int sx1, int sy2, int sx2, int sy1)
          Sets the boundaries of the enclosing screen that frames the graph
 void setXRange(double a, double b)
          Translates the input x Cartesian coordinate boundaries into the relevant boundaries for the inset graph and for the surrounding screen
 void setYRange(double a, double b)
          Translates the input y Cartesian coordinate boundaries into the relevant boundaries for the inset graph and for the surrounding screen
 String toString()
          The string representation of the GraphicsWrapper object, based on the Graphics object
 int wx(double x)
          Translate Cartesian to window coordinates
 double wy(double y)
          Translate Cartesian to window coordinates
 void xTicks()
          Draws evenly spaced ticks on the x axis for the full range of the x axis
 void xTicks(double y, double x1, double x2, double spacing)
          Draws ticks on the x axis from x1 to x2, with each tick evenly spaced apart
 void xTicks(int n)
          Draws n evenly spaced ticks on the x axis for the full range of the x axis
 void yTicks()
          Draws evenly spaced ticks on the y axis for the full range of the y axis
 void yTicks(double x, double y1, double y2, double spacing)
          Draws ticks on the y axis from y1 to y2, with each tick evenly spaced apart
 void yTicks(int n)
          Draws n evenly spaced ticks on the y axis for the full range of the y axis
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ox

double ox
Scaled origin coordinates used to appropriately left/right shift


oy

double oy
Scaled origin coordinates used to appropriately left/right shift


kx

double kx
Scale factors to take zoom ratio into account when drawing the inset graph within the larger screen


ky

double ky
Scale factors to take zoom ratio into account when drawing the inset graph within the larger screen


cx1

double cx1
Rectangle coordinates in traditional Cartesian coordinates of the graph. cx1 (west), cx2 (east) cy2 (south), cy1 (north)


cy2

double cy2
Rectangle coordinates in traditional Cartesian coordinates of the graph. cx1 (west), cx2 (east) cy2 (south), cy1 (north)


cx2

double cx2
Rectangle coordinates in traditional Cartesian coordinates of the graph. cx1 (west), cx2 (east) cy2 (south), cy1 (north)


cy1

double cy1
Rectangle coordinates in traditional Cartesian coordinates of the graph. cx1 (west), cx2 (east) cy2 (south), cy1 (north)


sx1

int sx1
Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)


sy2

int sy2
Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)


sx2

int sx2
Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)


sy1

int sy1
Rectangle coordinates of the total screen containing the graph sx1 (west), sx2(east) sy1 (south), sy2 (north)


tickHalfWidth

int tickHalfWidth
Number of pixels long of half an axis tick


ticks

int ticks
Default number of ticks on an axis


xMargin

int xMargin
Number of pixels for the margin between the graph and the surrounding border


yMargin

int yMargin
Number of pixels for the margin between the graph and the surrounding border


graphics

protected final Graphics graphics
Inherent graphics context object that contains the color and spatial information

Constructor Detail

GraphicsWrapper

public GraphicsWrapper(Graphics _graphics)
Sets default values for the screen boundaries and the x and y range of the inset graph

Parameters:
_graphics - The intrinsic graphics object
Method Detail

abscissa

public void abscissa(String label)
Draws the x-axis and labels it with input string

Parameters:
label - The text that labels the x-axis

cx

public double cx(int x)
Translate window to Cartesian coordinates

Parameters:
x - Window x coordinate
Returns:
Cartesian x coordinate equivalent

cy

public double cy(int y)
Translate window to Cartesian coordinates

Parameters:
y - Window y coordinate
Returns:
Cartesian y coordinate equivalent

drawFunctionHeat

public void drawFunctionHeat(double[] x_points,
                             double[] y_points,
                             double[] z_points,
                             double colorGradient,
                             int colorSpectrum)
Draws a three dimensional heat graph given three arrays of doubles The scope of the input determines the color gradient shift Colors are specified by Hue, Saturation and Brightness (ranging from [0,1]) and are converted to RGB values

Parameters:
x_points - Array of x values
y_points - Array of y values
z_points - Array of z values
colorGradient - Order of magnitude of the inputs to determine how rapidly the colors should shift
colorSpectrum - Breadth of color spectrum to be created and graphed from

drawFunctionLines

public void drawFunctionLines(double[] x_points,
                              double[] y_points,
                              int flag)
Draws a two dimensional line graph given two arrays of doubles

Parameters:
x_points - Array of x values
y_points - Array of y values
flag - Indicates what color the line should be

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)
Translates input Cartesian coordinates for the drawLine inherent to the graphics object and draws it

Parameters:
x1 - start x Cartesian coordinate
y1 - start y Cartesian coordinate
x2 - end x Cartesian coordinate
y2 - end y Cartesian coordinate

drawPoint

public void drawPoint(double x,
                      double y)
Draws defined circles at discrete point (x,y) in current graph context's color

Parameters:
x - Cartesian x coordinate
y - Cartesian y coordinate

drawRect

public void drawRect(double x1,
                     double y2,
                     double x2,
                     double y1)
Draws the rectangle defined by the (x1, y2) and (x2, y1) as opposite corners with the current color of the graphics context translated to the graphics coordinate system

Parameters:
x1 - Cartesian x coordinate of first corner
y2 - Cartesian y coordinate of first corner
x2 - Cartesian x coordinate of opposite corner
y1 - Cartesian y coordinate of opposite corner

drawString

public void drawString(String message,
                       double x,
                       double y,
                       int dx,
                       int dy)
Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at Cartesian coordinate (x, y) to be translated to this graphics context's coordinate system, shifting relative to the surrounding screen by pixels (dx, dy)

Parameters:
message - The text to be drawn
x - The x Cartesian coordinate on the graph
y - The y Cartesian coordinate on the graph
dx - The number of pixels in the x direction to shift within the surrounding screen
dy - The number of pixels in the y direction to shift within the surrounding screen

equals

public boolean equals(GraphicsWrapper compare)
Tests the equality based on the inner graphics wrapper

Parameters:
compare - The GraphicsWrapper object to compare
Returns:
true if the inner graphics object is equal, false otherwise

fillRect

public void fillRect(double x1,
                     double y2,
                     double x2,
                     double y1)
Fills the rectangle defined by the (x1, y2) and (x2, y1) as opposite corners with the current color of the graphics context translated to the graphics coordinate system

Parameters:
x1 - Cartesian x coordinate of first corner
y2 - Cartesian y coordinate of first corner
x2 - Cartesian x coordinate of opposite corner
y1 - Cartesian y coordinate of opposite corner

hashCode

public int hashCode()
Returns a hash code value for the GraphicsWrapper object, based on the Graphics object

Overrides:
hashCode in class Object
Returns:
a hash code value

insetScreenRect

public void insetScreenRect()
Sets the surrounding screen as a border around the graph with a margin set by xMargin and yMargin


insetScreenRect

public void insetScreenRect(int dx,
                            int dy)
Sets the surrounding screen as a border around the graph with a margin set by input parameters dx, dy

Parameters:
dx - Number of pixels for margin between graph and screen in x direction
dy - Number of pixels for margin between graph and screen in y direction

ordinate

public void ordinate(String label)
Draws the y-axis and labels it with the input string

Parameters:
label - The text that labels the y-axis

setScreenRect

public void setScreenRect(int sx1,
                          int sy2,
                          int sx2,
                          int sy1)
Sets the boundaries of the enclosing screen that frames the graph

Parameters:
sx1 - new western boundary ( x direction )
sy2 - new southern boundary ( y direction )
sx2 - new eastern boundary ( x direction )
sy1 - new northern boundary ( y direction )

setXRange

public void setXRange(double a,
                      double b)
Translates the input x Cartesian coordinate boundaries into the relevant boundaries for the inset graph and for the surrounding screen

Parameters:
a - new west boundary (x) in Cartesian coordinates
b - new east boundary (x) in Cartesian coordinates

setYRange

public void setYRange(double a,
                      double b)
Translates the input y Cartesian coordinate boundaries into the relevant boundaries for the inset graph and for the surrounding screen

Parameters:
a - new south boundary (y) in Cartesian coordinates
b - new north boundary (y) in Cartesian coordinates

toString

public String toString()
The string representation of the GraphicsWrapper object, based on the Graphics object

Overrides:
toString in class Object
Returns:
a string representation of the object

wx

public int wx(double x)
Translate Cartesian to window coordinates

Parameters:
x - Cartesian x coordinate
Returns:
Relative window x coordinate

wy

public double wy(double y)
Translate Cartesian to window coordinates

Parameters:
y - Cartesian y coordinate
Returns:
Relative window y coordinate

xTicks

public void xTicks()
Draws evenly spaced ticks on the x axis for the full range of the x axis


xTicks

public void xTicks(double y,
                   double x1,
                   double x2,
                   double spacing)
Draws ticks on the x axis from x1 to x2, with each tick evenly spaced apart

Parameters:
y - The height of the tick
x1 - The starting x tick
x2 - The ending x tick
spacing - Number of pixels between each tick

xTicks

public void xTicks(int n)
Draws n evenly spaced ticks on the x axis for the full range of the x axis

Parameters:
n - Number of ticks to be drawn

yTicks

public void yTicks()
Draws evenly spaced ticks on the y axis for the full range of the y axis


yTicks

public void yTicks(double x,
                   double y1,
                   double y2,
                   double spacing)
Draws ticks on the y axis from y1 to y2, with each tick evenly spaced apart

Parameters:
x - Number of ticks to be drawn
y1 - The starting y tick
y2 - The ending y tick
spacing - Number of pixels between each tick

yTicks

public void yTicks(int n)
Draws n evenly spaced ticks on the y axis for the full range of the y axis

Parameters:
n - Number of ticks to be drawn