org.ibisph.charts
Class AbstractChart

java.lang.Object
  extended by org.ibisph.charts.AbstractChart
All Implemented Interfaces:
java.io.Serializable, Chart
Direct Known Subclasses:
AbstractSharedChart, Area, Pie, StackedArea

public abstract class AbstractChart
extends java.lang.Object
implements Chart, java.io.Serializable

Core chart object that provides the common Chart methods. This also contains helper methods and core functionality used by all IBISPH chart objects. The specific sub classed chart objects then implement the chart specific AgileBlox objects along with chart specific setter methods and chart adjustment code.

Author:
Garth Braithwaite, STG
See Also:
Serialized Form

Field Summary
protected  java.lang.String acxmlPathAndFilename
           
protected  double defaultChartHeight
           
protected  double defaultXAxisLabelDistance
           
protected  double defaultYAxisLabelDistance
           
protected  double labelCharacterWidth
           
protected  double legendSymbolWidth
           
protected  double maxLegendWidth
           
protected  double maxXAxisLabelWidth
           
protected  double maxYAxisLabelWidth
           
protected  double minLegendWidth
           
 
Constructor Summary
AbstractChart(java.lang.String acxmlPathAndFilename)
          Simple constructor which simply sets ACXML file property.
 
Method Summary
protected  void adjustLegendSize(com.elan.wclibrary.svg.BaseChart baseChart, java.lang.String[] legendTitles)
          Adjust chart's legend size based on the titles and the legend size properties.
protected  void adjustXAxisLabelHeight(com.elan.wclibrary.svg.BaseChart baseChart, java.lang.String[] categoryTitles)
          Modifies x axis category label titles.
protected  void adjustXAxisLabelHeight(com.elan.wclibrary.svg.BaseChart baseChart, java.lang.String[] labels, double xAxisLabelTitleDistance)
          Modifies x axis category label titles.
protected  void adjustYAxisLabelWidthAndSetScale(com.elan.wclibrary.svg.BaseChart baseChart, double maxValue)
           
protected  void adjustYAxisLabelWidthAndSetScale(com.elan.wclibrary.svg.BaseChart baseChart, double maxValue, double labelDistance)
          Modifies y axis value titles.
 void generate(javax.servlet.http.HttpServletRequest request, ChartData chartData, java.lang.String chartHeight, boolean showConfidenceLimits, boolean zipOutput, java.io.OutputStream outputStream)
          Uses the supplied chart data, existing property settings, and chart specific adjustment methods to generate an SVG output stream.
protected abstract  com.elan.wclibrary.svg.BaseChart getBaseChart(java.lang.String chartTitle, java.lang.String seriesAxisTitle, java.lang.String[] seriesTitles, java.lang.String categoryAxisTitle, java.lang.String[] categoryTitles, java.lang.String[][] values, java.lang.String[][] lowerLimits, java.lang.String[][] upperLimits, java.lang.String[][] toolTips, double maxValue, boolean showConfidenceLimits)
          Sets the chart's data values, adjusts chart's layout based on the control properties, and returns the chart instance.
protected  double getMaxCategorySum(java.lang.String[][] valueArray)
          Sums according to the category to determines the maximum value.
protected  double getMaxSeriesSum(java.lang.String[][] valueArray)
          Sums the series to determines the maximum value.
protected  int numberOfLines(int charsPerLine, int totalChars)
          Calculates number of lines so that the label and title spacing can be set.
protected  void setChartHeight(com.elan.wclibrary.svg.BaseChart baseChart, java.lang.String chartHeight)
          Validates height range and sets the chart's height.
 void setDefaultChartHeight(double defaultChartHeight)
          Sets the default height property of the entire chart (including legends, titles, labels).
 void setDefaultXAxisLabelDistance(double defaultXAxisLabelDistance)
          Sets x axis label distance property.
 void setDefaultYAxisLabelDistance(double defaultYAxisLabelDistance)
          Sets y axis label distance property.
 void setLabelCharacterWidth(double labelCharacterWidth)
          Sets average character width, in pixels, used when guessing/determining the screen width of the string.
 void setLegendSymbolWidth(double legendSymbolWidth)
          Sets this chart's legend symbol width property.
 void setMaxLegendWidth(double maxLegendWidth)
          Sets maximum allowable width property for this chart's legend.
 void setMaxXAxisLabelWidth(double maxXAxisLabelWidth)
          Sets maximum allowable width property for this chart's X Axis Labels.
 void setMaxYAxisLabelWidth(double maxYAxisLabelWidth)
          Sets maximum allowable width property for this chart's Y Axis Labels.
 void setMinLegendWidth(double minLegendWidth)
          Sets minimum allowable width property for this chart's legend.
