com.sun.slamd.stat
Class StatGrapher

java.lang.Object
  extended bycom.sun.slamd.stat.StatGrapher

public class StatGrapher
extends java.lang.Object

This class provides a mechanism for generating graphs based on sets of data obtained during job processing. Note that a maximum of 30 data sets can be represented on a single graph.


Field Summary
static java.awt.Color[] COLORS
          The set of colors that will be used when producing the graphs.
 
Constructor Summary
StatGrapher(int width, int height, java.lang.String graphTitle)
          Creates a new stat grapher with the specified information.
 
Method Summary
 void addDataSet(double[] dataValues, int collectionInterval, java.lang.String dataSetLabel)
          Adds the specified data to the set of information that will be graphed.
 void addStackedBarGraphDataSet(java.lang.String dataSetName, java.lang.String[] categoryNames, double[] categoryAverages)
          Adds the specified data for use in generating a stacked bar graph.
 double chooseVerticalLabelIncrement(int numVerticalLabels)
          This method attempts to determine an appropriate increment between labels on the vertical axis.
 double chooseVerticalLabelIncrement(int numVerticalLabels, double graphSpan)
          This method attempts to determine an appropriate increment between labels on the vertical axis.
 java.awt.image.BufferedImage generateBarGraph()
          Generates a bar graph based on the information that has been provided.
 java.awt.image.BufferedImage generateDualLineGraph(java.lang.String label1, java.lang.String caption1, double[] values1, int interval1, java.lang.String label2, java.lang.String caption2, double[] values2, int interval2, boolean useSameAxis, java.lang.String horizontalAxisCaption, java.lang.String[] jobIDs)
          Generates a line graph that can be used to overlay data for two different statistics.
 java.awt.image.BufferedImage generateLineGraph()
          Generates a line graph based on the information that has been provided.
 java.awt.image.BufferedImage generatePieGraph(java.lang.String[] categoryNames, int[] occurrencesPerCategory)
          Generates a pie graph based on the information that has been provided.
 java.awt.image.BufferedImage generateStackedAreaGraph()
          Generates a stacked area graph based on the information that has been provided.
 java.awt.image.BufferedImage generateStackedBarGraph()
          Generates a stacked bar graph based on the information that has been provided.
 java.awt.image.BufferedImage generateXYLineGraph(double[][] xValues, double[][] yValues, java.lang.String[] labels, boolean drawPoints, boolean baseXAtZero)
          Generates a line graph by plotting the provided data and connecting those points with lines.
 int graphXToValueX(int graphX)
          Converts the provided X coordinate to the value along the horizontal axis to which it corresponds.
 double graphYToValueY(int graphY)
          Converts the provided Y coordinate to the value along the vertical axis to which it corresponds.
 double graphYToValueY(int graphY, double graphMin, double graphSpan)
          Converts the provided Y coordinate to the value along the specific vertical axis to which it corresponds.
 void setBaseAtZero(boolean baseAtZero)
          Indicates whether the lower bound of the graph should be at zero or should be dynamically calculated based on information in the data set.
 void setFlatBetweenPoints(boolean flatBetweenPoints)
          Indicates whether line graphs should have a flat horizontal line followed by a vertical line between data points, or if the points should be directly connected.
 void setHorizontalAxisTitle(java.lang.String horizontalAxisTitle)
          Specifies the title to be used for the horizontal axis of the generated graph.
 void setIgnoreZeroValues(boolean ignoreZeroValues)
          Indicates whether the graph should ignore data intervals where the value for that interval is zero.
 void setIncludeAverage(boolean includeAverage)
          Indicates whether the graph should include a line that indicates the average of all values provided.
 void setIncludeHorizontalGrid(boolean includeHorizontalGrid)
          Indicates whether the generated graph should include horizontal grid lines.
 void setIncludeLegend(boolean includeLegend, java.lang.String legendTitle)
          Indicates whether the generated graph should include a legend.
 void setIncludeRegression(boolean includeRegression)
          Indicates whether the graph should include a trend line based on a linear regression calculation of all the values.
 void setIncludeVerticalGrid(boolean includeVerticalGrid)
          Indicates whether the generated graph should include horizontal grid lines.
 void setShowPercentages(boolean showPercentages)
          Indicates whether the generated pie graph should show the percentages for each category.
 void setStartSeconds(int startSeconds)
          Specifies the number of seconds into the test that the graph starts.
 void setVerticalAxisTitle(java.lang.String verticalAxisTitle)
          Specifies the title to be used for the verticial axis of the generated graph.
 int valueXToGraphX(double xValue, double xMax)
          Converts the provided value along the horizontal axis to an X coordinate in the graph image.
 int valueXToGraphX(int valueX)
          Converts the provided value along the horizontal axis to an X coordinate in the graph image.
 int valueYToGraphY(double valueY)
          Converts the provided value along the vertical axis to a Y oordinate in the graph image.
 int valueYToGraphY(double valueY, double graphMin, double graphSpan)
          Converts the provided value along the vertical axis to a Y oordinate in the graph image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLORS

