JLogView_.datastructs
Class LGGraph

java.lang.Object
  extended by JLogView_.datastructs.LGGraph

public class LGGraph
extends java.lang.Object

LGGraph is a class representing the data structure of a graph. It contains a set of columns, all the columns being used in all different plots. It can contains any number of plots, any number of shapes and any numer of annotations. labels to be used for axis are also stored here.


Constructor Summary
LGGraph(java.lang.String n, int ncol, int nplots, int scaletype)
          This is the constructor for LGGraph.
 
Method Summary
 void addAnnotation(LGAnnotation note)
          This method adds a new annotation to be drawn on this graph
 void addColumn(java.lang.String n)
          This method adds a new column to this graph.
 void addDataInColumn(int index, float data)
          This method returns add the given data into the specified column.
 void addPlot(int x, int y)
          This method adds a new plot definition to this graph.
 void addShape(LGShape shap)
          This method adds a new shape to be drawn on this graph
 void clearAnnotations()
          This method deletes all existing annotations.
 void concatGraph(LGGraph g)
          This method concatenates the given graph with this graph.
 void deleteAnnotation(int delindex)
          This method deletes an existing annotation.
 int[] draw(java.awt.Graphics2D g, int w, int h, LGAxis X, LGAxis Y, boolean useColours, boolean useLineStyles, boolean useSymbols)
          This method the big drawing method.
 LGAnnotation[] getAnnotations()
          This method returns all the existing annotations from this graph.
 LGColumn[] getColumns()
          This method returns all the columns from this graph.
 LGLegend getLegend()
          This method returns the legend for this graph.
 java.lang.String getName()
          This method returns the name of this graph
 java.awt.Color getNameColour()
          This method returns the colour that is to be used to display the name of the graph.
 java.awt.Font getNameFont()
          This method returns the font details that are to be used to display the name of the graph.
 java.lang.String getNameOf(float x, float y)
          This method returns the name of the plot (which is also the y column name) associated with these coordinates.
 float[] getNearestSpot(float X, float Y, float xrad, float yrad)
          This method returns the nearest data point to the given coordinates within the given radii.
 int getNPlot()
          This method returns the number of plots within this graph.
 LGPlot[] getPlots()
          This method returns all the plots definitions from this graph.
 LGShape[] getShapes()
          This method returns all the shape defintions from this graph.
 javax.swing.JLabel getXLabel()
          This method returns the label for the X axis.
 javax.swing.JLabel getYLabel()
          This method returns the label for the Y axis.
 boolean isEmpty()
          This methods performs a safety check to see if the graph is empty.
 boolean isScatterPlot()
          This method tells whether or not this graph behaves as a scatter.
 void setAnnotation(int index, LGAnnotation note)
          This method updates/sets the value of an existing annotation.
 void setAxesRange(LGAxis X, LGAxis Y)
          This method sets the axis range for the physical axis objects.
 void setLegend(LGLegend newlegend)
          This method sets the legend for this graph.
 void setName(java.lang.String newname)
          This method sets the name of this graph
 void setNameColour(java.awt.Color c)
          This method sets the colour that is to be used to display the name of the graph.
 void setNameFont(java.awt.Font f)
          This method sets the font details that are to be used to display the name of the graph.
 void setScaling(float xmin, float xmax, float ymin, float ymax)
          This method sets the scale, or axis ranges to be more precise, for this graph.
 void setScatterPlot(boolean scatter)
          This method tells this graph to behave as a scatter plot or not.
 void setXLabel(javax.swing.JLabel newlabel)
          This method extract the label information for the X axis from the given object.
 void setYLabel(javax.swing.JLabel newlabel)
          This method extract the label information for the Y axis from the given object.
 void switchPlot(int index, boolean onoff)
          This method switches one particular plot on or off.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LGGraph

public LGGraph(java.lang.String n,
               int ncol,
               int nplots,
               int scaletype)
This is the constructor for LGGraph. The necessary parameters are the total number of columns necessary, the total number of plots, the name of the graph and the scaling type being used for the axes.

Parameters:
n - a String representing the graph name
ncol - the number of columns
nplots - the number of plots
scaletype - the type of scaling (0 -> NOUGHT, 1 -> AUTO, 2 -> specified)
Method Detail

addPlot