protected  void setTitle(com.elan.wclibrary.svg.BaseChart baseChart, java.lang.String title)
          Sets the main chart header title, escapes ' and " characters, and sets the header height.
protected  double toDouble(java.lang.String value)
          Converts the string to double.
protected  double[][] toNullToZeroDoubleArray(java.lang.String[][] stringValueArray)
          Converts String array values to a double value array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minLegendWidth

protected double minLegendWidth

maxLegendWidth

protected double maxLegendWidth

maxYAxisLabelWidth

protected double maxYAxisLabelWidth

maxXAxisLabelWidth

protected double maxXAxisLabelWidth

legendSymbolWidth

protected double legendSymbolWidth

labelCharacterWidth

protected double labelCharacterWidth

defaultYAxisLabelDistance

protected double defaultYAxisLabelDistance

defaultXAxisLabelDistance

protected double defaultXAxisLabelDistance

defaultChartHeight

protected double defaultChartHeight

acxmlPathAndFilename

protected java.lang.String acxmlPathAndFilename
Constructor Detail

AbstractChart

public AbstractChart(java.lang.String acxmlPathAndFilename)
Simple constructor which simply sets ACXML file property. This property file is latter used when creating the actual AgileBlox chart object.

Parameters:
acxmlPathAndFilename - complete filename with path of the ACXML properties file.
Method Detail

setMinLegendWidth

public void setMinLegendWidth(double minLegendWidth)
Sets minimum allowable width property for this chart's legend. This value is referenced when building the chart's layout. If the legend titles are small then the legend is shrunk to allow more area to be displayed by the chart. This value controls the minimum amount that the legend can be downsized to. This property is kept as a class variable so it is typically only set once when the object is first created.

Specified by:
setMinLegendWidth in interface Chart
Parameters:
minLegendWidth - minimum legend width in pixels.

setMaxLegendWidth

public void setMaxLegendWidth(double maxLegendWidth)
Sets maximum allowable width property for this chart's legend. This value is referenced when building the chart's layout. If the legend titles are large then the legend is expanded to allow more legend area to be displayed to show the longer legend titles. This value controls the maximum amount of pixels that the legend can be increased to. This property is kept as a class variable so it is typically only set once when the object is first created.

Specified by:
setMaxLegendWidth in interface Chart
Parameters:
maxLegendWidth - maximum legend width in pixels.

setMaxYAxisLabelWidth

public void setMaxYAxisLabelWidth(double maxYAxisLabelWidth)
Sets maximum allowable width property for this chart's Y Axis Labels. This value is referenced when building the chart's layout. If the Y Axis item labels/titles are large then the label distance and the max label size is used to control the maximum space/width of the axis label. This property is kept as a class variable so it is typically only set once when the object is first created.

Specified by:
setMaxYAxisLabelWidth in interface Chart
Parameters:
maxYAxisLabelWidth - maximum Y Axis Label width in pixels.

setMaxXAxisLabelWidth

public void setMaxXAxisLabelWidth(double maxXAxisLabelWidth)
Sets maximum allowable width property for this chart's X Axis Labels. This value is referenced when building the chart's layout. If the X Axis item labels/titles are large and will not fit the alloted size the label will be rotated x degrees based on the number of axis label items and length. This property is kept as a class variable so it is typically only set once when the object is first created.

Specified by:
setMaxXAxisLabelWidth in interface Chart
Parameters:
maxXAxisLabelWidth - maximum X Axis Label width in pixels.

setLegendSymbolWidth

public void setLegendSymbolWidth(double legendSymbolWidth)
Sets this chart's legend symbol width property.

Specified by:
setLegendSymbolWidth in interface Chart
Parameters:
legendSymbolWidth - width of the legend icon (typically a circle) in pixels.

setLabelCharacterWidth

public void setLabelCharacterWidth(double labelCharacterWidth)
Sets average character width, in pixels, used when guessing/determining the screen width of the string.

Specified by:
setLabelCharacterWidth in interface Chart
Parameters:
labelCharacterWidth - Average width in pixels of a character.

setDefaultYAxisLabelDistance

public void setDefaultYAxisLabelDistance(double defaultYAxisLabelDistance)
Sets y axis label distance property. This value controls where the y axis labels will be displayed with respect to the chart canvas and is defined as the number of pixels from the left edge of the chart.

Specified by:
setDefaultYAxisLabelDistance in interface Chart
Parameters:
defaultYAxisLabelDistance - Number of pixels to the left of the chart on where to start the y axis labels.

setDefaultXAxisLabelDistance

public void setDefaultXAxisLabelDistance(double defaultXAxisLabelDistance)
Sets x axis label distance property. This value controls where the x axis labels will be displayed and is defined as the number of pixels from the bottom edge of the chart.

Specified by:
setDefaultXAxisLabelDistance in interface Chart
Parameters:
defaultXAxisLabelDistance - Number of pixels from the bottom of the chart on where to start the x axis labels.