public static final java.awt.Color[] COLORS
The set of colors that will be used when producing the graphs.

Constructor Detail

StatGrapher

public StatGrapher(int width,
                   int height,
                   java.lang.String graphTitle)
Creates a new stat grapher with the specified information.

Parameters:
width - The width of the drawable area to create.
height - The height of the drawable area to create.
graphTitle - The caption to include at the top of the graph.
Method Detail

addDataSet

public void addDataSet(double[] dataValues,
                       int collectionInterval,
                       java.lang.String dataSetLabel)
Adds the specified data to the set of information that will be graphed.

Parameters:
dataValues - The of data to include in the set of information that will be graphed.
collectionInterval - The collection interval associated with this data set.
dataSetLabel - The label to use for this data set in the legend.

addStackedBarGraphDataSet

public void addStackedBarGraphDataSet(java.lang.String dataSetName,
                                      java.lang.String[] categoryNames,
                                      double[] categoryAverages)
Adds the specified data for use in generating a stacked bar graph.

Parameters:
dataSetName - The overall name of the data set.
categoryNames - The names of the categories in the data set.
categoryAverages - The average values for each category of the data set.

setFlatBetweenPoints

public void setFlatBetweenPoints(boolean flatBetweenPoints)
Indicates whether line graphs should have a flat horizontal line followed by a vertical line between data points, or if the points should be directly connected.

Parameters:
flatBetweenPoints - Indicates whether line graphs should have a flat horizontal line followed by a vertical line between data points.

setIgnoreZeroValues

public void setIgnoreZeroValues(boolean ignoreZeroValues)
Indicates whether the graph should ignore data intervals where the value for that interval is zero. Note that if this is to be used, it should be set before any calls to addDataSet are made.

Parameters:
ignoreZeroValues - Indicates whether the graph should ignore data intervals where the value for that interval is zero.

setIncludeAverage

public void setIncludeAverage(boolean includeAverage)
Indicates whether the graph should include a line that indicates the average of all values provided.

Parameters:
includeAverage - Indicates whether the graph should include a line that indicates the average of all values provided.

setIncludeRegression

public void setIncludeRegression(boolean includeRegression)
Indicates whether the graph should include a trend line based on a linear regression calculation of all the values.

Parameters:
includeRegression - Indicates whether the graph should include a regression line.

setBaseAtZero

public void setBaseAtZero(boolean baseAtZero)
Indicates whether the lower bound of the graph should be at zero or should be dynamically calculated based on information in the data set.

Parameters:
baseAtZero - Indicates whether the lower bound of the graph should be at zero or should be dynamically calculated based on information in the data set.

setIncludeLegend

public void setIncludeLegend(boolean includeLegend,
                             java.lang.String legendTitle)
Indicates whether the generated graph should include a legend.

Parameters:
includeLegend - Indicates whether the generated graph should include a legend.
legendTitle - The title to use for the legend if it is included.

setIncludeHorizontalGrid

