org.perf4j.chart
Class GoogleChartGenerator

java.lang.Object
  extended by org.perf4j.chart.GoogleChartGenerator
All Implemented Interfaces:
StatisticsChartGenerator

public class GoogleChartGenerator
extends Object
implements StatisticsChartGenerator

This implementation of StatisticsChartGenerator creates a chart URL in the format expected by the Google Chart API.

Author:
Alex Devine
See Also:
Google Chart API

Field Summary
static String DEFAULT_BASE_URL
          The DEFAULT_BASE_URL points to Google's charting server at chart.apis.google.com.
static int DEFAULT_CHART_HEIGHT
          The default chart height is 400 pixels.
static int DEFAULT_CHART_WIDTH
          The default chart width is 750 pixels.
static String[] DEFAULT_SERIES_COLORS
          The default hex color codes used for the individual data series displayed on the chart.
static int MAX_POSSIBLE_CHART_SIZE
          The maximum supported chart size is 300,000 pixels per the Google Chart API.
 
Fields inherited from interface org.perf4j.chart.StatisticsChartGenerator
DEFAULT_MAX_DATA_POINTS
 
Constructor Summary
GoogleChartGenerator()
          Default constructor creates a chart that displays mean execution values and uses the default Google Chart URL.
GoogleChartGenerator(StatsValueRetriever statsValueRetriever)
          Creates a chart that uses the specified StatsValueRetriever to determine which values from the TimingStatistic object to display.
GoogleChartGenerator(StatsValueRetriever valueRetriever, String baseUrl)
          Creates a chart that uses the specified StatsValueRetriever to determine which values from the StatsPerTag object to display, and also allows the base chart URL to be overridden from the Google default.
 
Method Summary
 void appendData(GroupedTimingStatistics statistics)
          Appends a set of statistics to the list of data to be displayed on the chart.
protected  String encodeUrl(String string)
          Helper method encodes a string use as a URL parameter value.
protected  String generateGoogleChartParams()
          Helper method takes the list of data values and converts them to a String suitable for appending to a Google Chart URL.
 String getChartUrl()
          Implementing classes should return a URL to the chart that depicts the data sent in to the appendData method.
 List<GroupedTimingStatistics> getData()
          Gets the data that will be visualized by any charts created by this chart generator.
 Set<String> getEnabledTags()
          Gets the set of tag names for which values will be displayed on the chart.
 int getHeight()
          Gets the height of the chart that will be displayed
 int getMaxDataPoints()
          Gets the maximum number of data points to display on a chart.
 int getWidth()
          Gets the width of the chart that will be displayed
protected  String numberValuesToGoogleDataSeriesParam(List<Number> values, double minPossibleValue, double maxPossibleValue)
          This helper method is used to normalize a list of data values from 0 - 100 as required by the Google Chart Data API, and from this data it constructs the series data URL param.
 void setEnabledTags(Set<String> enabledTags)
          Sets the set of tag names for which values will be displayed on the chart.
 void setHeight(int height)
          Sets the height of the chart in pixels.
 void setMaxDataPoints(int maxDataPoints)
          Sets the maximum number of data points to display on a chart.
 void setWidth(int width)
          Sets the width of the chart in pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BASE_URL

public static final String DEFAULT_BASE_URL
The DEFAULT_BASE_URL points to Google's charting server at chart.apis.google.com.

See Also:
Constant Field Values

MAX_POSSIBLE_CHART_SIZE

public static final int MAX_POSSIBLE_CHART_SIZE
The maximum supported chart size is 300,000 pixels per the Google Chart API.

See Also:
Constant Field Values

DEFAULT_CHART_WIDTH

public static final int DEFAULT_CHART_WIDTH
The default chart width is 750 pixels.

See Also:
Constant Field Values

DEFAULT_CHART_HEIGHT

public static final int DEFAULT_CHART_HEIGHT
The default chart height is 400 pixels.

See Also:
Constant Field Values

DEFAULT_SERIES_COLORS

public static final String[] DEFAULT_SERIES_COLORS
The default hex color codes used for the individual data series displayed on the chart.

Constructor Detail

GoogleChartGenerator

public GoogleChartGenerator()
Default constructor creates a chart that displays mean execution values and uses the default Google Chart URL.


GoogleChartGenerator

public GoogleChartGenerator(StatsValueRetriever statsValueRetriever)
Creates a chart that uses the specified StatsValueRetriever to determine which values from the TimingStatistic object to display. For example, a chart could be used to display mean values, transactions per second, etc.