setDefaultChartHeight

public void setDefaultChartHeight(double defaultChartHeight)
Sets the default height property of the entire chart (including legends, titles, labels). The chart height is sometimes changed at chart generation time depending on the number of series and categories etc. This value specifies the standard/default/minimum height.

Specified by:
setDefaultChartHeight in interface Chart
Parameters:
defaultChartHeight - height of the chart in pixels.

generate

public void generate(javax.servlet.http.HttpServletRequest request,
                     ChartData chartData,
                     java.lang.String chartHeight,
                     boolean showConfidenceLimits,
                     boolean zipOutput,
                     java.io.OutputStream outputStream)
Uses the supplied chart data, existing property settings, and chart specific adjustment methods to generate an SVG output stream. This is the main method used to generate the chart. It calls the required, chart specific getBaseChart method which loads the data and does most of the chart adjustments, then sets the chart height and zip property, calls the AgileBlox buildSVG method, and finally generates the chart and streams the results back to the specified output stream.

IMPORTANT NOTE: Sub classes must deal with the AgileBlox charts objects which are NOT thread safe!

Specified by:
generate in interface Chart
Parameters:
request - HttpServletRequest needed by the Agileblox chart object.
chartData - Contains chart data typically loaded by a DAO.
showConfidenceLimits - Controls displaying confidence intervals. If true the confidence limits will always be visible. If false then the limits are only shown to the user when they mouse over the value or they mouse over the series title in the legend.
zipOutput - Controls compressed output. true = compress the output using gzip. false = no compression. As of 10/2005, this feature is not used. The biggest reason that the output should NOT be zipped for IBIS is that the jpeg conversion needs raw SVG text. To do SVG compression, a compression servlet filter was developed.
outputStream - destination where chart data is sent.
chartHeight - controls how tall/high the chart will be (in pixels).

getBaseChart

protected abstract com.elan.wclibrary.svg.BaseChart getBaseChart(java.lang.String chartTitle,
                                                                 java.lang.String seriesAxisTitle,
                                                                 java.lang.String[] seriesTitles,
                                                                 java.lang.String categoryAxisTitle,
                                                                 java.lang.String[] categoryTitles,
                                                                 java.lang.String[][] values,
                                                                 java.lang.String[][] lowerLimits,
                                                                 java.lang.String[][] upperLimits,
                                                                 java.lang.String[][] toolTips,
                                                                 double maxValue,
                                                                 boolean showConfidenceLimits)
Sets the chart's data values, adjusts chart's layout based on the control properties, and returns the chart instance. This is the chart specific core method that needs to be implemented for each type of chart. This method can share a single instance or create a new instance of the chart each time. This behavior was changed 11/2005 because some of the AgileBlox chart objects were not behaving well. Some chart objects could be reused (for speed) and others would get messed after being used for a while so they were instantiated upon each use.

Parameters:
chartTitle - Main title that is to be displayed on the top of the chart.
seriesAxisTitle - Title to be shown on typically the Y axis which is associated with the series. This axis title usually describes the type of "values" that the data is e.g. "Population Count", "Percentage of Adults" etc.
seriesTitles - Array of strings that is the title/description for each data series. These series title values are displayed in the legend.
categoryAxisTitle - Title to be shown on typically the X axis which is associated with the categoy values. This axis title usually describes what the categories are. Examples are "Year" or "County" etc.
categoryTitles - Array that contains the title for each different data category. These values are typically displayed as labels for each interval on the axis. For the above example these titles would be "1995", "1996", ... "2005" or "Beaver", "Box Elder", ... "Weber".
values - 2-d array that contains the actual data values to be displayed/plotted on the chart. These are string values so that null missing values will be handled (e.g. not shown) on the chart. If the double method is used, then missing values are counted as 0.0 and the chart is not correct. The first array index is the series with the second corresponding to the category.
lowerLimits - Similar to the values array but contains the lower confidence limit (if any) associated with the value[series][category].
upperLimits - Similar to the values array but contains the upper confidence limit (if any) associated with the value[series][category].
toolTips - Contains any special label type values to be shown to the user when the data value is moused over.
maxValue - Maximum data value which is used to control the chart's value scaling.
showConfidenceLimits - flag to control how to displaying the confidence intervals. if true the confidence limits will always be displayed. If false then the limits are only shown to the user when they mouse over the value or they mouse over the series title in the legend.
Returns:
Agileblox base chart.

setTitle

protected void setTitle(com.elan.wclibrary.svg.BaseChart baseChart,
                        java.lang.String title)
Sets the main chart header title, escapes ' and " characters, and sets the header height. Any ' and/or " characters need to be escaped for the Agileblox javascript that handles wrapping the title. This method also adjusts the chart's header height based on the size of the title string.

