org.jrobin.graph
Class RrdGraph

java.lang.Object
  extended by org.jrobin.core.RrdOpener
      extended by org.jrobin.graph.RrdGraph
All Implemented Interfaces:
java.io.Serializable

public class RrdGraph
extends RrdOpener
implements java.io.Serializable

Class to represent JRobin graphs. This class needs an appropriate RrdGraphDef to generate graphs.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jrobin.core.RrdOpener
pool, readOnly, usePool
 
Constructor Summary
RrdGraph()
          Constructs a new JRobin graph object, without a shared database pool.
RrdGraph(boolean usePool)
          Constructs a new JRobin graph object.
RrdGraph(RrdGraphDef graphDef)
          Constructs a new JRobin graph object from the supplied definition.
RrdGraph(RrdGraphDef graphDef, boolean usePool)
          Constructs a new JRobin graph from the supplied definition.
 
Method Summary
 ExportData fetchExportData()
          This retrieves the ExportData object associated with the reduced dataset of this Graph, by calculating the dataset on the spot.
 ExportData fetchExportData(int maxRows)
          This retrieves the ExportData object associated with the reduced dataset of this Graph, by calculating the dataset on the spot.
 java.awt.image.BufferedImage getBufferedImage(int width, int height)
          Returns the underlying BufferedImage of a graph with custom dimensions.
 ChartPanel getChartPanel()
          Returns panel object so that graph can be easily embedded in swing applications.
 ExportData getExportData()
          This retrieves the ExportData object associated with the reduced dataset of this Graph.
 byte[] getGIFBytes()
          Returns graph with default chart dimensions (400 by 100) as an array of GIF bytes.
 byte[] getGIFBytes(int width, int height)
          Returns graph with custom chart dimensions as an array of GIF bytes.
 byte[] getJPEGBytes(float quality)
          Returns graph with default chart dimensions (400 by 100) as an array of JPEG bytes.
 byte[] getJPEGBytes(int width, int height, float quality)
          Returns graph with custom chart dimensions as an array of JPEG bytes.
 byte[] getPNGBytes()
          Returns graph with default chart dimensions (400 by 100) as an array of PNG bytes.
 byte[] getPNGBytes(int width, int height)
          Returns graph with custom chart dimensions as an array of PNG bytes.
 void renderImage(java.awt.Graphics2D graphics, int width, int height)
          Renders the graph onto a specified Graphics2D object.
 void saveAsGIF(java.lang.String path)
          Creates and saves a graph image with default dimensions as a GIF file.
 void saveAsGIF(java.lang.String path, int width, int height)
          Creates and saves a graph image with custom chart dimensions as a GIF file.
 void saveAsJPEG(java.lang.String path, float quality)
          Creates and saves a graph image with default dimensions as a JPEG file.
 void saveAsJPEG(java.lang.String path, int width, int height, float quality)
          Creates and saves a graph image with custom chart dimensions as a JPEG file.
 void saveAsPNG(java.lang.String path)
          Creates and saves a graph image with default dimensions as a PNG file.
 void saveAsPNG(java.lang.String path, int width, int height)
          Creates and saves a graph image with custom chart dimensions as a PNG file.
 void setGraphDef(RrdGraphDef graphDef)
          Sets the graph definition to use for the graph construction.
 void specifyImageSize(boolean specImgSize)
          Determines if graph creation should specify dimensions for the chart graphing are, of for the entire image size.
 
Methods inherited from class org.jrobin.core.RrdOpener
getRrd, releaseRrd
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RrdGraph

public RrdGraph()
Constructs a new JRobin graph object, without a shared database pool.


RrdGraph

public RrdGraph(boolean usePool)
Constructs a new JRobin graph object.

Parameters:
usePool - True if this object should use RrdDbPool

RrdGraph

public RrdGraph(RrdGraphDef graphDef)
Constructs a new JRobin graph object from the supplied definition.

Parameters:
graphDef - Graph definition.

RrdGraph

public RrdGraph(RrdGraphDef graphDef,
                boolean usePool)
Constructs a new JRobin graph from the supplied definition.

Parameters:
graphDef - Graph definition.
usePool - True if this should object should use RrdDbPool
Method Detail

specifyImageSize

public void specifyImageSize(boolean specImgSize)
Determines if graph creation should specify dimensions for the chart graphing are, of for the entire image size. Default is the only the chart graphing area, this has an impact on the entire image size.

Parameters:
specImgSize - True if the dimensions for the entire image will be specified, false if only for the chart area.

setGraphDef

public void setGraphDef(RrdGraphDef graphDef)
Sets the graph definition to use for the graph construction.

Parameters:
graphDef - Graph definition.

saveAsPNG

public void saveAsPNG(java.lang.String path)
               throws RrdException,
                      java.io.IOException
Creates and saves a graph image with default dimensions as a PNG file. By default the chart area is 400 by 100 pixels, the size of the entire image is dependant on number of title/legend/comment lines and some other settings.

Parameters:
path - Path to the PNG file to be created.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException - Thrown in case of JRobin specific error.

saveAsPNG

public void saveAsPNG(java.lang.String path,
                      int width,
                      int height)
               throws RrdException,
                      java.io.IOException
Creates and saves a graph image with custom chart dimensions as a PNG file. The resulting size of the entire image is also influenced by many other settings like number of comment lines.

Parameters:
path - Path to the PNG file to be created.
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException - Thrown in case of JRobin specific error.

saveAsGIF

public void saveAsGIF(java.lang.String path)
               throws RrdException,
                      java.io.IOException
Creates and saves a graph image with default dimensions as a GIF file. By default the chart area is 400 by 100 pixels, the size of the entire image is dependant on number of title/legend/comment lines and some other settings.