public void addPlot(int x,
                    int y)
This method adds a new plot definition to this graph.

Parameters:
x - the index of the column to be use for x coordinate
y - the index of the column to be use for y coordinate

setScatterPlot

public void setScatterPlot(boolean scatter)
This method tells this graph to behave as a scatter plot or not. This means whether or not to draw only data points from each plot.

Parameters:
scatter - a boolean, true -> only draw data points, false -> draw data points and lines

isScatterPlot

public boolean isScatterPlot()
This method tells whether or not this graph behaves as a scatter. This means whether or not it draws only data points from each plot.

Returns:
a boolean, true -> only draw data points, false -> draw data points and lines

getNPlot

public int getNPlot()
This method returns the number of plots within this graph.

Returns:
the number of plots

isEmpty

public boolean isEmpty()
This methods performs a safety check to see if the graph is empty.

Returns:
true -> no data in graph, false-> no problem

switchPlot

public void switchPlot(int index,
                       boolean onoff)
This method switches one particular plot on or off. This mean making this plot being drawn or not

Parameters:
index - the index of the plot (starting from 0)
onoff - a boolean, true -> draw the plot, false -> skip it

addColumn

public void addColumn(java.lang.String n)
This method adds a new column to this graph.

Parameters:
n - a String representing the column name
See Also:
String

addShape

public void addShape(LGShape shap)
This method adds a new shape to be drawn on this graph

Parameters:
shap - an LGShape object representing the shape to be drawn
See Also:
LGShape

addAnnotation

public void addAnnotation(LGAnnotation note)
This method adds a new annotation to be drawn on this graph

Parameters:
note - an LGAnnotation object representing the annotation to be drawn
See Also:
LGAnnotation

setAnnotation

public void setAnnotation(int index,
                          LGAnnotation note)
This method updates/sets the value of an existing annotation. It uses an index telling which position in the list of annotations the one to be updated/set is.

Parameters:
index - the index of the annotation in the list of annotation (starting from 0)
note - an LGAnnotation object representing the annotation to be drawn
See Also:
LGAnnotation

deleteAnnotation

public void deleteAnnotation(int delindex)
This method deletes an existing annotation. It uses an index telling which position in the list of annotations the one deleted is.

Parameters:
delindex - the index of the annotation in the list of annotation (starting from 0)

getAnnotations

public LGAnnotation[] getAnnotations()
This method returns all the existing annotations from this graph.

Returns:
an array of LGAnnotation object representing all the annotations
See Also:
LGAnnotation

clearAnnotations

public void clearAnnotations()
This method deletes all existing annotations.


getNearestSpot

public float[] getNearestSpot(float X,
                              float Y,
                              float xrad,
                              float yrad)
This method returns the nearest data point to the given coordinates within the given radii. If no data point is found, return value will be null.

Parameters:
X - the x coordinate of the point we are searching from
Y - the y coordinate of the point we are searching from
xrad - the radius along the x axis within we are accepting data points
yrad - the radius along the y axis within we are accepting data points
Returns:
an array float giving the coordinates of the nearest data point or null

getNameOf

public java.lang.String getNameOf(float x,
                                  float y)
This method returns the name of the plot (which is also the y column name) associated with these coordinates.

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point
Returns:
a String object representing the name of the column
See Also:
String

addDataInColumn

public void addDataInColumn(int index,
                            float data)
This method returns add the given data into the specified column.

Parameters:
index - the column index (starting from 0)
data - the data value

getColumns

public LGColumn[] getColumns()
This method returns all the columns from this graph.

Returns:
an array of LGColumn object representing each of the columns
See Also:
LGColumn

getPlots

public LGPlot[] getPlots()
This method returns all the plots definitions from this graph.

Returns:
an array of LGPlot object representing each of the plots
See Also:
LGPlot

getShapes

public LGShape[] getShapes()
This method returns all the shape defintions from this graph.

Returns:
an array of LGShape object representing each of the shapes
See Also:
LGShape

getName

public java.lang.String getName()
This method returns the name of this graph

Returns:
a String representing the name of this graph
See Also:
String

getNameFont

public java.awt.Font getNameFont()
This method returns the font details that are to be used to display the name of the graph.

Returns:
a Font object containing the font details (face+style+size)
See Also:
Font

