From: Arne V. <cob...@us...> - 2004-07-10 00:07:26
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11053/org/jrobin/graph Modified Files: ExportData.java Grapher.java Pdef.java RrdExport.java RrdExportDef.java RrdExporter.java RrdGraphDef.java Source.java ValueAxisUnit.java ValueGrid.java Log Message: JRobin 1.4.0 - Value grid tweaking - Fixed graph generation - Modified setExportData into addExportData on RrdExportDef level - Added getStep() to RrdDataSet interface Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ValueAxisUnit.java 9 Jul 2004 12:22:15 -0000 1.6 --- ValueAxisUnit.java 10 Jul 2004 00:07:03 -0000 1.7 *************** *** 175,184 **** long lmMod = lmValue % lmGridStep; ! /*if ( ovalue < 0 ) { ! } else ! {*/ if ( lmMod < ( mGridStep * 0.5 ) ) return ((double) (sign*lmValue - lmMod) / mGridFactor); --- 175,189 ---- long lmMod = lmValue % lmGridStep; ! if ( ovalue < 0 ) { ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) (sign*lmValue + lmMod - lmGridStep ) / mGridFactor); ! else if ( lMod > 0 ) ! return ((double) (sign*lValue + lMod - lGridStep) / gridFactor); ! else ! return ((double) (sign*lValue - lGridStep) / gridFactor); } else ! { if ( lmMod < ( mGridStep * 0.5 ) ) return ((double) (sign*lmValue - lmMod) / mGridFactor); *************** *** 187,191 **** else return ((double) (sign*lValue) / gridFactor); ! //} } --- 192,196 ---- else return ((double) (sign*lValue) / gridFactor); ! } } *************** *** 225,232 **** long lmMod = lmValue % lmGridStep; ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) ( sign * lmValue - lmMod + lmGridStep) / mGridFactor); else ! return ((double) ( sign * lValue - lMod + lGridStep) / gridFactor); } --- 230,248 ---- long lmMod = lmValue % lmGridStep; ! if ( ovalue < 0 ) ! { ! if ( lmMod < ( mGridStep * 0.5 ) ) ! return ((double) (sign*lmValue + lmMod ) / mGridFactor); ! else ! return ((double) (sign*lValue + lMod ) / gridFactor); ! } else ! { ! if ( lmMod > ( mGridStep * 0.5 ) ) ! return ((double) ( sign * lmValue - lmMod + lmGridStep) / mGridFactor); ! else ! return ((double) ( sign * lValue - lMod + lGridStep) / gridFactor); ! } ! } Index: RrdExporter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExporter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExporter.java 9 Jul 2004 12:22:15 -0000 1.1 --- RrdExporter.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 26,33 **** import java.io.IOException; - import java.io.File; - import java.io.OutputStream; import java.util.HashMap; ! import java.awt.*; import org.jrobin.core.*; --- 26,31 ---- import java.io.IOException; import java.util.HashMap; ! import java.util.ArrayList; import org.jrobin.core.*; *************** *** 111,117 **** int numPdefs = pdefList.length; // Set up the array with all datasources (both Def, Cdef and Pdef) ! sources = new Source[ numDefs + numCdefs + numPdefs ]; ! sourceIndex = new HashMap( numDefs + numCdefs + numPdefs ); int tblPos = 0; int vePos = 0; --- 109,144 ---- int numPdefs = pdefList.length; + ExportData[] edata = def.getExportData(); + int[] edefTs; + Source[] edefList; + if ( edata.length > 0 ) + { + ArrayList tsList = new ArrayList( 30 ); + ArrayList list = new ArrayList( 30 ); + for ( int i = 0; i < edata.length; i++ ) + { + Source[] esrc = edata[i].getSources(); + + for ( int j = 0; j < esrc.length; j++ ) + { + list.add( esrc[j] ); + tsList.add( new Integer(i) ); + } + } + edefTs = new int[ tsList.size() ]; + for ( int i = 0; i < edefTs.length; i++ ) + edefTs[i] = ((Integer) tsList.get(i)).intValue(); + edefList = (Source[]) list.toArray( new Source[] {} ); + } + else + { + edefTs = new int[0]; + edefList = new Source[0]; + } + int numEdefs = edefList.length; + // Set up the array with all datasources (both Def, Cdef and Pdef) ! sources = new Source[ numDefs + numEdefs + numCdefs + numPdefs ]; ! sourceIndex = new HashMap( numDefs + numEdefs + numCdefs + numPdefs ); int tblPos = 0; int vePos = 0; *************** *** 125,130 **** long minStep = Integer.MAX_VALUE, maxStep = Integer.MIN_VALUE, vStartTime, vEndTime, fetchEndTime; ! // Open all datasources ! if ( fetchSources.size() > 0 ) { try --- 152,157 ---- long minStep = Integer.MAX_VALUE, maxStep = Integer.MIN_VALUE, vStartTime, vEndTime, fetchEndTime; ! // -- Open all fetch datasources ! if ( fetchSources.size() > 0 || numEdefs > 0 ) { try *************** *** 148,152 **** // Calculate the step for data retrieval ! long[] steps = src.getFetchStep( startTime, endTime, def.getResolution() ); int reduceFactor = (int) Math.ceil( (double) requestedStep / (double) steps[0] ); --- 175,179 ---- // Calculate the step for data retrieval ! long[] steps = src.getFetchStep( startTime, endTime, def.getResolution() ); int reduceFactor = (int) Math.ceil( (double) requestedStep / (double) steps[0] ); *************** *** 162,165 **** --- 189,208 ---- } + for ( int i = 0; i < edata.length; i++ ) + { + long step = edata[i].getStep(); + + int reduceFactor = (int) Math.ceil( (double) requestedStep / (double) step ); + step = step * reduceFactor; + + if ( step < minStep ) + { + minStep = step; + minReduceFactor = reduceFactor; + } + if ( step > maxStep ) + maxStep = step; + } + vStartTime = Util.normalize( startTime, minStep ); vStartTime = ( vStartTime > startTime ? vStartTime - minStep : vStartTime ); *************** *** 218,224 **** { // The range should be used exactly as specified ! minStep = requestedStep; ! vStartTime = Util.normalize( startTime, minStep ); ! vStartTime = ( vStartTime > startTime ? vStartTime - minStep : vStartTime ); if ( !changingEndTime ) --- 261,267 ---- { // The range should be used exactly as specified ! minStep = requestedStep; ! vStartTime = Util.normalize( startTime, minStep ); ! vStartTime = ( vStartTime > startTime ? vStartTime - minStep : vStartTime ); if ( !changingEndTime ) *************** *** 238,244 **** reducedNumRows = (int) ((reducedEndTime - reducedStartTime) / reducedStep) + 1; finalEndTime = endTime; } ! // Add all Pdefs to the source table for ( int i = 0; i < pdefList.length; i++ ) { --- 281,298 ---- reducedNumRows = (int) ((reducedEndTime - reducedStartTime) / reducedStep) + 1; finalEndTime = endTime; + + vEndTime += minStep; + numRows = (int) ((vEndTime - vStartTime) / minStep) + 1; } ! // -- Add all Export datasources to the source table ! for ( int i = 0; i < edefList.length; i++ ) ! { ! sources[tblPos] = new Def( edefList[i].getName(), numRows, reducedNumRows ); ! sources[tblPos].setFetchedStep( edefList[i].getStep() ); ! sourceIndex.put( edefList[i].getName(), new Integer(tblPos++) ); ! } ! ! // -- Add all Pdefs to the source table for ( int i = 0; i < pdefList.length; i++ ) { *************** *** 252,256 **** int cdefStart = tblPos; // First Cdef element, necessary for tree descend calculation ! // Add all Cdefs to the source table // Reparse all RPN datasources to use indices of the correct variables for ( int i = 0; i < cdefList.length; i++ ) --- 306,310 ---- int cdefStart = tblPos; // First Cdef element, necessary for tree descend calculation ! // -- Add all Cdefs to the source table // Reparse all RPN datasources to use indices of the correct variables for ( int i = 0; i < cdefList.length; i++ ) *************** *** 322,325 **** --- 376,384 ---- pos = veList[j].extract( t, sources, i, pos ); + // Get all export datasources + for (int j = pos; j < pos + numEdefs; j++ ) + sources[j].set( i, t, edefList[j - pos].get( t, edata[ edefTs[j - pos] ].getTimestamps() ) ); + pos += numEdefs; + // Get all custom datasources for (int j = pos; j < pos + numPdefs; j++) *************** *** 360,363 **** --- 419,427 ---- pos = veList[j].extract( t, sources, i, pos ); + // Get all export datasources + for (int j = pos; j < pos + numEdefs; j++ ) + sources[j].set( i, t, edefList[j - pos].get( t, edata[ edefTs[j - pos] ].getTimestamps() ) ); + pos += numEdefs; + // Get all custom datasources for (int j = pos; j < pos + numPdefs; j++) Index: Pdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Pdef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Pdef.java 9 Jul 2004 12:22:15 -0000 1.4 --- Pdef.java 10 Jul 2004 00:07:03 -0000 1.5 *************** *** 53,56 **** --- 53,57 ---- * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. + * * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class extending Plottable and providing the datapoints. *************** *** 65,68 **** --- 66,70 ---- * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. + * * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class extending Plottable and providing the datapoints. *************** *** 80,83 **** --- 82,86 ---- * Constructs a new Plottable Def: a custom external datasource * (represented as a Plottable class) that can be graphed by JRobin. + * * @param name Name of the datasource in the graph definition. * @param plottable Reference to the class extending Plottable and providing the datapoints. *************** *** 98,101 **** --- 101,105 ---- /** * Prepares the array that will hold the values. + * * @param numPoints Number of datapoints that will be used. */ *************** *** 112,115 **** --- 116,120 ---- * Sets the value of a specific datapoint for this Pdef. The Pdef gets the datapoint by retrieving * the value from the Plottable interface using an appropriate getValue() method. + * * @param pos Position (index in the value table) of the new datapoint. * @param timestamp Timestamp of the new datapoint in number of seconds. *************** *** 118,129 **** { double val = Double.NaN; ! if ( indexed ) ! val = plottable.getValue( timestamp, index ); else if ( named ) ! val = plottable.getValue( timestamp, sourceName ); else ! val = plottable.getValue( timestamp ); ! super.set( pos, timestamp, val ); --- 123,141 ---- { double val = Double.NaN; ! ! /** ! * With the new calculation algorithm we expect the value for a period to be defined ! * by the first timestamp AFTER that period. The implementation of Pdef is different, ! * and works with 'point' value instead of period. Converted to period this would mean ! * that the period is defined by the starting timestamp, or another timestamp IN that ! * period. As a result, we shift the requested timestamp one step back in time. ! */ if ( indexed ) ! val = plottable.getValue( timestamp - step, index ); else if ( named ) ! val = plottable.getValue( timestamp - step, sourceName ); else ! val = plottable.getValue( timestamp - step ); ! super.set( pos, timestamp, val ); Index: ExportData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ExportData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExportData.java 9 Jul 2004 12:22:15 -0000 1.1 --- ExportData.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 72,75 **** --- 72,82 ---- } + /** + * Create an ExportData object based on export XML string.. + * + * @param xportXml File containing export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( String xportXml ) throws RrdException, IOException { *************** *** 79,82 **** --- 86,97 ---- } + /** + * Create an ExportData object based on export XML string.. + * + * @param xportXml File containing export xml. + * @param useLegendNames Map datasources to legend items in the export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( String xportXml, boolean useLegendNames ) throws RrdException, IOException { *************** *** 86,89 **** --- 101,111 ---- } + /** + * Create an ExportData object based on export XML file. + * + * @param xmlFile File containing export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( File xmlFile ) throws RrdException, IOException { *************** *** 93,96 **** --- 115,126 ---- } + /** + * Create an ExportData object based on export XML file. + * + * @param xmlFile File containing export xml. + * @param useLegendNames Map datasources to legend items in the export xml. + * @throws RrdException Thrown in case of JRobin specific exception. + * @throws IOException Thrown in case of I/O related exception. + */ public ExportData( File xmlFile, boolean useLegendNames ) throws RrdException, IOException { *************** *** 135,138 **** --- 165,177 ---- /** + * Returns the step with which this data was fetched. + * @return Step as long. + */ + public long getStep() + { + return timestamps[1] - timestamps[0]; + } + + /** * Returns all values for a single datasource, the returned values * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method. Index: RrdExport.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExport.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExport.java 9 Jul 2004 12:22:15 -0000 1.1 --- RrdExport.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 31,35 **** /** ! * <p>ExportData represents a reduced dataset that is the result of a JRobin rrd export.</p> * * @author Arne Vandamme (cob...@jr...) --- 31,39 ---- /** ! * <p>RrdExport can be used to export graph-like datasources to XML format, ! * by means of the ExportData object. More information about Export can be ! * found in the RRDtool XPORT man page.</p> ! * ! * <p>RrdExport needs a RrdExportDef that holds the configuration.</p> * * @author Arne Vandamme (cob...@jr...) *************** *** 40,44 **** // -- Members // ================================================================ ! private int maxRows = 400; // Default width of a graph --- 44,48 ---- // -- Members // ================================================================ ! private int maxRows = 400; // Default width of a graph Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Source.java 9 Jul 2004 12:22:15 -0000 1.9 --- Source.java 10 Jul 2004 00:07:03 -0000 1.10 *************** *** 56,60 **** private double nextValue = Double.POSITIVE_INFINITY; ! private long step = 0; private long lastTime = 0; private long totalTime = 0; --- 56,60 ---- private double nextValue = Double.POSITIVE_INFINITY; ! protected long step = 0; private long lastTime = 0; private long totalTime = 0; *************** *** 110,114 **** double get( int pos ) { ! if ( pos < 0 ) return Double.NaN; double val = values[pos]; --- 110,117 ---- double get( int pos ) { ! if ( pos < 0 ) ! return Double.NaN; ! if ( pos > values.length ) ! return Double.NaN; double val = values[pos]; *************** *** 155,159 **** } ! if ( stPos < reducedTimestamps.length && reducedTimestamps[stPos] <= t ) return get( stPos ); --- 158,162 ---- } ! if ( t <= reducedTimestamps[stPos] ) return get( stPos ); Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Grapher.java 9 Jul 2004 12:22:15 -0000 1.16 --- Grapher.java 10 Jul 2004 00:07:03 -0000 1.17 *************** *** 310,317 **** { // Do the actual graphing ! if ( graphDef.useExportData() ) ! calculateSeries( graphDef.getExportData() ); ! else ! calculateSeries(); // calculate all datasources plotImageBackground( graphics ); // draw the image background --- 310,314 ---- { // Do the actual graphing ! calculateSeries(); // calculate all datasources plotImageBackground( graphics ); // draw the image background *************** *** 367,413 **** /** - * Calculates graphing values based on a ExportData object. - * - * @param dataSet ExportData holding the values. - * @throws RrdException Thrown in case of a JRobin specific error. - * @throws IOException Thrown in case of a I/O related error. - */ - private void calculateSeries( ExportData dataSet ) throws RrdException, IOException - { - numPoints = dataSet.getRowCount(); - - startTime = graphDef.getStartTime(); - endTime = graphDef.getEndTime(); - - tsChart = new long[ chartWidth ]; - plotDefs = graphDef.getPlotDefs(); - - timestamps = dataSet.getTimestamps(); - sources = dataSet.getSources(); - sourceIndex = new HashMap( sources.length ); - - for ( int i = 0; i < sources.length; i++ ) - sourceIndex.put( sources[i].getName(), new Integer(i) ); - - for ( int i = 0; i < plotDefs.length; i++ ) - { - plotDefs[i].setSource( sources, sourceIndex ); - plotDefs[i].prepareValues( chartWidth ); - } - - for ( int i = 0; i < chartWidth; i++ ) - { - long t = (long) (startTime + i * ((endTime - startTime) / (double) (chartWidth - 1))); - - for ( int j = 0; j < plotDefs.length; j++ ) - plotDefs[j].setValue( i, t, timestamps ); - - tsChart[i] = t; - } - - - } - - /** * Draws the image background, title and value axis label. * @param g Handle of a Graphics2D context to draw on. --- 364,367 ---- *************** *** 580,587 **** int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[chartWidth]; // Pre calculate x positions of the corresponding timestamps ! int[] xValues = new int[tsChart.length]; for (int i = 0; i < tsChart.length; i++) xValues[i] = g.getX(tsChart[i]); --- 534,541 ---- int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[tsChart.length]; // Pre calculate x positions of the corresponding timestamps ! int[] xValues = new int[tsChart.length]; for (int i = 0; i < tsChart.length; i++) xValues[i] = g.getX(tsChart[i]); Index: RrdExportDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExportDef.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdExportDef.java 9 Jul 2004 12:22:15 -0000 1.1 --- RrdExportDef.java 10 Jul 2004 00:07:03 -0000 1.2 *************** *** 66,70 **** protected ArrayList cdefList = new ArrayList( 10 ); // holds the list of Cdef datasources protected ArrayList exportList = new ArrayList( 10 ); // holds the list of datasources to export ! // ================================================================ --- 66,70 ---- protected ArrayList cdefList = new ArrayList( 10 ); // holds the list of Cdef datasources protected ArrayList exportList = new ArrayList( 10 ); // holds the list of datasources to export ! protected ArrayList edefList = new ArrayList( 3 ); // holds the list of export data objects // ================================================================ *************** *** 309,312 **** --- 309,322 ---- /** + * Adds a set of ExportData to the datasource list. + * + * @param edata ExportData to add. + */ + public void addExportData( ExportData edata ) + { + edefList.add( edata ); + } + + /** * Sets a specific datasource to be exported (if export is strict). * The expor legend for this datasource will be empty. *************** *** 387,390 **** --- 397,405 ---- } + protected ExportData[] getExportData() + { + return (ExportData[]) edefList.toArray( new ExportData[] {} ); + } + protected int getNumSdefs() { Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ValueGrid.java 9 Jul 2004 12:22:15 -0000 1.9 --- ValueGrid.java 10 Jul 2004 00:07:03 -0000 1.10 *************** *** 161,169 **** // Create nice grid based on 'fixed' ranges ! if ( shifted <= 1.5 ) vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 3 ) vAxis = new ValueAxisUnit( 0.2 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 5 ) vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else --- 161,169 ---- // Create nice grid based on 'fixed' ranges ! if ( shifted <= 2 ) vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 4 ) vAxis = new ValueAxisUnit( 0.2 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); ! else if ( shifted <= 6 ) vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 1.0 * mod * scaleValues[scaleIndex] ); else Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RrdGraphDef.java 9 Jul 2004 12:22:15 -0000 1.17 --- RrdGraphDef.java 10 Jul 2004 00:07:03 -0000 1.18 *************** *** 105,109 **** private ValueAxisUnit vAxis = null; // custom value axis grid, defaults to no custom private GridRange gridRange = null; // custom value range definition, defaults to auto-scale - private ExportData exportData = null; // possible export data set to use for graphing // -- Non-settable members --- 105,108 ---- *************** *** 177,188 **** } - public void setExportData( ExportData dataSet ) { - exportData = dataSet; - } - - public void setUseExportData( boolean flag ) { - useExportDataFlag = flag; - } - /** * Sets graph title. --- 176,179 ---- *************** *** 978,989 **** return lazyGeneration; } - - protected boolean useExportData() { - return useExportDataFlag; - } - - protected ExportData getExportData() { - return exportData; - } protected Title getTitle() { --- 969,972 ---- |