Parameters:
baseChart - chart to be modified.
title - Sets the baseChart's Header Title (main title of the chart).

setChartHeight

protected void setChartHeight(com.elan.wclibrary.svg.BaseChart baseChart,
                              java.lang.String chartHeight)
Validates height range and sets the chart's height.

Parameters:
baseChart - chart to be modified.
chartHeight - String which contains a numerical value in pixels. This value is not an int or double as the Agileblox object accepts a String and the value is typically set on the URL via the XSLT which builds the page's code (comes in from the chart data).

adjustLegendSize

protected void adjustLegendSize(com.elan.wclibrary.svg.BaseChart baseChart,
                                java.lang.String[] legendTitles)
Adjust chart's legend size based on the titles and the legend size properties. The legend titles array needs to be passed because the Agileblox chart object does not have a getLegendTitles method. The width adjustment is the most critcal and is based on the max title length. The height is based on the number of title elements.

Parameters:
baseChart - chart to be modified.
legendTitles - Array of titles to be displayed within the legend.

adjustYAxisLabelWidthAndSetScale

protected void adjustYAxisLabelWidthAndSetScale(com.elan.wclibrary.svg.BaseChart baseChart,
                                                double maxValue,
                                                double labelDistance)
Modifies y axis value titles. This should be called after data values are set and before the x axis width is calculated. Also, this method is not as accurate since agileblox decides how to format the value labels. The best guess is to use the values maximum number of significant digits but it's only a guide. See the xaxis comments below for how these distances work.

Parameters:
baseChart - chart to be modified.
maxValue - Greatest value of the data that is used to determine the number of significant digits so that the y axis value size can be adjusted correctly.
labelDistance - Additional padding size in pixels to be used for the y axis labels.

adjustYAxisLabelWidthAndSetScale

protected void adjustYAxisLabelWidthAndSetScale(com.elan.wclibrary.svg.BaseChart baseChart,
                                                double maxValue)

adjustXAxisLabelHeight

protected void adjustXAxisLabelHeight(com.elan.wclibrary.svg.BaseChart baseChart,
                                      java.lang.String[] labels,
                                      double xAxisLabelTitleDistance)
Modifies x axis category label titles. This should be called after the data values are set.

Parameters:
baseChart - chart to be modified.
labels - Array of x axis category titles.
xAxisLabelTitleDistance - Absolute value the x axis title is placed away from the center of the category labels. Valid values are 1 to basically chart height. Agileblox doesn't adjust for the category size and angle but they do take into account (set the chart area) according to the x axis label distance setting. This is a kludge which is used to set the area needed to hold the category labels.

adjustXAxisLabelHeight

protected void adjustXAxisLabelHeight(com.elan.wclibrary.svg.BaseChart baseChart,
                                      java.lang.String[] categoryTitles)
Modifies x axis category label titles. Overloaded method which uses the defaultXAxisLabelDistance property.

Parameters:
baseChart - chart to be modified.
categoryTitles - Array of x axis category titles.

numberOfLines

protected int numberOfLines(int charsPerLine,
                            int totalChars)
Calculates number of lines so that the label and title spacing can be set.

Parameters:
charsPerLine - sets the number of characters that define a single line.
totalChars - Size of the string - length.
Returns:
total number of lines based on the total characters divided by the characters per line.

toDouble

protected double toDouble(java.lang.String value)
Converts the string to double.

Parameters:
value - String to be parsed/converted to a double.
Returns:
Converted value of string to a double. If there's a problem it will try and remove the $%, characters incase the values come in formatted. If it still can't convert then a null is returned so that the Agileblox null string value will be used.

getMaxSeriesSum

protected double getMaxSeriesSum(java.lang.String[][] valueArray)
Sums the series to determines the maximum value. Used by stacked area and bar charts to determine the maximum summed value based on the series (2nd dimension of the array). This value is then used to determine the value label size axis adjustment.

Parameters:
valueArray - series and category values to be looped summed and checked.
Returns:
largest summation of all category values for a series.

getMaxCategorySum

protected double getMaxCategorySum(java.lang.String[][] valueArray)
Sums according to the category to determines the maximum value. Determines the maximum summed value based on the category (1st dimension of the array). This value is used to determine the value label size axis adjustment.

Parameters:
valueArray - series and category values to be looped summed and checked.
Returns:
largest summation of all category values for a series.

toNullToZeroDoubleArray

protected double[][] toNullToZeroDoubleArray(java.lang.String[][] stringValueArray)
Converts String array values to a double value array. If a value is null, it is set to 0 for Agileblox stacked area and stacked bar charts which can not handle null values.

Parameters:
stringValueArray - String values to be converted to a double value.
Returns:
converted string values to double. If String value is null a zero is returned.