public void setIncludeHorizontalGrid(boolean includeHorizontalGrid)
Indicates whether the generated graph should include horizontal grid lines.

Parameters:
includeHorizontalGrid - Indicates whether the generated graph should include horizontal grid lines.

setIncludeVerticalGrid

public void setIncludeVerticalGrid(boolean includeVerticalGrid)
Indicates whether the generated graph should include horizontal grid lines.

Parameters:
includeVerticalGrid - Indicates whether the generated graph should include vertical grid lines.

setShowPercentages

public void setShowPercentages(boolean showPercentages)
Indicates whether the generated pie graph should show the percentages for each category.

Parameters:
showPercentages - Indicates whether the generated pie graph should show the percentages for each category.

setHorizontalAxisTitle

public void setHorizontalAxisTitle(java.lang.String horizontalAxisTitle)
Specifies the title to be used for the horizontal axis of the generated graph.

Parameters:
horizontalAxisTitle - The title to be used for the horizontal axis of the generated graph.

setVerticalAxisTitle

public void setVerticalAxisTitle(java.lang.String verticalAxisTitle)
Specifies the title to be used for the verticial axis of the generated graph.

Parameters:
verticalAxisTitle - The title to be used for the vertical axis of the generated graph.

setStartSeconds

public void setStartSeconds(int startSeconds)
Specifies the number of seconds into the test that the graph starts.

Parameters:
startSeconds - The number of seconds into the test that the graph starts.

generatePieGraph

public java.awt.image.BufferedImage generatePieGraph(java.lang.String[] categoryNames,
                                                     int[] occurrencesPerCategory)
Generates a pie graph based on the information that has been provided.

Parameters:
categoryNames - The names of the categories of each of the elements.
occurrencesPerCategory - The number of occurrences of the tracked event in each category.
Returns:
A buffered image containing the generated pie graph.

generateLineGraph

public java.awt.image.BufferedImage generateLineGraph()
Generates a line graph based on the information that has been provided.

Returns:
A buffered image containig the generated line graph.

generateXYLineGraph

public java.awt.image.BufferedImage generateXYLineGraph(double[][] xValues,
                                                        double[][] yValues,
                                                        java.lang.String[] labels,
                                                        boolean drawPoints,
                                                        boolean baseXAtZero)
Generates a line graph by plotting the provided data and connecting those points with lines.

Parameters:
xValues - The sets of x coordinates for the data to graph.
yValues - The sets of y coordinates for the data to graph.
labels - The labels to use in the legend.
baseXAtZero - Indicates whether to start the x coordinates at zero or the first x coordinate.
Returns:
A buffered image containig the generated line graph.

generateStackedAreaGraph

public java.awt.image.BufferedImage generateStackedAreaGraph()
Generates a stacked area graph based on the information that has been provided. Note that all data points provided must have exactly the same number of elements.

Returns:
A buffered image containig the generated stacked area graph.

generateDualLineGraph

public java.awt.image.BufferedImage generateDualLineGraph(java.lang.String label1,
                                                          java.lang.String caption1,
                                                          double[] values1,
                                                          int interval1,
                                                          java.lang.String label2,
                                                          java.lang.String caption2,
                                                          double[] values2,
                                                          int interval2,
                                                          boolean useSameAxis,
                                                          java.lang.String horizontalAxisCaption,
                                                          java.lang.String[] jobIDs)
Generates a line graph that can be used to overlay data for two different statistics. The left X axis will be used for the first statistic and the right X axis will be used for the second.

Parameters:
label1 - The label for the first statistic.
caption1 - The caption that should be used for the vertical axis for the first statistic.
values1 - The actual data values for the first statistic.
interval1 - The collection interval used when gathering the data for the first statistic.
label2 - The label for the second statistic.
caption2 - The caption that should be used for the vertical axis for the second statistic.
values2 - The actual data values for the second statistic.
interval2 - The collection interval used when gathering the data for the second statistic.
useSameAxis - Indicates whether both statistics should be graphed along the same axis.
horizontalAxisCaption - The caption that should be displayed along the horizontal axis for this graph.
jobIDs - The set of job IDs that correspond to each data point in each value set. This should be null unless each data point represents a different job.
Returns:
A buffered image containig the generated line graph.

