|
From: Arne V. <cob...@us...> - 2004-03-30 23:09:42
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17048/src/org/jrobin/graph Modified Files: RpnCalculator.java RrdGraph.java Grapher.java ValueGrid.java ValueAxisUnit.java Source.java Cdef.java Log Message: JRobin 1.3.1 - Changed ValueGrid for different base values - Added SAMPLES and STEP RPN constants Index: RpnCalculator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RpnCalculator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RpnCalculator.java 7 Nov 2003 08:23:19 -0000 1.1 --- RpnCalculator.java 30 Mar 2004 22:57:44 -0000 1.2 *************** *** 81,85 **** --- 81,88 ---- public static final byte TKN_OR = 37; public static final byte TKN_XOR = 38; + public static final byte TKN_SAMPLES = 39; + public static final byte TKN_STEP = 40; + private double step; private Source[] sources; private ArrayList stack = new ArrayList(); *************** *** 92,99 **** * Constructs a RPN calculator object by providing the source array to use for value lookups. * @param sources Table containing all retrieved datasources of the graph definition. */ ! RpnCalculator( Source[] sources ) { ! this.sources = sources; } --- 95,104 ---- * Constructs a RPN calculator object by providing the source array to use for value lookups. * @param sources Table containing all retrieved datasources of the graph definition. + * @param step Time in seconds that one sample represents. */ ! RpnCalculator( Source[] sources, double step ) { ! this.sources = sources; ! this.step = step; } *************** *** 312,315 **** --- 317,328 ---- push(((x1 != 0 && x2 == 0) || (x1 == 0 && x2 != 0))? 1: 0); break; + + case TKN_SAMPLES: + push( cdef.getSampleCount() ); + break; + + case TKN_STEP: + push( step ); + break; } } Index: ValueAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueAxisUnit.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ValueAxisUnit.java 1 Mar 2004 08:50:25 -0000 1.3 --- ValueAxisUnit.java 30 Mar 2004 22:57:45 -0000 1.4 *************** *** 42,53 **** // -- Members // ================================================================ - - private double gridStep = 2; - private double labelStep = 10; // ================================================================ // -- Constructors ! // ================================================================ /** * Creates a ValueAxisUnit based on a minor and major grid step. --- 42,52 ---- // -- Members // ================================================================ + private double gridStep = 2; + private double labelStep = 10; // ================================================================ // -- Constructors ! // ================================================================ /** * Creates a ValueAxisUnit based on a minor and major grid step. *************** *** 60,66 **** { this.gridStep = gridStep; ! this.labelStep = labelStep; } ! double getGridStep() { return gridStep; --- 59,65 ---- { this.gridStep = gridStep; ! this.labelStep = labelStep; } ! double getGridStep() { return gridStep; *************** *** 84,89 **** ValueMarker[] getValueMarkers( double lower, double upper ) { ! double minPoint = 0.0d; ! double majPoint = 0.0d; // Find the first visible gridpoint --- 83,88 ---- ValueMarker[] getValueMarkers( double lower, double upper ) { ! double minPoint = 0.0d; ! double majPoint = 0.0d; // Find the first visible gridpoint Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ValueGrid.java 11 Nov 2003 11:44:11 -0000 1.3 --- ValueGrid.java 30 Mar 2004 22:57:45 -0000 1.4 *************** *** 39,42 **** --- 39,47 ---- private double upper; + private double baseValue = ValueFormatter.DEFAULT_BASE; + private double[] scaleValues = new double[] { + 1e18, 1e15, 1e12, 1e9, 1e6, 1e3, 1e0, 1e-3, 1e-6, 1e-9, 1e-12, 1e-15 + }; + private ValueAxisUnit vAxis; *************** *** 55,59 **** * ValueAxisUnit is null, one will be automatically determined. */ ! ValueGrid( GridRange gr, double low, double up, ValueAxisUnit vAxis ) { double grLower = Double.MAX_VALUE; --- 60,64 ---- * ValueAxisUnit is null, one will be automatically determined. */ ! ValueGrid( GridRange gr, double low, double up, ValueAxisUnit vAxis, double base ) { double grLower = Double.MAX_VALUE; *************** *** 70,73 **** --- 75,91 ---- this.upper = up; this.vAxis = vAxis; + baseValue = base; + + // Fill in the scale values + double tmp = 1; + for (int i = 1; i < 7; i++) { + tmp *= baseValue; + scaleValues[6 - i] = tmp; + } + tmp = 1; + for (int i = 7; i < scaleValues.length; i++) { + tmp *= baseValue; + scaleValues[i] = ( 1 / tmp ); + } // Set an appropriate value axis it not given yet *************** *** 122,146 **** shifted = upper; double mod = 1.0; ! while ( shifted > 10 ) { shifted /= 10; ! mod *= 10; } ! while ( shifted < 1 ) { shifted *= 10; ! mod /= 10; } ! // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) ! vAxis = new ValueAxisUnit( 0.1*mod, 0.5*mod ); else if ( shifted <= 3 ) ! vAxis = new ValueAxisUnit( 0.2*mod, 1.0*mod ); else if ( shifted <= 5 ) ! vAxis = new ValueAxisUnit( 0.5*mod, 1.0*mod ); else if ( shifted <= 9 ) ! vAxis = new ValueAxisUnit( 0.5*mod, 2.0*mod ); else ! vAxis = new ValueAxisUnit( 1.0*mod, 5.0*mod ); } } --- 140,181 ---- shifted = upper; + // Find the scaled unit for this range double mod = 1.0; ! int scaleIndex = scaleValues.length - 1; ! while ( scaleIndex >= 0 && scaleValues[scaleIndex] < shifted ) ! scaleIndex--; ! ! // Keep the rest of division ! double left = shifted % scaleValues[scaleIndex + 1]; ! shifted = shifted / scaleValues[++scaleIndex]; ! ! // While rest > 10, divide by 10 ! while ( shifted > 10.0 ) { shifted /= 10; ! mod *= 10; } ! ! while ( shifted < 1.0 ) { shifted *= 10; ! mod /= 10; } ! ! left = left / scaleValues[scaleIndex]; ! if ( left > 0.9 || left == 0.00 ) { ! scaleIndex--; ! mod = 1.0; ! } ! // 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 if ( shifted <= 9 ) ! vAxis = new ValueAxisUnit( 0.5 * mod * scaleValues[scaleIndex], 2.0 * mod * scaleValues[scaleIndex] ); else ! vAxis = new ValueAxisUnit( 0.1 * mod * scaleValues[scaleIndex], 0.5 * mod * scaleValues[scaleIndex] ); } } Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Grapher.java 1 Mar 2004 12:02:46 -0000 1.7 --- Grapher.java 30 Mar 2004 22:57:45 -0000 1.8 *************** *** 352,359 **** sourceIndex.put( cdefList[i].getName(), new Integer(tblPos++) ); } ! ! // RPN calculator for the Cdefs ! RpnCalculator rpnCalc = new RpnCalculator( sources ); ! // Fill the array for all datasources timestamps = new long[numPoints]; --- 352,356 ---- sourceIndex.put( cdefList[i].getName(), new Integer(tblPos++) ); } ! // Fill the array for all datasources timestamps = new long[numPoints]; *************** *** 364,370 **** } for (int i = 0; i < numPoints; i++) { ! long t = (long) (startTime + i * ((endTime - startTime) / (double)(numPoints - 1))); int pos = 0; --- 361,370 ---- } + // RPN calculator for the Cdefs + RpnCalculator rpnCalc = new RpnCalculator( sources, (endTime - startTime) / (double) numPoints ); + for (int i = 0; i < numPoints; i++) { ! long t = (long) (startTime + i * ((endTime - startTime) / (double) (numPoints - 1))); int pos = 0; *************** *** 521,525 **** } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); --- 521,525 ---- } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Source.java 15 Jan 2004 22:24:30 -0000 1.4 --- Source.java 30 Mar 2004 22:57:45 -0000 1.5 *************** *** 139,142 **** --- 139,146 ---- } + long getSampleCount() { + return ( values != null ? values.length : 0 ); + } + // ================================================================ Index: Cdef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Cdef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Cdef.java 1 Mar 2004 08:50:25 -0000 1.4 --- Cdef.java 30 Mar 2004 22:57:45 -0000 1.5 *************** *** 179,182 **** --- 179,187 ---- else if ( tkn.equals("XOR") ) tokens[i] = RpnCalculator.TKN_XOR; + // Extra tokens for JRobin + else if ( tkn.equals("SAMPLES") ) + tokens[i] = RpnCalculator.TKN_SAMPLES; + else if ( tkn.equals("STEP") ) + tokens[i] = RpnCalculator.TKN_STEP; else throw new RrdException("Unknown token enocuntered: " + tkn); Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdGraph.java 11 Mar 2004 13:54:25 -0000 1.5 --- RrdGraph.java 30 Mar 2004 22:57:45 -0000 1.6 *************** *** 76,80 **** /** * Constructs a new JRobin graph object. ! * @param usePool True if this should object should use RrdDbPool */ public RrdGraph( boolean usePool ) --- 76,80 ---- /** * Constructs a new JRobin graph object. ! * @param usePool True if this object should use RrdDbPool */ public RrdGraph( boolean usePool ) |