From: Arne V. <cob...@us...> - 2004-05-30 19:50:08
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27850/org/jrobin/graph Modified Files: Cdef.java ChartPanel.java FetchSource.java Grapher.java Pdef.java RpnCalculator.java RrdGraph.java RrdGraphDef.java RrdGraphDefTemplate.java ValueExtractor.java ValueGrid.java Added Files: RrdtoolGraph.java Sdef.java Log Message: JRobin 1.4.0 - Added new datasource (Sdef) - Added backend specification to datasource - Added option to pass Graphics2D object for drawing - Minor changes to RrdGraph/Grapher/ChartPanel Index: Cdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Cdef.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Cdef.java 30 Mar 2004 22:57:45 -0000 1.5 --- Cdef.java 30 May 2004 19:49:55 -0000 1.6 *************** *** 51,55 **** // ================================================================ // -- Constructors ! // ================================================================ /** * Constructs a new Cdef object holding a number of datapoints for a graph. --- 51,67 ---- // ================================================================ // -- Constructors ! // ================================================================ ! /** ! * Constructs a new simple Cdef object based on an empty RPN expression,. ! * ! * @param name Name of the datasource in the graph definition. ! */ ! Cdef( String name ) ! { ! super( name ); ! ! strTokens = new String[0]; ! } ! /** * Constructs a new Cdef object holding a number of datapoints for a graph. *************** *** 185,189 **** tokens[i] = RpnCalculator.TKN_STEP; else ! throw new RrdException("Unknown token enocuntered: " + tkn); } --- 197,201 ---- tokens[i] = RpnCalculator.TKN_STEP; else ! throw new RrdException("Unknown token encountered: " + tkn); } *************** *** 191,194 **** --- 203,225 ---- /** + * Returns the level this Cdef would have in the calculation tree. The level defines when + * the Cdef can be calculated. The level depends on the number of Sdefs this Cdef is depending + * on, and their corresponding calculation levels. + * + * @param levels Array containing the previously calculated calculation levels. + * @return Level of this Sdef in the calculation tree. + */ + int calculateLevel( int[] levels ) + { + int level = 0; + + for ( int i = 0; i < dsIndices.length; i++ ) + if ( levels[ dsIndices[i] ] > level ) + level = levels[ dsIndices[i] ]; + + return level; + } + + /** * Sets the value of a specific datapoint for this Cdef. * @param pos Position (index in the value table) of the new datapoint. Index: ValueExtractor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueExtractor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ValueExtractor.java 7 Nov 2003 08:23:19 -0000 1.1 --- ValueExtractor.java 30 May 2004 19:49:56 -0000 1.2 *************** *** 103,107 **** for (int j = 0; j < dsValues[i].length; j++) sources[tblPos++].set( row, timestamp, dsValues[i][j][ tIndex + 1 ] ); ! break; } else { --- 103,107 ---- for (int j = 0; j < dsValues[i].length; j++) sources[tblPos++].set( row, timestamp, dsValues[i][j][ tIndex + 1 ] ); ! break; } else { --- NEW FILE: Sdef.java --- package org.jrobin.graph; import java.util.HashMap; import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; /** * <p>Represents a 'static' datasource for a graph. A static datasource is a single value (constant), * but can only be the result of applying a consolidation function (AVG, MIN, MAX, LAST, FIRST or TOTAL) * to one of the other, already defined, datasources.</p> * * @author Arne Vandamme (cob...@jr...) */ class Sdef extends Cdef { // ================================================================ // -- Members // ================================================================ private int defIndex = -1; private String defName = ""; private String consolFunc = "AVERAGE"; private int aggregate = Source.AGG_AVERAGE; private boolean calculated = false; private double[] value = null; // ================================================================ // -- Constructors // ================================================================ /** * Constructs a new Sdef object based on an existing datasource (Def, Cdef or Pdef) * and the consolidation function to apply to that datasource. * * @param name Name of the datasource in the graph definition. * @param defName Name of the datasource this Sdef is derived from. * @param consolFunc Consolidation function to apply to the referring datasource (defName). * @throws RrdException Thrown in case of invalid consolidation function specified. */ Sdef( String name, String defName, String consolFunc ) throws RrdException { super( name ); this.defName = defName; this.consolFunc = consolFunc; // -- Parse the consolidation function to be used if ( consolFunc.equalsIgnoreCase("AVERAGE") || consolFunc.equalsIgnoreCase("AVG") ) aggregate = Source.AGG_AVERAGE; else if ( consolFunc.equalsIgnoreCase("MAX") || consolFunc.equalsIgnoreCase("MAXIMUM") ) aggregate = Source.AGG_MAXIMUM; else if ( consolFunc.equalsIgnoreCase("MIN") || consolFunc.equalsIgnoreCase("MINIMUM") ) aggregate = Source.AGG_MINIMUM; else if ( consolFunc.equalsIgnoreCase("LAST") ) aggregate = Source.AGG_LAST; else if ( consolFunc.equalsIgnoreCase("FIRST") ) aggregate = Source.AGG_FIRST; else if ( consolFunc.equalsIgnoreCase("TOTAL") ) aggregate = Source.AGG_TOTAL; else throw new RrdException( "Invalid consolidation function specified." ); } // ================================================================ // -- Protected methods // ================================================================ /** * Prepares the Sef for faster value calculation by setting the internal * array and references. Override from Cdef parent class. * * @param sourceIndex Lookup table holding the name - index pairs for all datasources. * @param numPoints Number of points used as graph resolution (size of the value table). * @throws RrdException Thrown in case of the requested datasource is not available in the sourceIndex */ void prepare( HashMap sourceIndex, int numPoints ) throws RrdException { if ( sourceIndex.containsKey( defName ) ) defIndex = ( (Integer) sourceIndex.get( defName ) ).intValue(); else throw new RrdException( "Datasource not found: " + defName ); values = new double[ numPoints ]; } /** * Returns the level this Sdef would have in the calculation tree. The level defines when * the Sdef can be calculated. The level of the Sdef will always be one higher than that of * its referring datasource, since it can only be calculated after that datasource has already * been calculated. * * @param levels Array containing the previously calculated calculation levels. * @return Level of this Sdef in the calculation tree. */ int calculateLevel( int[] levels ) { // An Sdef is always one lower in the tree than its source return levels[defIndex] + 1; } /** * Gets the value of the datapoint at a particular position in the datapoint array. * In case of an Sdef, the value will be the same for every different position. * * @param pos Inherited from Cdef * @return The consolidated value of the referring datasource as double */ double get( int pos ) { return values[0]; } /** * Calculates the internal value of this Sdef. * * @param sources Array of the calculated datasources. */ void set( Source[] sources ) { if ( calculated ) return; double value = sources[ defIndex ].getAggregate( aggregate ); for ( int i = 0; i < values.length; i++ ) values[i] = value; calculated = true; } /** * Override from the corresponding method in the Source parent class, * overridden for faster implementation. * * Five of the possible aggregation methods return the actual value * of the Sdef: * <code>AGG_MINIMUM, AGG_MAXIMUM, AGG_AVERAGE, AGG_FIRST and AGG_LAST</code> * * Only <code>AGG_TOTAL</code> will return value summed over the number of * samples in the graph. * * @param aggType Type of the aggregate requested. * @return The double value of the requested aggregate. */ double getAggregate( int aggType ) { switch ( aggType ) { case AGG_MINIMUM: case AGG_MAXIMUM: case AGG_AVERAGE: case AGG_FIRST: case AGG_LAST: return values[0]; case AGG_TOTAL: return (values[0] * values.length) ; } return Double.NaN; } void exportXml(XmlWriter xml) { xml.startTag( "def" ); xml.writeTag( "name", getName() ); xml.writeTag( "datasource", defName ); xml.writeTag( "cf", consolFunc ); xml.closeTag(); // def } } Index: ChartPanel.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ChartPanel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ChartPanel.java 7 Nov 2003 09:53:35 -0000 1.2 --- ChartPanel.java 30 May 2004 19:49:56 -0000 1.3 *************** *** 25,29 **** package org.jrobin.graph; ! import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.JPanel; --- 25,29 ---- package org.jrobin.graph; ! import java.awt.*; import java.awt.image.BufferedImage; import javax.swing.JPanel; *************** *** 38,42 **** private BufferedImage chart; ! void setChart( BufferedImage chart ) { this.chart = chart; } --- 38,42 ---- private BufferedImage chart; ! public void setChart( BufferedImage chart ) { this.chart = chart; } Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdGraphDefTemplate.java 28 Apr 2004 12:05:01 -0000 1.6 --- RrdGraphDefTemplate.java 30 May 2004 19:49:56 -0000 1.7 *************** *** 495,501 **** validateTagsOnlyOnce(nodes[i], new String[] {"name", "rpn"}); String name = getChildValue(nodes[i], "name"); ! String rpn = getChildValue(nodes[i], "rpn"); rrdGraphDef.datasource(name, rpn); } else { throw new RrdException("Unrecognized <def> format"); --- 495,509 ---- validateTagsOnlyOnce(nodes[i], new String[] {"name", "rpn"}); String name = getChildValue(nodes[i], "name"); ! String rpn = getChildValue(nodes[i], "rpn"); rrdGraphDef.datasource(name, rpn); } + else if ( hasChildNode( nodes[i], "cf" ) || hasChildNode( nodes[i], "datasource" ) ) { + // STATIC AGGREGATED DATASOURCE + validateTagsOnlyOnce( nodes[i], new String[] {"name", "datasource", "cf"} ); + String name = getChildValue(nodes[i], "name"); + String ds = getChildValue(nodes[i], "datasource"); + String cf = getChildValue(nodes[i], "cf"); + rrdGraphDef.datasource( name, ds, cf ); + } else { throw new RrdException("Unrecognized <def> format"); Index: Pdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Pdef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Pdef.java 16 Jan 2004 16:36:54 -0000 1.2 --- Pdef.java 30 May 2004 19:49:56 -0000 1.3 *************** *** 36,39 **** --- 36,42 ---- class Pdef extends Source { + // ================================================================ + // -- Members + // ================================================================ private Plottable plottable; *************** *** 42,46 **** private boolean indexed = false; private boolean named = false; ! /** * Constructs a new Plottable Def: a custom external datasource --- 45,53 ---- private boolean indexed = false; private boolean named = false; ! ! ! // ================================================================ ! // -- Constructors ! // ================================================================ /** * Constructs a new Plottable Def: a custom external datasource *************** *** 85,88 **** --- 92,99 ---- } + + // ================================================================ + // -- Protected methods + // ================================================================ /** * Prepares the array that will hold the values. Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FetchSource.java 1 Mar 2004 08:50:25 -0000 1.3 --- FetchSource.java 30 May 2004 19:49:56 -0000 1.4 *************** *** 26,29 **** --- 26,30 ---- import java.util.Vector; + import java.util.ArrayList; import java.io.IOException; *************** *** 53,59 **** private String rrdFile; // Holds the name of the RRD file ! private int numSources = 0; ! private Vector[] datasources = new Vector[MAX_CF]; --- 54,61 ---- private String rrdFile; // Holds the name of the RRD file ! private String backendName; ! private int numSources = 0; ! private ArrayList[] datasources = new ArrayList[MAX_CF]; *************** *** 71,75 **** // Initialization of datasource lists per CF for (int i = 0; i < datasources.length; i++) ! datasources[i] = new Vector(); } --- 73,77 ---- // Initialization of datasource lists per CF for (int i = 0; i < datasources.length; i++) ! datasources[i] = new ArrayList( 10 ); } *************** *** 86,92 **** { this( rrdFile ); ! addSource( consolFunc, dsName, name ); } ! // ================================================================ // -- Protected methods --- 88,110 ---- { this( rrdFile ); ! addSource( consolFunc, dsName, name ); } ! ! /** ! * Constructs a FetchSource object based on a RRD file name, and ! * adds a given datasource to the datasources list. ! * @param rrdFile Name of the RRD file holding all datasources. ! * @param consolFunc Consolidation function of the datasource to fetch. ! * @param dsName Internal name of the datasource in the RRD file. ! * @param name Variable name of the datasource in the graph definition. ! * @param backendName Name of the RrdBackendFactory to use for this RrdDb. ! * @throws RrdException Thrown in case of a JRobin specific error. ! */ ! FetchSource( String rrdFile, String consolFunc, String dsName, String name, String backendName ) throws RrdException ! { ! this( rrdFile, consolFunc, dsName, name ); ! setBackendFactory( backendName ); ! } ! // ================================================================ // -- Protected methods *************** *** 114,118 **** numSources++; } ! /** * Fetches all datavalues for a given timespan out of the provided RRD file. --- 132,145 ---- numSources++; } ! ! /** ! * Sets the name of the RrdBackendFactory that should be used for this FetchSource. ! * The factory should be registered with RrdBackendFactory static. ! * @param backendName Name of the RrdBackendFactory to use for this RrdDb. ! */ ! protected void setBackendFactory( String backendName ) { ! this.backendName = backendName; ! } ! /** * Fetches all datavalues for a given timespan out of the provided RRD file. *************** *** 126,129 **** --- 153,159 ---- protected ValueExtractor fetch ( RrdDb rrd, long startTime, long endTime ) throws IOException, RrdException { + int dsSize = 0; + String[] dsNames, vNames; + long rrdStep = rrd.getRrdDef().getStep(); FetchData[] result = new FetchData[datasources.length]; *************** *** 134,144 **** for (int i = 0; i < datasources.length; i++) { ! if ( datasources[i].size() > 0 ) { // Set the list of ds names ! String[] dsNames = new String[ datasources[i].size() ]; ! String[] vNames = new String[ datasources[i].size() ]; ! for (int j = 0; j < dsNames.length; j++ ) { ! String[] spair = (String[]) datasources[i].elementAt(j); dsNames[j] = spair[0]; vNames[j] = spair[1]; --- 164,176 ---- for (int i = 0; i < datasources.length; i++) { ! dsSize = datasources[i].size(); ! ! if ( dsSize > 0 ) { // Set the list of ds names ! dsNames = new String[ dsSize ]; ! vNames = new String[ dsSize ]; ! for (int j = 0; j < dsSize; j++ ) { ! String[] spair = (String[]) datasources[i].get(j); dsNames[j] = spair[0]; vNames[j] = spair[1]; *************** *** 151,157 **** FetchData data = request.fetchData(); ! for (int j = 0; j < vNames.length; j++) names[ data.getDsIndex(dsNames[j]) + tblPos ] = vNames[j]; ! tblPos += dsNames.length; result[i] = data; --- 183,189 ---- FetchData data = request.fetchData(); ! for (int j = 0; j < dsSize; j++) names[ data.getDsIndex(dsNames[j]) + tblPos ] = vNames[j]; ! tblPos += dsSize; result[i] = data; *************** *** 166,173 **** } public void exportXml(XmlWriter xml) { for ( int i = 0; i < datasources.length; i++ ) { for ( int j = 0; j < datasources[i].size(); j++ ) { ! String[] pair = (String[]) datasources[i].elementAt(j); xml.startTag("def"); xml.writeTag("name", pair[1]); --- 198,213 ---- } + protected RrdBackendFactory getRrdBackendFactory() throws RrdException + { + if ( backendName != null ) + return RrdBackendFactory.getFactory( backendName ); + + return RrdBackendFactory.getDefaultFactory(); + } + public void exportXml(XmlWriter xml) { for ( int i = 0; i < datasources.length; i++ ) { for ( int j = 0; j < datasources[i].size(); j++ ) { ! String[] pair = (String[]) datasources[i].get(j); xml.startTag("def"); xml.writeTag("name", pair[1]); --- NEW FILE: RrdtoolGraph.java --- package org.jrobin.graph; import org.jrobin.core.RrdException; import java.awt.*; /** * Created by IntelliJ IDEA. * User: cbld * Date: 25-mei-2004 * Time: 21:02:56 * To change this template use File | Settings | File Templates. */ public class RrdtoolGraph { // ================================================================ // -- Constants // ================================================================ private static final int SAVE_PNG = 0; private static final int SAVE_GIF = 1; private static final int DS_DEF = 0; private static final int DS_CDEF = 1; private static final int TXT_COMMENT = 0; private static final int TXT_GPRINT = 1; private static final int GRAPH_LINE = 0; private static final int GRAPH_AREA = 1; private static final int GRAPH_STACK = 2; private static final int TKN_IGNORE = -2; private static final int TKN_UNKNOWN = -1; private static final int TKN_RRDTOOL = 0; private static final int TKN_GRAPH = 1; private static final int TKN_START = 2; private static final int TKN_END = 3; private static final int TKN_COMMENT = 4; private static final int TKN_LINE = 5; private static final int TKN_AREA = 6; private static final int TKN_STACK = 7; private static final int TKN_CDEF = 8; private static final int TKN_DEF = 9; private static final int TKN_GPRINT = 11; private static final int TKN_HRULE = 12; private static final int TKN_VRULE = 13; private static final int TKN_STEP = 14; private static final int TKN_TITLE = 15; private static final int TKN_NOLEGEND = 16; private static final int TKN_COLOR = 17; private static final int TKN_RIGID = 18; private static final int TKN_LOWERLIMIT = 19; private static final int TKN_UPPERLIMIT = 20; private static final int TKN_LAZY = 21; private static final int TKN_OVERLAY = 23; private static final int TKN_BACKGROUND = 24; private static final int TKN_IMGFORMAT = 25; private static final int TKN_WIDTH = 26; private static final int TKN_HEIGHT = 27; private static final int TKN_VERT_LABEL = 28; private static final int TKN_UNITS_EXP = 29; private static final int TKN_NOMINOR = 30; private static final int TKN_XGRID = 31; private static final int TKN_YGRID = 32; private static final int TKN_BASE = 33; // ================================================================ // -- Members // ================================================================ private String token = ""; private String script = null; private RrdGraphDef graphDef = null; private int tokenPos = 0; private char[] parseCmd = new char[0]; private boolean gridRigid = false; private double gridLower = Double.MAX_VALUE; private double gridUpper = Double.MIN_VALUE; private int width = 0; private int height = 0; private int fileType = SAVE_PNG; private String fileName = ""; // ================================================================ // -- Constructors // ================================================================ public RrdtoolGraph( String script ) { this.script = script; } // ================================================================ // -- Public methods // ================================================================ public RrdGraphDef getRrdGraphDef() throws RrdException { parseRrdtoolScript(); return graphDef; } // ================================================================ // -- Private methods // ================================================================ /** * * @return * @throws RrdException */ private boolean parseRrdtoolScript() throws RrdException { long startTime = 0, stopTime = 0; graphDef = new RrdGraphDef(); // First replace all special whitespace chars by a space parseCmd = script.replace( '\n', ' ' ).replace( '\r', ' ' ).replace( '\t', ' ' ).toCharArray(); while ( nextToken() > 0 ) { System.err.println( token ); switch ( parseToken( token ) ) { case TKN_RRDTOOL: // We don't care about this token break; case TKN_GRAPH: // Next token is the filename nextToken(); break; case TKN_START: // Next token is the start time nextToken(); startTime = Long.parseLong( token ); break; case TKN_END: // Next token is the end time nextToken(); stopTime = Long.parseLong( token ); break; case TKN_NOMINOR: // Hide the entire minor grid graphDef.setMinorGridX( false ); graphDef.setMinorGridY( false ); break; case TKN_WIDTH: // Next token is graph pixel width nextToken(); width = Integer.parseInt( token ); break; case TKN_HEIGHT: // Next token is graph pixel height nextToken(); height = Integer.parseInt( token ); break; case TKN_UNITS_EXP: // Next token is the units exponent value nextToken(); graphDef.setUnitsExponent( Integer.parseInt( token ) ); break; case TKN_VERT_LABEL: // Next token is the actual vertical label text nextToken(); graphDef.setVerticalLabel( unescape(token) ); break; case TKN_TITLE: // Next token is the actual title text nextToken(); graphDef.setTitle( unescape(token) ); break; case TKN_IMGFORMAT: // Next token is the file type nextToken(); if ( token.equalsIgnoreCase("gif") ) fileType = SAVE_GIF; break; case TKN_BACKGROUND: // Next token is the filename of background image nextToken(); graphDef.setBackground( unescape(token) ); break; case TKN_OVERLAY: // Next token is the filename of background image nextToken(); graphDef.setOverlay( unescape(token) ); break; case TKN_NOLEGEND: // Hide the legend graphDef.setShowLegend( false ); break; case TKN_LOWERLIMIT: // Next token is the lower limit value nextToken(); gridLower = Double.parseDouble(token); break; case TKN_UPPERLIMIT: // Next token is the upper limit value nextToken(); gridUpper = Double.parseDouble(token); break; case TKN_RIGID: // Set rigid grid gridRigid = true; break; case TKN_BASE: // Set base value nextToken(); graphDef.setBaseValue( Double.parseDouble(token) ); break; case TKN_COMMENT: parseTextCommand( TXT_COMMENT ); break; case TKN_GPRINT: parseTextCommand( TXT_GPRINT ); break; case TKN_LINE: parseGraphCommand( GRAPH_LINE ); break; case TKN_AREA: parseGraphCommand( GRAPH_AREA ); break; case TKN_STACK: parseGraphCommand( GRAPH_STACK ); break; case TKN_DEF: parseDatasource( DS_DEF ); break; case TKN_CDEF: parseDatasource( DS_CDEF ); break; case TKN_IGNORE: // Do nothing break; case TKN_UNKNOWN: throw new RrdException( "Unknown token: " + token ); } } // Set grid range if necessary if ( gridRigid || ( gridLower == Double.MAX_VALUE ) || ( gridUpper == Double.MIN_VALUE ) ) graphDef.setGridRange( gridLower, gridUpper, gridRigid ); return true; } /** * * @param type * @throws RrdException */ private void parseGraphCommand( int type ) throws RrdException { if ( type == GRAPH_LINE ) { int w = Integer.parseInt( "" + token.charAt( 4 ) ); // Get the datasource int pos = token.indexOf( '#', 6 ); int npos = token.indexOf( ':', 6 ); if ( pos < 0 ) pos = npos; String ds = ( pos > 0 ? token.substring( 6, pos ) : token.substring( 6 ) ); Color color = null; String legend = null; // Get the color if ( pos > 0 && token.charAt(pos) == '#' ) color = Color.decode( npos > 0 ? token.substring( pos, npos ) : token.substring( pos ) ); // Get the legend (if there is one) if ( npos > 0 ) legend = unescape( token.substring( npos + 1 ) ); graphDef.line( ds, color, legend, w ); } else { if ( type == GRAPH_STACK ) token = token.substring( 6 ); else token = token.substring( 5 ); int pos = token.indexOf( '#' ); int npos = token.indexOf( ':' ); String ds = ( pos > 0 ? token.substring( 0, pos ) : token.substring( 0 ) ); Color color = null; String legend = null; // Get the color if ( pos > 0 && token.charAt(pos) == '#' ) color = Color.decode( npos > 0 ? token.substring( pos, npos ) : token.substring( pos ) ); // Get the legend (if there is one) if ( npos > 0 ) legend = unescape( token.substring( npos + 1 ) ); if ( type == GRAPH_AREA ) graphDef.area( ds, color, legend ); else if ( type == GRAPH_STACK ) graphDef.stack( ds, color, legend ); } } /** * * @param text * @return */ private String unescape( String text ) { if ( text.startsWith( "'" ) || text.startsWith( "\"" ) ) return text.substring( 1, text.length() - 1 ); return text; } /** * * @param type * @throws RrdException */ private void parseTextCommand( int type ) throws RrdException { int pos = token.indexOf( ':' ); if ( type == TXT_COMMENT ) { String text = unescape( token.substring( pos + 1 ) ); graphDef.comment( text ); } else if ( type == TXT_GPRINT ) { // GPRINT:vname:CF:format int npos = token.indexOf( ':', ++pos ); String ds = token.substring( pos, npos ); pos = token.indexOf( ':', ++npos ); String cf = token.substring( npos, pos ); String text = unescape( token.substring( pos + 1 ) ); // Change the placeholder to JRobin //graphDef.gprint( ds, cf, text ); } } /** * * @param type * @throws RrdException */ private void parseDatasource( int type ) throws RrdException { // Fetch the name of the datasource int pos = token.indexOf( ':' ); int npos = token.indexOf( '=', ++pos ); String name = token.substring( pos, npos ); if ( type == DS_DEF ) { // DEF:vname=rrd:ds-name:CF token = token.substring( npos + 1 ); // Fetch reverse pos = token.lastIndexOf( ':' ); String cf = token.substring( pos + 1 ); npos = token.lastIndexOf( ':', pos - 1 ); String dsName = token.substring( npos + 1, pos ); String rrdFile = token.substring( 0, npos ); graphDef.datasource( name, rrdFile, dsName, cf ); } else { // CDEF:vname=rpn-expression graphDef.datasource( name, token.substring( npos + 1 ) ); } } /** * Reads the next token in the rrdtool script. * * @return */ private int nextToken() { char[] tknChars = new char[512]; int charPos = 0; int cmdPos = tokenPos; boolean found = false; boolean stringComplete = true; char findChar = ' '; /* * This will read from the current position, till the next whitespace. * However, if it encounters a " or a ' that is not escaped, it will read until the next matching character. */ while ( charPos < 512 && (cmdPos < parseCmd.length) && !found ) { if ( parseCmd[cmdPos] == '"' ) { if ( stringComplete ) { stringComplete = false; findChar = '"'; } else if ( findChar == '"' && !(parseCmd[cmdPos - 1] == '\\') ) stringComplete = true; } else if ( parseCmd[cmdPos] == '\'' ) { if ( stringComplete ) { stringComplete = false; findChar = '\''; } else if ( findChar == '\'' && !(parseCmd[cmdPos - 1] == '\\') ) stringComplete = true; } if ( stringComplete && parseCmd[cmdPos] == ' ' ) found = true; else tknChars[charPos++] = parseCmd[cmdPos++]; } token = new String( tknChars, 0, charPos ).trim(); tokenPos = cmdPos + 1; return charPos; } /** * * @param token * @return */ private int parseToken( String token ) { if ( token.equalsIgnoreCase("rrdtool") ) return TKN_RRDTOOL; if ( token.equalsIgnoreCase("graph") ) return TKN_GRAPH; if ( token.equalsIgnoreCase("--start") || token.equals("-s") ) return TKN_START; if ( token.equalsIgnoreCase("--end") || token.equals("-e") ) return TKN_END; if ( token.equalsIgnoreCase("--width") || token.equals("-w") ) return TKN_WIDTH; if ( token.equalsIgnoreCase("--height") || token.equals("-h") ) return TKN_HEIGHT; if ( token.equalsIgnoreCase("--no-minor") ) return TKN_NOMINOR; if ( token.equalsIgnoreCase("--units-exponent") || token.equals("-X") ) return TKN_UNITS_EXP; if ( token.equalsIgnoreCase("--vertical-label") || token.equals("-v") ) return TKN_VERT_LABEL; if ( token.equalsIgnoreCase("--imgformat") || token.equals("-a") ) return TKN_IMGFORMAT; if ( token.equalsIgnoreCase("--background") || token.equals("-B") ) return TKN_BACKGROUND; if ( token.equalsIgnoreCase("--overlay") || token.equals("-O") ) return TKN_OVERLAY; if ( token.equalsIgnoreCase("--title") || token.equals("-t") ) return TKN_TITLE; if ( token.equalsIgnoreCase("--step") || token.equals("-S") ) return TKN_STEP; if ( token.equalsIgnoreCase("--no-legend") || token.equals("-g") ) return TKN_NOLEGEND; if ( token.equalsIgnoreCase("--base") || token.equals("-b") ) return TKN_BASE; if ( token.equalsIgnoreCase("--lower-limit") || token.equals("-l") ) return TKN_LOWERLIMIT; if ( token.equalsIgnoreCase("--upper-limit") || token.equals("-u") ) return TKN_UPPERLIMIT; if ( token.equalsIgnoreCase("--rigid") || token.equals("-r") ) return TKN_RIGID; if ( token.startsWith("COMMENT") ) return TKN_COMMENT; if ( token.startsWith("GPRINT") ) return TKN_GPRINT; if ( token.startsWith("LINE") ) return TKN_LINE; if ( token.startsWith("AREA") ) return TKN_AREA; if ( token.startsWith("STACK") ) return TKN_STACK; if ( token.startsWith("HRULE") ) return TKN_HRULE; if ( token.startsWith("VRULE") ) return TKN_VRULE; if ( token.startsWith("CDEF") ) return TKN_CDEF; if ( token.startsWith("DEF") ) return TKN_DEF; if ( token.equals("-Y") || token.equals("--alt-y-grid") || token.equals("-R") || token.equals("--alt-y-mrtg") || token.equals("-A") || token.equals("--alt-autoscale") || token.equals("-M") || token.equals("--alt-autoscale-max") || token.equals("-L") || token.equals("--units-length") || token.equals("-i") || token.equals("--interlaced") || token.equals("-f") || token.equals("--imginfo") || token.equals("-o") || token.equals("--logarithmic") || token.equals("-j") || token.equals("--only-graph") || token.equals("-F") || token.equals("--force-rules-legend") || token.startsWith("PRINT") || token.equals("-U") || token.startsWith("--unit") ) return TKN_IGNORE; return TKN_UNKNOWN; } public static void main( String[] args ) throws Exception { String str = "rrdtool graph FNAME --start 100 --end 700\n" + "DEF:inOctets=c:/file.rrd:test-run:AVERAGE " + "CDEF:bitIn=inOctets,8,* " + "COMMENT:'commentaar \"nr\" 1'\n" + "AREA:test#ffa9b3:'this is the legend'\n" + "COMMENT:\"commentaar 'nr' 2\"\n" + "LINE2:test2:'this is the legend two' " + "GPRINT:bitIn:AVG:'Average %2.5'"; RrdtoolGraph rg = new RrdtoolGraph( str ); rg.getRrdGraphDef(); } } Index: RpnCalculator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RpnCalculator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RpnCalculator.java 30 Mar 2004 22:57:44 -0000 1.2 --- RpnCalculator.java 30 May 2004 19:49:56 -0000 1.3 *************** *** 333,338 **** return pop(); } ! ! // ================================================================ // -- Private methods --- 333,338 ---- return pop(); } ! ! // ================================================================ // -- Private methods Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ValueGrid.java 26 Apr 2004 22:28:33 -0000 1.7 --- ValueGrid.java 30 May 2004 19:49:56 -0000 1.8 *************** *** 127,133 **** return; ! if ( upper == Double.NaN || upper == Double.MIN_VALUE || upper == Double.MAX_VALUE ) upper = 0.9; ! if ( lower == Double.NaN || lower == Double.MAX_VALUE || lower == Double.MIN_VALUE ) lower = 0; --- 127,133 ---- return; ! if ( Double.isNaN(upper) || upper == Double.MIN_VALUE || upper == Double.MAX_VALUE ) upper = 0.9; ! if ( Double.isNaN(lower) || lower == Double.MAX_VALUE || lower == Double.MIN_VALUE ) lower = 0; Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdGraph.java 21 Apr 2004 09:48:54 -0000 1.7 --- RrdGraph.java 30 May 2004 19:49:56 -0000 1.8 *************** *** 39,46 **** --- 39,48 ---- import java.awt.image.RenderedImage; import java.awt.image.BufferedImage; + import java.awt.*; import org.jrobin.core.RrdDb; import org.jrobin.core.RrdDbPool; import org.jrobin.core.RrdException; + import org.jrobin.core.RrdBackendFactory; /** *************** *** 154,159 **** public void saveAsPNG( String path, int width, int height ) throws RrdException, IOException { ! ImageIO.write(getBufferedImage(width, height, BufferedImage.TYPE_INT_RGB), ! "png", new File(path) ); } --- 156,160 ---- public void saveAsPNG( String path, int width, int height ) throws RrdException, IOException { ! ImageIO.write( getBufferedImage(width, height, BufferedImage.TYPE_INT_RGB), "png", new File(path) ); } *************** *** 188,192 **** stream.close(); - } --- 189,192 ---- *************** *** 270,274 **** return outputStream.toByteArray(); } ! /** * Returns graph with default chart dimensions (400 by 100) as an array of JPEG bytes. --- 270,274 ---- return outputStream.toByteArray(); } ! /** * Returns graph with default chart dimensions (400 by 100) as an array of JPEG bytes. *************** *** 351,360 **** return bStream.toByteArray(); } ! /** * Returns panel object so that graph can be easily embedded in swing applications. * @return Swing JPanel object with graph embedded in panel. */ ! public JPanel getChartPanel() throws RrdException, IOException { ChartPanel p = new ChartPanel(); --- 351,374 ---- return bStream.toByteArray(); } ! ! /** ! * Returns the underlying BufferedImage of a graph with custom dimensions. ! * Specifying 0 for both width and height will result in a auto-sized graph. ! * @param width Width of the chart area in pixels. ! * @param height Height of the chart area in pixels. ! * @return BufferedImage containing the graph. ! * @throws IOException Thrown in case of I/O error. ! * @throws RrdException Thrown in case of JRobin specific error. ! */ ! public BufferedImage getBufferedImage( int width, int height ) throws IOException, RrdException ! { ! return getBufferedImage( width, height, BufferedImage.TYPE_INT_RGB ); ! } ! /** * Returns panel object so that graph can be easily embedded in swing applications. * @return Swing JPanel object with graph embedded in panel. */ ! public ChartPanel getChartPanel() throws RrdException, IOException { ChartPanel p = new ChartPanel(); *************** *** 363,376 **** return p; } ! // ================================================================ // -- Protected (package) methods // ================================================================ ! RrdDb getRrd( String rrdFile ) throws IOException, RrdException { if ( pool != null ) return pool.requestRrdDb( rrdFile ); ! else ! return new RrdDb( rrdFile, true ); } --- 377,407 ---- return p; } ! ! /** ! * Renders the graph onto a specified Graphics2D object. ! * Specifying 0 for both width and height will result in a auto-sized graph. ! * @param graphics Handle to a Graphics2D object to render the graph on. ! * @param width Width of the chart area in pixels. ! * @param height Height of the chart area in pixels. ! * @throws RrdException Thrown in case of JRobin specific error. ! * @throws IOException Thrown in case of I/O error ! */ ! public void renderImage( Graphics2D graphics, int width, int height ) throws RrdException, IOException ! { ! if ( useImageSize ) ! grapher.renderImage( width, height, graphics, true ); ! else ! grapher.renderImage( width, height, graphics, false ); ! } ! // ================================================================ // -- Protected (package) methods // ================================================================ ! RrdDb getRrd( String rrdFile, RrdBackendFactory backendFactory ) throws IOException, RrdException { if ( pool != null ) return pool.requestRrdDb( rrdFile ); ! else ! return new RrdDb( rrdFile, true, backendFactory ); } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RrdGraphDef.java 29 Apr 2004 10:17:21 -0000 1.11 --- RrdGraphDef.java 30 May 2004 19:49:56 -0000 1.12 *************** *** 29,37 **** import java.awt.Color; import java.awt.BasicStroke; ! import java.util.Date; ! import java.util.Vector; ! import java.util.HashMap; ! import java.util.Iterator; ! import java.util.GregorianCalendar; import java.text.SimpleDateFormat; --- 29,33 ---- import java.awt.Color; import java.awt.BasicStroke; ! import java.util.*; import java.text.SimpleDateFormat; *************** *** 113,125 **** // -- Non-settable members private int numDefs = 0; // number of Def datasources added private int commentLines = 0; // number of complete lines in the list of comment items private int commentLineShift = 0; // modifier to add to get minimum one complete line of comments ! private HashMap fetchSources = new HashMap(); // holds the list of FetchSources ! private Vector cdefList = new Vector(); // holds the list of Cdef datasources ! private Vector pdefList = new Vector(); // holds the list of Plottable datasources ! private Vector plotDefs = new Vector(); // holds the list of PlotDefs ! private Vector comments = new Vector(); // holds the list of comment items --- 109,122 ---- // -- Non-settable members + private int numSdefs = 0; private int numDefs = 0; // number of Def datasources added private int commentLines = 0; // number of complete lines in the list of comment items private int commentLineShift = 0; // modifier to add to get minimum one complete line of comments ! private HashMap fetchSources = new HashMap( 10 ); // holds the list of FetchSources ! private ArrayList cdefList = new ArrayList( 10 ); // holds the list of Cdef datasources ! private ArrayList pdefList = new ArrayList( 10 ); // holds the list of Plottable datasources ! private ArrayList plotDefs = new ArrayList( 10 ); // holds the list of PlotDefs ! private ArrayList comments = new ArrayList( 10 ); // holds the list of comment items *************** *** 620,629 **** * can be used:</p> * <ul> ! * <li>To specify sources for line, area and stack plots. * <li>To define complex graph sources * (see {@link #datasource(java.lang.String, java.lang.String) complex graph ! * source definition}). * <li>To specify graph data source for the ! * {@link #gprint(java.lang.String, java.lang.String, java.lang.String) gprint()} method. * @param name Graph source name. * @param file Path to RRD file. --- 617,628 ---- * can be used:</p> * <ul> ! * <li>To specify sources for line, area and stack plots.</li> * <li>To define complex graph sources * (see {@link #datasource(java.lang.String, java.lang.String) complex graph ! * source definition}).</li> * <li>To specify graph data source for the ! * {@link #gprint(java.lang.String, java.lang.String, java.lang.String) gprint()} method.</li> ! * </ul> ! * * @param name Graph source name. * @param file Path to RRD file. *************** *** 643,647 **** numDefs++; } ! /** * <p>Adds complex graph source with the given name to the graph definition. --- 642,679 ---- numDefs++; } ! ! /** ! * <p>Adds simple graph source to graph definition. Graph source <code>name</code> ! * can be used:</p> ! * <ul> ! * <li>To specify sources for line, area and stack plots.</li> ! * <li>To define complex graph sources ! * (see {@link #datasource(java.lang.String, java.lang.String) complex graph ! * source definition}).</li> ! * <li>To specify graph data source for the ! * {@link #gprint(java.lang.String, java.lang.String, java.lang.String) gprint()} method.</li> ! * </ul> ! * ! * @param name Graph source name. ! * @param file Path to RRD file. ! * @param dsName Data source name defined in the RRD file. ! * @param consolFunc Consolidation function that will be used to extract data from the RRD ! * file ("AVERAGE", "MIN", "MAX" or "LAST"). ! * @param backend Name of the RrdBackendFactory that should be used for this RrdDb. ! */ ! public void datasource( String name, String file, String dsName, String consolFunc, String backend ) throws RrdException ! { ! if ( fetchSources.containsKey(file) ) ! { ! FetchSource rf = (FetchSource) fetchSources.get(file); ! rf.setBackendFactory( backend ); ! rf.addSource( consolFunc, dsName, name ); ! } ! else ! fetchSources.put( file, new FetchSource(file, consolFunc, dsName, name, backend ) ); ! ! numDefs++; ! } ! /** * <p>Adds complex graph source with the given name to the graph definition. *************** *** 662,665 **** --- 694,698 ---- * <p>For more details on RPN see RRDTool's * <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/manual/rrdgraph.html" target="man">rrdgraph man page</a>.</p> + * * @param name Graph source name. * @param rpn RPN expression containig comma delmited simple and complex graph *************** *** 670,674 **** cdefList.add( new Cdef(name, rpn) ); } ! /** * <p>Adds a custom graph source with the given name to the graph definition. --- 703,722 ---- cdefList.add( new Cdef(name, rpn) ); } ! ! /** ! * <p>Adds static graph source with the given name to the graph definition. ! * Static graph sources are the result of a consolidation function applied ! * to *any* other graph source that has been defined previously.</p> ! * ! * @param name Graph source name. ! * @param defName Name of the datasource to calculate the value from. ! * @param consolFunc Consolidation function to use for value calculation ! */ ! public void datasource( String name, String defName, String consolFunc ) throws RrdException ! { ! cdefList.add( new Sdef(name, defName, consolFunc) ); ! numSdefs++; ! } ! /** * <p>Adds a custom graph source with the given name to the graph definition. *************** *** 1020,1026 **** fs.exportXml(xml); } ! // cdefs for (int i = 0; i < cdefList.size(); i++ ) { ! Cdef cdef = (Cdef) cdefList.elementAt(i); cdef.exportXml(xml); } --- 1068,1074 ---- fs.exportXml(xml); } ! // cdefs and sdefs for (int i = 0; i < cdefList.size(); i++ ) { ! Cdef cdef = (Cdef) cdefList.get(i); cdef.exportXml(xml); } *************** *** 1029,1036 **** for ( int i = 0; i < comments.size(); i++ ) { ! Comment cmt = (Comment) comments.elementAt(i); if ( cmt.commentType == Comment.CMT_LEGEND || cmt.commentType == Comment.CMT_NOLEGEND) { ! PlotDef pDef = (PlotDef) plotDefs.elementAt( ((Legend) cmt).getPlofDefIndex() ); pDef.exportXmlTemplate(xml, cmt.text); } --- 1077,1084 ---- for ( int i = 0; i < comments.size(); i++ ) { ! Comment cmt = (Comment) comments.get(i); if ( cmt.commentType == Comment.CMT_LEGEND || cmt.commentType == Comment.CMT_NOLEGEND) { ! PlotDef pDef = (PlotDef) plotDefs.get( ((Legend) cmt).getPlofDefIndex() ); pDef.exportXmlTemplate(xml, cmt.text); } *************** *** 1048,1053 **** --- 1096,1112 ---- /** + * Exports RrdGraphDef (graph definition) object in XML format to string. + * Generated code can be parsed with {@link RrdGraphDefTemplate} class + * {@see exportXmlTemplate). + * + * @return String representing graph definition in XML format + */ + public String getXmlTemplate() { + return exportXmlTemplate(); + } + /** * Exports RrdGraphDef (graph definition) object in XML format to string. * Generated code can be parsed with {@link RrdGraphDefTemplate} class. + * * @return String representing graph definition in XML format */ *************** *** 1061,1064 **** --- 1120,1124 ---- * Exports RrdGraphDef (graph definition) object in XML format to file. * Generated code can be parsed with {@link RrdGraphDefTemplate} class. + * * @param filePath destination file */ *************** *** 1257,1261 **** return (Pdef[]) pdefList.toArray( new Pdef[] {} ); } ! protected HashMap getFetchSources() { --- 1317,1326 ---- return (Pdef[]) pdefList.toArray( new Pdef[] {} ); } ! ! protected int getNumSdefs() ! { ! return numSdefs; ! } ! protected HashMap getFetchSources() { Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Grapher.java 21 Apr 2004 09:49:01 -0000 1.10 --- Grapher.java 30 May 2004 19:49:56 -0000 1.11 *************** *** 144,156 **** // ================================================================ /** ! * Creates the actual graph based on the GraphDef definition. ! * The graph is created as a <code>java.awt.image.BufferedImage</code>. * @param cWidth Width of the chart area in pixels. * @param cHeight Height of the chart area in pixels. - * @return The created graph as a BufferedImage. - * @throws RrdException Thrown in case of a JRobin specific error. - * @throws IOException Thrown in case of a I/O related error. */ ! protected BufferedImage createImage( int cWidth, int cHeight, int colorType ) throws RrdException, IOException { // Calculate chart dimensions --- 144,152 ---- // ================================================================ /** ! * Calculates the graph and chart dimensions. * @param cWidth Width of the chart area in pixels. * @param cHeight Height of the chart area in pixels. */ ! private void calculateDimensions( int cWidth, int cHeight ) { // Calculate chart dimensions *************** *** 163,216 **** chart_lpadding = ( graphDef.showMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM ); chart_bpadding = ( graphDef.showMajorGridX() ? CHART_BPADDING : CHART_BPADDING_NM ); ! // Size of all lines below chart commentBlock = 0; if ( graphDef.showLegend() ) ! commentBlock = graphDef.getCommentLineCount() * (nfont_height + LINE_PADDING) - LINE_PADDING; ! ! // x_offset and y_offset define the starting corner of the actual graph x_offset = LBORDER_SPACE; ! if ( graphDef.getVerticalLabel() != null ) x_offset += nfont_height + LINE_PADDING; imgWidth = chartWidth + x_offset + RBORDER_SPACE + chart_lpadding + CHART_RPADDING; ! y_offset = UBORDER_SPACE; ! if ( graphDef.getTitle() != null ) // Title *always* gets a extra LF automatically y_offset += ((tfont_height + LINE_PADDING) * graphDef.getTitle().getLineCount() + tfont_height) + LINE_PADDING; imgHeight = chartHeight + commentBlock + y_offset + BBORDER_SPACE + CHART_UPADDING + CHART_BPADDING; - - // Create graphics object - BufferedImage bImg = new BufferedImage( imgWidth, imgHeight, colorType ); - Graphics2D graphics = (Graphics2D) bImg.getGraphics(); - - // Do the actual graphing - calculateSeries(); // calculate all datasources - - plotImageBackground( graphics ); // draw the image background - - plotChart( graphics ); // draw the actual chart - - plotComments( graphics ); // draw all comment lines - - plotOverlay( graphics ); // draw a possible image overlay - - plotSignature( graphics ); // draw the JRobin signature - - // Dispose graphics context - graphics.dispose(); - - return bImg; } ! /** ! * Creates the actual graph based on the GraphDef definition. ! * The graph is created as a <code>java.awt.image.BufferedImage</code>. * @param cWidth Width of the entire image in pixels. * @param cHeight Height of the entire image in pixels. - * @return The created graph as a BufferedImage. - * @throws RrdException Thrown in case of a JRobin specific error. - * @throws IOException Thrown in case of a I/O related error. */ ! protected BufferedImage createImageGlobal( int cWidth, int cHeight, int colorType ) throws RrdException, IOException { imgWidth = cWidth; --- 159,186 ---- chart_lpadding = ( graphDef.showMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM ); chart_bpadding = ( graphDef.showMajorGridX() ? CHART_BPADDING : CHART_BPADDING_NM ); ! // Size of all lines below chart commentBlock = 0; if ( graphDef.showLegend() ) ! commentBlock = graphDef.getCommentLineCount() * (nfont_height + LINE_PADDING) - LINE_PADDING; ! ! // x_offset and y_offset define the starting corner of the actual graph x_offset = LBORDER_SPACE; ! if ( graphDef.getVerticalLabel() != null ) x_offset += nfont_height + LINE_PADDING; imgWidth = chartWidth + x_offset + RBORDER_SPACE + chart_lpadding + CHART_RPADDING; ! y_offset = UBORDER_SPACE; ! if ( graphDef.getTitle() != null ) // Title *always* gets a extra LF automatically y_offset += ((tfont_height + LINE_PADDING) * graphDef.getTitle().getLineCount() + tfont_height) + LINE_PADDING; imgHeight = chartHeight + commentBlock + y_offset + BBORDER_SPACE + CHART_UPADDING + CHART_BPADDING; } ! /** ! * Calculates the graph and chart dimensions. * @param cWidth Width of the entire image in pixels. * @param cHeight Height of the entire image in pixels. */ ! private void calculateDimensionsGlobal( int cWidth, int cHeight ) { imgWidth = cWidth; *************** *** 222,266 **** chart_lpadding = ( graphDef.showMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM ); chart_bpadding = ( graphDef.showMajorGridX() ? CHART_BPADDING : CHART_BPADDING_NM ); ! // Size of all lines below chart commentBlock = 0; if ( graphDef.showLegend() ) ! commentBlock = graphDef.getCommentLineCount() * (nfont_height + LINE_PADDING) - LINE_PADDING; ! // x_offset and y_offset define the starting corner of the actual graph x_offset = LBORDER_SPACE; ! if ( graphDef.getVerticalLabel() != null ) x_offset += nfont_height + LINE_PADDING; chartWidth = imgWidth - x_offset - RBORDER_SPACE - chart_lpadding - CHART_RPADDING; ! y_offset = UBORDER_SPACE; ! if ( graphDef.getTitle() != null ) // Title *always* gets a extra LF automatically y_offset += ((tfont_height + LINE_PADDING) * graphDef.getTitle().getLineCount() + tfont_height) + LINE_PADDING; chartHeight = imgHeight - commentBlock - y_offset - BBORDER_SPACE - CHART_UPADDING - CHART_BPADDING; ! // Create graphics object BufferedImage bImg = new BufferedImage( imgWidth, imgHeight, colorType ); Graphics2D graphics = (Graphics2D) bImg.getGraphics(); ! // Do the actual graphing calculateSeries(); // calculate all datasources ! plotImageBackground( graphics ); // draw the image background ! plotChart( graphics ); // draw the actual chart ! plotComments( graphics ); // draw all comment lines ! plotOverlay( graphics ); // draw a possible image overlay plotSignature( graphics ); // draw the JRobin signature ! // Dispose graphics context graphics.dispose(); - - return bImg; } ! ! // ================================================================ // -- Private methods --- 192,308 ---- chart_lpadding = ( graphDef.showMajorGridY() ? graphDef.getChartLeftPadding() : CHART_LPADDING_NM ); chart_bpadding = ( graphDef.showMajorGridX() ? CHART_BPADDING : CHART_BPADDING_NM ); ! // Size of all lines below chart commentBlock = 0; if ( graphDef.showLegend() ) ! commentBlock = graphDef.getCommentLineCount() * (nfont_height + LINE_PADDING) - LINE_PADDING; ! // x_offset and y_offset define the starting corner of the actual graph x_offset = LBORDER_SPACE; ! if ( graphDef.getVerticalLabel() != null ) x_offset += nfont_height + LINE_PADDING; chartWidth = imgWidth - x_offset - RBORDER_SPACE - chart_lpadding - CHART_RPADDING; ! y_offset = UBORDER_SPACE; ! if ( graphDef.getTitle() != null ) // Title *always* gets a extra LF automatically y_offset += ((tfont_height + LINE_PADDING) * graphDef.getTitle().getLineCount() + tfont_height) + LINE_PADDING; chartHeight = imgHeight - commentBlock - y_offset - BBORDER_SPACE - CHART_UPADDING - CHART_BPADDING; ! } ! ! /** ! * Creates the actual graph based on the GraphDef definition. ! * The graph is created as a <code>java.awt.image.BufferedImage</code>. ! * @param cWidth Width of the chart area in pixels. ! * @param cHeight Height of the chart area in pixels. ! * @return The created graph as a BufferedImage. ! * @throws RrdException Thrown in case of a JRobin specific error. ! * @throws IOException Thrown in case of a I/O related error. ! */ ! protected BufferedImage createImage( int cWidth, int cHeight, int colorType ) throws RrdException, IOException ! { ! calculateDimensions( cWidth, cHeight ); ! // Create graphics object BufferedImage bImg = new BufferedImage( imgWidth, imgHeight, colorType ); Graphics2D graphics = (Graphics2D) bImg.getGraphics(); ! ! render( graphics ); ! ! // Dispose graphics context ! graphics.dispose(); ! ! return bImg; ! } ! ! /** ! * Creates the actual graph based on the GraphDef definition. ! * The graph is created as a <code>java.awt.image.BufferedImage</code>. ! * @param cWidth Width of the entire image in pixels. ! * @param cHeight Height of the entire image in pixels. ! * @return The created graph as a BufferedImage. ! * @throws RrdException Thrown in case of a JRobin specific error. ! * @throws IOException Thrown in case of a I/O related error. ! */ ! protected BufferedImage createImageGlobal( int cWidth, int cHeight, int colorType ) throws RrdException, IOException ! { ! calculateDimensionsGlobal( cWidth, cHeight ); ! ! // Create graphics object ! BufferedImage bImg = new BufferedImage( imgWidth, imgHeight, colorType ); ! Graphics2D graphics = (Graphics2D) bImg.getGraphics(); ! ! render( graphics ); ! ! // Dispose graphics context ! graphics.dispose(); ! ! return bImg; ! } ! ! /** ! * Creates the actual graph based on the GraphDef definition. ! * The graph is rendered on the Graphics2D object passed as a parameter. ! * @param cWidth Width of the entire image in pixels. ! * @param cHeight Height of the entire image in pixels. ! * @param graphics The handle to the Graphics2D object to render the graph on. ! * @param useGlobal True if the dimensions specified are those of the entire image. ! * @throws RrdException Thrown in case of a JRobin specific error. ! * @throws IOException Thrown in case of a I/O related error. ! */ ! protected void renderImage( int cWidth, int cHeight, Graphics2D graphics, boolean useGlobal ) throws RrdException, IOException ! { ! if ( useGlobal ) ! calculateDimensionsGlobal( cWidth, cHeight ); ! else ! calculateDimensions( cWidth, cHeight ); ! ! render( graphics ); ! } ! ! /** ! * Renders the actual graph onto the specified Graphics2D object ! * @param graphics The handle to the Graphics2D object to render the graph on. ! * @throws RrdException Thrown in case of a JRobin specific error. ! * @throws IOException Thrown in case of a I/O related error. ! */ ! private void render( Graphics2D graphics ) throws RrdException, IOException ! { // Do the actual graphing calculateSeries(); // calculate all datasources ! plotImageBackground( graphics ); // draw the image background ! plotChart( graphics ); // draw the actual chart ! plotComments( graphics ); // draw all comment lines ! plotOverlay( graphics ); // draw a possible image overlay plotSignature( graphics ); // draw the JRobin signature ! // Dispose graphics context graphics.dispose(); } ! // ================================================================ // -- Private methods *************** *** 277,280 **** --- 319,323 ---- RrdDb rrd; String[] varList; + long finalEndTime = 0; boolean changingEndTime = false; *************** *** 285,289 **** int numDefs = graphDef.getNumDefs(); ! Cdef[] cdefList = graphDef.getCdefs(); int numCdefs = cdefList.length; --- 328,333 ---- int numDefs = graphDef.getNumDefs(); ! int numSdefs = graphDef.getNumSdefs(); ! Cdef[] cdefList = graphDef.getCdefs(); int numCdefs = cdefList.length; *************** *** 291,295 **** Pdef[] pdefList = graphDef.getPdefs(); int numPdefs = pdefList.length; ! // Set up the array with all datasources (both Def, Cdef and Pdef) sourc... [truncated message content] |