Parameters:
path - Path to the GIF file to be created.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException - Thrown in case of JRobin specific error.

saveAsGIF

public void saveAsGIF(java.lang.String path,
                      int width,
                      int height)
               throws RrdException,
                      java.io.IOException
Creates and saves a graph image with custom chart dimensions as a GIF file. The resulting size of the entire image is also influenced by many other settings like number of comment lines.

Parameters:
path - Path to the GIF file to be created.
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException - Thrown in case of JRobin specific error.

saveAsJPEG

public void saveAsJPEG(java.lang.String path,
                       float quality)
                throws RrdException,
                       java.io.IOException
Creates and saves a graph image with default dimensions as a JPEG file. By default the chart area is 400 by 100 pixels, the size of the entire image is dependant on number of title/legend/comment lines and some other settings.

Parameters:
path - Path to the JPEG file to be created.
quality - JPEG quality, between 0 (= low) and 1.0f (= high).
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

saveAsJPEG

public void saveAsJPEG(java.lang.String path,
                       int width,
                       int height,
                       float quality)
                throws RrdException,
                       java.io.IOException
Creates and saves a graph image with custom chart dimensions as a JPEG file. The resulting size of the entire image is also influenced by many other settings like number of comment lines.

Parameters:
path - Path to the JPEG file to be created.
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
quality - JPEG quality, between 0 (= low) and 1.0f (= high).
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getPNGBytes

public byte[] getPNGBytes()
                   throws java.io.IOException,
                          RrdException
Returns graph with default chart dimensions (400 by 100) as an array of PNG bytes.

Returns:
Array of PNG bytes.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getPNGBytes

public byte[] getPNGBytes(int width,
                          int height)
                   throws java.io.IOException,
                          RrdException
Returns graph with custom chart dimensions as an array of PNG bytes.

Parameters:
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
Returns:
Array of PNG bytes.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getJPEGBytes

public byte[] getJPEGBytes(float quality)
                    throws java.io.IOException,
                           RrdException
Returns graph with default chart dimensions (400 by 100) as an array of JPEG bytes.

Parameters:
quality - JPEG quality, between 0 (= low) and 1.0f (= high).
Returns:
Array of PNG bytes.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getJPEGBytes

public byte[] getJPEGBytes(int width,
                           int height,
                           float quality)
                    throws java.io.IOException,
                           RrdException
Returns graph with custom chart dimensions as an array of JPEG bytes.

Parameters:
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
quality - JPEG quality, between 0 (= low) and 1.0f (= high).
Returns:
Array of JPEG bytes.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getGIFBytes

public byte[] getGIFBytes()
                   throws RrdException,
                          java.io.IOException
Returns graph with default chart dimensions (400 by 100) as an array of GIF bytes.

Returns:
Array of GIF bytes.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getGIFBytes

public byte[] getGIFBytes(int width,
                          int height)
                   throws RrdException,
                          java.io.IOException
Returns graph with custom chart dimensions as an array of GIF bytes.

Parameters:
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
Returns:
Array of GIF bytes.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage(int width,
                                                     int height)
                                              throws java.io.IOException,
                                                     RrdException
Returns the underlying BufferedImage of a graph with custom dimensions. Specifying 0 for both width and height will result in a auto-sized graph.

Parameters:
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
Returns:
BufferedImage containing the graph.
Throws:
java.io.IOException - Thrown in case of I/O error.
RrdException - Thrown in case of JRobin specific error.

getChartPanel

public ChartPanel getChartPanel()
                         throws RrdException,
                                java.io.IOException
Returns panel object so that graph can be easily embedded in swing applications.

Returns:
Swing JPanel object with graph embedded in panel.
Throws:
RrdException
java.io.IOException

renderImage

public void renderImage(java.awt.Graphics2D graphics,
                        int width,
                        int height)
                 throws RrdException,
                        java.io.IOException
Renders the graph onto a specified Graphics2D object. Specifying 0 for both width and height will result in a auto-sized graph.

Parameters:
graphics - Handle to a Graphics2D object to render the graph on.
width - Width of the chart area in pixels.
height - Height of the chart area in pixels.
Throws:
RrdException - Thrown in case of JRobin specific error.
java.io.IOException - Thrown in case of I/O error

getExportData

public ExportData getExportData()
                         throws RrdException
This retrieves the ExportData object associated with the reduced dataset of this Graph. This method assumes the graph or at least the dataset has already been calculated.

Returns:
ExportData object containing the reduced dataset.
Throws:
RrdException - Thrown in case of JRobin specific error.

fetchExportData

public ExportData fetchExportData()
                           throws RrdException,
                                  java.io.IOException
This retrieves the ExportData object associated with the reduced dataset of this Graph, by calculating the dataset on the spot. Use this if you want to retrieve the associated ExportData without generating the actual graph.

Returns:
ExportData object containing the reduced dataset.
Throws:
RrdException - Thrown in case of JRobin specific error.
java.io.IOException - Thrown in case of I/O error

fetchExportData

public ExportData fetchExportData(int maxRows)
                           throws RrdException,
                                  java.io.IOException
This retrieves the ExportData object associated with the reduced dataset of this Graph, by calculating the dataset on the spot. Use this if you want to retrieve the associated ExportData without generating the actual graph, or if you wish to re-calculate the associated dataset for a different number of rows.

Parameters:
maxRows - Ballpark figure 'maximum number of rows' that the dataset can contain. Note that this is not an absolute maximum and can be overruled in some cases.
Returns:
ExportData object containing the reduced dataset.
Throws:
RrdException - Thrown in case of JRobin specific error.
java.io.IOException - Thrown in case of I/O error