Parameters:
statsValueRetriever - The StatsPerTagDataValueExtractor that determines which value to display.

GoogleChartGenerator

public GoogleChartGenerator(StatsValueRetriever valueRetriever,
                            String baseUrl)
Creates a chart that uses the specified StatsValueRetriever to determine which values from the StatsPerTag object to display, and also allows the base chart URL to be overridden from the Google default.

Parameters:
valueRetriever - Determines which value (such as mean/min/max/etc) from the TimingStatistic to display on the chart
baseUrl - A value to override for the default base URL of "http://chart.apis.google.com/chart?"
Method Detail

getWidth

public int getWidth()
Gets the width of the chart that will be displayed

Returns:
The width of the chart in pixels, defaults to 750.

setWidth

public void setWidth(int width)
Sets the width of the chart in pixels. Note that the Google Charting API currently only supports a maximum of 300,000 pixels for display, so width X height must be less than 300,000.

Parameters:
width - the width of the chart in pixels.

getHeight

public int getHeight()
Gets the height of the chart that will be displayed

Returns:
The height of the chart in pixels, defaults to 400.

setHeight

public void setHeight(int height)
Sets the height of the chart in pixels. Note that the Google Charting API currently only supports a maximum of 300,000 pixels for display, so width X height must be less than 300,000.

Parameters:
height - the height of the chart in pixels.

getEnabledTags

public Set<String> getEnabledTags()
Gets the set of tag names for which values will be displayed on the chart. Each tag is represented as a separate series on the chart.

Returns:
The set of enabled tag names, or null if ALL tags found in the GroupedTimingStatistics data will be displayed.

setEnabledTags

public void setEnabledTags(Set<String> enabledTags)
Sets the set of tag names for which values will be displayed on the chart.

Parameters:
enabledTags - The set of enabled tag names. If this method is not called, or if enabledTags is null, then ALL tags from the GroupedTimingStatistics data will be displayed on the chart.

getMaxDataPoints

public int getMaxDataPoints()
Gets the maximum number of data points to display on a chart. If appendData is called more than this number of times, then only the last maxDataPoints data items will be shown in any generated charts.

Returns:
the maximum number of data points that will be displayed

setMaxDataPoints

public void setMaxDataPoints(int maxDataPoints)
Sets the maximum number of data points to display on a chart.

Parameters:
maxDataPoints - The maximum number of data points.

getData

public List<GroupedTimingStatistics> getData()
Description copied from interface: StatisticsChartGenerator
Gets the data that will be visualized by any charts created by this chart generator.

Specified by:
getData in interface StatisticsChartGenerator
Returns:
The data for this chart generator.

appendData

public void appendData(GroupedTimingStatistics statistics)
Description copied from interface: StatisticsChartGenerator
Appends a set of statistics to the list of data to be displayed on the chart.

Specified by:
appendData in interface StatisticsChartGenerator
Parameters:
statistics - the statistics to be added to the list of data.

getChartUrl

public String getChartUrl()
Description copied from interface: StatisticsChartGenerator
Implementing classes should return a URL to the chart that depicts the data sent in to the appendData method. Note that the format of the URL is completely up to the implementing class - some implementations may generate a binary file and return a URL to the known server hosting the file, others may generate a Google Chart API-formatted URL, while others may return a data: URL with the image data directly embedded.

Specified by:
getChartUrl in interface StatisticsChartGenerator
Returns:
A URL that can be used to display the chart.

generateGoogleChartParams

protected String generateGoogleChartParams()
Helper method takes the list of data values and converts them to a String suitable for appending to a Google Chart URL.

Returns:
the chart parameters that encode all of the data necessary to display the chart.

numberValuesToGoogleDataSeriesParam

protected String numberValuesToGoogleDataSeriesParam(List<Number> values,
                                                     double minPossibleValue,
                                                     double maxPossibleValue)
This helper method is used to normalize a list of data values from 0 - 100 as required by the Google Chart Data API, and from this data it constructs the series data URL param.

Parameters:
values - the values to be normalized
minPossibleValue - the minimum possible value for the values
maxPossibleValue - the maximmum possible value for the values
Returns:
A Google Chart API data series using normal text encoding (see the Chart API docs)

encodeUrl

protected String encodeUrl(String string)
Helper method encodes a string use as a URL parameter value.

Parameters:
string - the string to encode
Returns:
the encoded string


Copyright © 2008-2009 perf4j.org. All Rights Reserved.