net.opentsdb.graph
Class Plot

java.lang.Object
  extended by net.opentsdb.graph.Plot

public final class Plot
extends Object

Produces files to generate graphs with Gnuplot.

This class takes a bunch of DataPoints instances and generates a Gnuplot script as well as the corresponding data files to feed to Gnuplot.


Constructor Summary
Plot(long start_time, long end_time)
          Constructor.
 
Method Summary
 void add(DataPoints datapoints, String options)
          Adds some data points to this plot.
 int dumpToFiles(String basepath)
          Generates the Gnuplot script and data files.
 Iterable<DataPoints> getDataPoints()
          Returns a view on the datapoints in this plot.
 void setDimensions(short width, short height)
          Sets the dimensions of the graph (in pixels).
 void setParams(Map<String,String> params)
          Sets the global parameters for this plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Plot

public Plot(long start_time,
            long end_time)
Constructor.

Parameters:
start_time - Timestamp of the start time of the graph.
end_time - Timestamp of the end time of the graph.
Throws:
IllegalArgumentException - if either timestamp is 0 or negative.
IllegalArgumentException - if start_time >= end_time.
Method Detail

setParams

public void setParams(Map<String,String> params)
Sets the global parameters for this plot.

Parameters:
params - Each entry is a Gnuplot setting that will be written as-is in the Gnuplot script file: set KEY VALUE. When the value is null the script will instead contain unset KEY.

setDimensions

public void setDimensions(short width,
                          short height)
Sets the dimensions of the graph (in pixels).

Parameters:
width - The width of the graph produced (in pixels).
height - The height of the graph produced (in pixels).
Throws:
IllegalArgumentException - if the width or height are negative, zero or "too small" (e.g. less than 100x100 pixels).

add

public void add(DataPoints datapoints,
                String options)
Adds some data points to this plot.

Parameters:
datapoints - The data points to plot.
options - The options to apply to this specific series.

getDataPoints

public Iterable<DataPoints> getDataPoints()
Returns a view on the datapoints in this plot. Do not attempt to modify the return value.


dumpToFiles

public int dumpToFiles(String basepath)
                throws IOException
Generates the Gnuplot script and data files.

Parameters:
basepath - The base path to use. A number of new files will be created and their names will all start with this string.
Returns:
The number of data points sent to Gnuplot. This can be less than the number of data points involved in the query due to things like aggregation or downsampling.
Throws:
IOException - if there was an error while writing one of the files.