generateBarGraph

public java.awt.image.BufferedImage generateBarGraph()
Generates a bar graph based on the information that has been provided.

Returns:
A buffered image containig the generated bar graph.

generateStackedBarGraph

public java.awt.image.BufferedImage generateStackedBarGraph()
Generates a stacked bar graph based on the information that has been provided.

Returns:
A buffered image containig the generated stacked bar graph.

chooseVerticalLabelIncrement

public double chooseVerticalLabelIncrement(int numVerticalLabels)
This method attempts to determine an appropriate increment between labels on the vertical axis. It has a preference for whole numbers if possible.

Parameters:
numVerticalLabels - The maximum number of labels that may be used along the vertical axis. The vertical span of the graph divided by the returned increment may not exceed this value.
Returns:
The increment that should be used between labels on the vertical axis of the generated line graph.

chooseVerticalLabelIncrement

public double chooseVerticalLabelIncrement(int numVerticalLabels,
                                           double graphSpan)
This method attempts to determine an appropriate increment between labels on the vertical axis. It has a preference for whole numbers if possible.

Parameters:
numVerticalLabels - The maximum number of labels that may be used along the vertical axis. The vertical span of the graph divided by the returned increment may not exceed this value.
graphSpan - The span of values covered along the vertical axis.
Returns:
The increment that should be used between labels on the vertical axis of the generated line graph.

graphXToValueX

public int graphXToValueX(int graphX)
Converts the provided X coordinate to the value along the horizontal axis to which it corresponds.

Parameters:
graphX - The X coordinate of the point in the image.
Returns:
The value that corresponds to the provided X coordinate.

valueXToGraphX

public int valueXToGraphX(int valueX)
Converts the provided value along the horizontal axis to an X coordinate in the graph image.

Parameters:
valueX - The value along the horizontal axis for which to retrieve the X coordinate.
Returns:
The X coordinate that corresponds to the specified value.

valueXToGraphX

public int valueXToGraphX(double xValue,
                          double xMax)
Converts the provided value along the horizontal axis to an X coordinate in the graph image.

Parameters:
xValue - The value along the horizontal axis for which to retrieve the X coordinate.
xMax - The maximum x value of any data point to be graphed.
Returns:
The X coordinate that corresponds to the specified value.

graphYToValueY

public double graphYToValueY(int graphY)
Converts the provided Y coordinate to the value along the vertical axis to which it corresponds.

Parameters:
graphY - The Y coordinate of the point in the image.
Returns:
The value that corresponds to the provided Y coordinate.

graphYToValueY

public double graphYToValueY(int graphY,
                             double graphMin,
                             double graphSpan)
Converts the provided Y coordinate to the value along the specific vertical axis to which it corresponds. This is to be used when the left and right vertical axes represent different ranges of values.

Parameters:
graphY - The Y coordinate of the point in the image.
graphMin - The minimum value for the vertical axis.
graphSpan - The span for the vertical axis.
Returns:
The value that corresponds to the provided Y coordinate.

valueYToGraphY

public int valueYToGraphY(double valueY)
Converts the provided value along the vertical axis to a Y oordinate in the graph image.

Parameters:
valueY - The value along the vertical axis for which to retrieve the Y coordinate.
Returns:
The Y coordinate that corresponds to the specified value.

valueYToGraphY

public int valueYToGraphY(double valueY,
                          double graphMin,
                          double graphSpan)
Converts the provided value along the vertical axis to a Y oordinate in the graph image. This is to be used when the left and right vertical axes represent different ranges of values.

Parameters:
valueY - The value along the vertical axis for which to retrieve the Y coordinate.
graphMin - The minimum value for the vertical axis.
graphSpan - The span for the vertical axis.
Returns:
The Y coordinate that corresponds to the specified value.