getNameColour

public java.awt.Color getNameColour()
This method returns the colour that is to be used to display the name of the graph.

Returns:
a Color object represeting the colour for the name
See Also:
Color

setName

public void setName(java.lang.String newname)
This method sets the name of this graph

Parameters:
newname - a String representing the name of this graph
See Also:
String

setNameFont

public void setNameFont(java.awt.Font f)
This method sets the font details that are to be used to display the name of the graph.

Parameters:
f - a Font object containing the font details (face+style+size)
See Also:
Font

setNameColour

public void setNameColour(java.awt.Color c)
This method sets the colour that is to be used to display the name of the graph.

Parameters:
c - a Color object represeting the colour for the name
See Also:
Color

concatGraph

public void concatGraph(LGGraph g)
This method concatenates the given graph with this graph. This includes shifting the column indexes in the second graph by the number of column from this graph.

Parameters:
g - the LGGraph object to be concatenated with this graph
See Also:
LGGraph

setScaling

public void setScaling(float xmin,
                       float xmax,
                       float ymin,
                       float ymax)
This method sets the scale, or axis ranges to be more precise, for this graph.

Parameters:
xmin - the minimum value for the x axis
xmax - the maximum value for the x axis
ymin - the minimum value for the y axis
ymax - the maximum value for the y axis

setAxesRange

public void setAxesRange(LGAxis X,
                         LGAxis Y)
This method sets the axis range for the physical axis objects.

Parameters:
X - the LGAxis object representing the x axis
Y - the LGAxis object representing the y axis
See Also:
LGAxis

getXLabel

public javax.swing.JLabel getXLabel()
This method returns the label for the X axis. It also gives the details for font and colour thanks to the JLabel object.

Returns:
a JLabel object containing the text, font details and colour for the label
See Also:
JLabel

getYLabel

public javax.swing.JLabel getYLabel()
This method returns the label for the Y axis. It also gives the details for font and colour thanks to the JLabel object.

Returns:
a JLabel object containing the text, font details and colour for the label
See Also:
JLabel

setYLabel

public void setYLabel(javax.swing.JLabel newlabel)
This method extract the label information for the Y axis from the given object. This mean getting the text of the label, the font details and the colour.

Parameters:
newlabel - a JLabel object containing the text, font details and colour for the label
See Also:
JLabel

setXLabel

public void setXLabel(javax.swing.JLabel newlabel)
This method extract the label information for the X axis from the given object. This mean getting the text of the label, the font details and the colour.

Parameters:
newlabel - a JLabel object containing the text, font details and colour for the label
See Also:
JLabel

draw

public int[] draw(java.awt.Graphics2D g,
                  int w,
                  int h,
                  LGAxis X,
                  LGAxis Y,
                  boolean useColours,
                  boolean useLineStyles,
                  boolean useSymbols)
This method the big drawing method. It is big because it has to deal with all scaling from real world to canvas coordinates. It has to find out whether plots were personalised or not, have to pick up the user current drawing preferences and apply them.

One important trick to know here, we are drawing considering the y axis of the canvas as going upwards (it actually goes downwards). This makes things more intuitive. The whole thing gets flipped back by the canvas widget so no worries here.

it also returns the canvas coordinates of the quadrant in which the least number of data points were draw (helps find out the best start point for legend).

Parameters:
g - the graphics context on which we are drawing
w - the width of the canvas in pixels
h - the height of the canvas in pixels
X - an LGAxis object representing the x axis
Y - an LGAxis object representing the y axis
useColours - a boolean, true -> use colours, false -> black
useLineStyles - a boolean, true -> use line styles, false -> plain line
useSymbols - a boolean, true -> use symbols, false -> use discs only
See Also:
LGAxis, Graphics2D

setLegend

public void setLegend(LGLegend newlegend)
This method sets the legend for this graph. This is mainly used for updates made from the main interface. Any change of item name in the legend will be propagated to the corresponding column for consistency.

Parameters:
newlegend - the LGLegend object representing the legend for this graph
See Also:
LGLegend

getLegend

public LGLegend getLegend()
This method returns the legend for this graph. This is mainly used for drawing it from the canvas and loading its details into the editing window.

Returns:
the LGLegend object representing the legend for this graph
See Also:
LGLegend