Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv964/src/org/jrobin/graph Modified Files: Gprint.java RrdGraphDefTemplate.java RrdGraphDef.java TimeAxisUnit.java ValueGrid.java ValueFormatter.java Source.java Log Message: JRobin 1.3.1 - Improved Value Grid calculation - Updated RrdGraph for read-only opening of RRD files - Added STEP and SAMPLES rpn values - Added first_day_of_week XML option for time_axis node - Added gprint overload with specific base value - Added TOTAL aggregate for datasources - Improved graph XML parsing (legend and comments do not get trimmed any longer) Index: ValueFormatter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueFormatter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ValueFormatter.java 7 Nov 2003 14:42:02 -0000 1.2 --- ValueFormatter.java 26 Apr 2004 22:28:33 -0000 1.3 *************** *** 207,211 **** * @param scaleIndex Forced index of the SI unit in the <code>PREFIXES</code> table. <code>NO_SCALE</code> if not forced. */ ! private void scaleValue( int scaleIndex) { double absValue = Math.abs(value); --- 207,211 ---- * @param scaleIndex Forced index of the SI unit in the <code>PREFIXES</code> table. <code>NO_SCALE</code> if not forced. */ ! private void scaleValue( int scaleIndex ) { double absValue = Math.abs(value); Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ValueGrid.java 21 Apr 2004 09:49:01 -0000 1.6 --- ValueGrid.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 147,151 **** // Keep the rest of division - double left = shifted % scaleValues[scaleIndex + 1]; shifted = shifted / scaleValues[++scaleIndex]; --- 147,150 ---- *************** *** 161,173 **** } - left = left / scaleValues[scaleIndex]; - - - if ( left == 0.00 ) { - scaleIndex--; - mod = 1.0; - } - - // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) --- 160,163 ---- Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdGraphDefTemplate.java 8 Mar 2004 13:14:39 -0000 1.4 --- RrdGraphDefTemplate.java 26 Apr 2004 22:28:33 -0000 1.5 *************** *** 96,99 **** --- 96,101 ---- * <date_format>HH:mm</date_format> * <center_labels>true</center_labels> + * <!-- ALLOWED DAYS OF WEEK: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY --> + * <first_day_of_week>MONDAY</first_day_of_week> * </time_axis> * <time_axis_label>time</time_axis_label> *************** *** 357,373 **** String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend"); rrdGraphDef.stack(datasource, color, legend); } else if(nodeName.equals("comment")) { ! String comment = getValue(childs[i]); rrdGraphDef.comment(comment); } else if(nodeName.equals("gprint")) { ! validateTagsOnlyOnce(childs[i], new String[] { "datasource", "cf", "format" }); ! String datasource = getChildValue(childs[i], "datasource"); ! String consolFun = getChildValue(childs[i], "cf"); ! String format = getChildValue(childs[i], "format"); ! rrdGraphDef.gprint(datasource, consolFun, format); } else if(nodeName.equals("hrule")) { --- 359,379 ---- String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend", false); rrdGraphDef.stack(datasource, color, legend); } else if(nodeName.equals("comment")) { ! String comment = getValue(childs[i], false); rrdGraphDef.comment(comment); } else if(nodeName.equals("gprint")) { ! validateTagsOnlyOnce(childs[i], new String[] { "datasource", "cf", "format", "base" }); ! String datasource = getChildValue(childs[i], "datasource"); ! String consolFun = getChildValue(childs[i], "cf"); ! String format = getChildValue(childs[i], "format", false ); ! ! if ( !hasChildNode(childs[i], "base") ) ! rrdGraphDef.gprint( datasource, consolFun, format ); ! else ! rrdGraphDef.gprint( datasource, consolFun, format, getChildValueAsDouble(childs[i], "base") ); } else if(nodeName.equals("hrule")) { *************** *** 376,380 **** String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend"); int width = 1; try { --- 382,386 ---- String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend", false); int width = 1; try { *************** *** 389,393 **** String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend"); int width = 1; try { --- 395,399 ---- String colorStr = getChildValue(childs[i], "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(childs[i], "legend", false); int width = 1; try { *************** *** 406,410 **** String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend"); // line width is not mandatory int width = 1; --- 412,416 ---- String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend", false); // line width is not mandatory int width = 1; *************** *** 427,431 **** String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend"); int width = 1; try { --- 433,437 ---- String colorStr = getChildValue(lineNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(lineNode, "legend", false); int width = 1; try { *************** *** 446,450 **** String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend"); rrdGraphDef.area(datasource, color, legend); } --- 452,456 ---- String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend", false); rrdGraphDef.area(datasource, color, legend); } *************** *** 462,466 **** String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend"); rrdGraphDef.area(gc1, v1, gc2, v2, color, legend); } --- 468,472 ---- String colorStr = getChildValue(areaNode, "color"); Color color = Color.decode(colorStr); ! String legend = getChildValue(areaNode, "legend", false); rrdGraphDef.area(gc1, v1, gc2, v2, color, legend); } *************** *** 645,657 **** validateTagsOnlyOnce(optionNode, new String[] { "min_grid_time_unit", "min_grid_unit_steps", "maj_grid_time_unit", ! "maj_grid_unit_steps", "date_format", "center_labels" }); ! int unit1 = resolveUnit(getChildValue(optionNode, "min_grid_time_unit")); ! int step1 = getChildValueAsInt(optionNode, "min_grid_unit_steps"); ! int unit2 = resolveUnit(getChildValue(optionNode, "maj_grid_time_unit")); ! int step2 = getChildValueAsInt(optionNode, "maj_grid_unit_steps"); ! String format = getChildValue(optionNode, "date_format"); ! boolean center = getChildValueAsBoolean(optionNode, "center_labels"); ! rrdGraphDef.setTimeAxis(unit1, step1, unit2, step2, format, center); } // TIME AXIS LABEL --- 651,674 ---- validateTagsOnlyOnce(optionNode, new String[] { "min_grid_time_unit", "min_grid_unit_steps", "maj_grid_time_unit", ! "maj_grid_unit_steps", "date_format", "center_labels", "first_day_of_week" }); ! ! if ( hasChildNode( optionNode, "min_grid_time_unit" ) ) ! { ! int unit1 = resolveUnit(getChildValue(optionNode, "min_grid_time_unit")); ! int step1 = getChildValueAsInt(optionNode, "min_grid_unit_steps"); ! int unit2 = resolveUnit(getChildValue(optionNode, "maj_grid_time_unit")); ! int step2 = getChildValueAsInt(optionNode, "maj_grid_unit_steps"); ! String format = getChildValue(optionNode, "date_format"); ! boolean center = getChildValueAsBoolean(optionNode, "center_labels"); ! rrdGraphDef.setTimeAxis(unit1, step1, unit2, step2, format, center); ! } ! ! // Determine first day of the week ! if ( hasChildNode( optionNode, "first_day_of_week" ) ) ! { ! int dow = resolveDayUnit( getChildValue(optionNode, "first_day_of_week") ); ! rrdGraphDef.setFirstDayOfWeek( dow ); ! } } // TIME AXIS LABEL *************** *** 721,724 **** --- 738,769 ---- } } + + private int resolveDayUnit( String unit ) { + if ( unit.equalsIgnoreCase("monday") ) { + return TimeAxisUnit.MONDAY; + } + else if ( unit.equalsIgnoreCase("tuesday") ) { + return TimeAxisUnit.TUESDAY; + } + else if ( unit.equalsIgnoreCase("wednesday") ) { + return TimeAxisUnit.WEDNESDAY; + } + else if ( unit.equalsIgnoreCase("thursday") ) { + return TimeAxisUnit.THURSDAY; + } + else if ( unit.equalsIgnoreCase("friday") ) { + return TimeAxisUnit.FRIDAY; + } + else if ( unit.equalsIgnoreCase("saturday") ) { + return TimeAxisUnit.SATURDAY; + } + else if ( unit.equalsIgnoreCase("sunday") ) { + return TimeAxisUnit.SUNDAY; + } + else { + throw new IllegalArgumentException( "Invalid day unit specified: " + unit ); + } + + } private void resolveSpan(Node spanNode) throws RrdException { Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Source.java 19 Apr 2004 22:35:00 -0000 1.6 --- Source.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 55,59 **** private long lastTime = 0; private long totalTime = 0; - double testval = 0; // ================================================================ --- 55,58 ---- *************** *** 129,133 **** case AGG_TOTAL: ! return testval; } --- 128,132 ---- case AGG_TOTAL: ! return totalValue; } *************** *** 164,168 **** { long timeDelta = time - lastTime; ! testval += value; totalValue += timeDelta * ( value + lastValue ) / 2.0; totalTime += timeDelta; --- 163,167 ---- { long timeDelta = time - lastTime; ! totalValue += timeDelta * ( value + lastValue ) / 2.0; totalTime += timeDelta; Index: TimeAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TimeAxisUnit.java 21 Apr 2004 09:49:01 -0000 1.6 --- TimeAxisUnit.java 26 Apr 2004 22:28:33 -0000 1.7 *************** *** 69,72 **** --- 69,76 ---- "SECOND", "MINUTE", "HOUR", "DAY", "WEEK", "MONTH", "YEAR" }; + + private static final String[] DAY_NAMES = { + "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" + }; private int minGridTimeUnit = HOUR; // minor grid *************** *** 282,285 **** --- 286,293 ---- return UNIT_NAMES[unit]; } + + static String getDayName( int dayIndex ) { + return DAY_NAMES[dayIndex]; + } void exportXmlTemplate(XmlWriter xml) { *************** *** 291,294 **** --- 299,306 ---- xml.writeTag("date_format", getDateFormat().toPattern()); xml.writeTag("center_labels", getCenterLabels()); + + if ( firstDayOfWeek != MONDAY ) + xml.writeTag( "first_day_of_week", getDayName(firstDayOfWeek) ); + xml.closeTag(); // time_axis } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdGraphDef.java 21 Apr 2004 09:48:58 -0000 1.9 --- RrdGraphDef.java 26 Apr 2004 22:28:33 -0000 1.10 *************** *** 916,919 **** --- 916,937 ---- addComment( new Gprint(sourceName, consolFun, format) ); } + + /** + * <p>See the {@link #gprint(java.lang.String, java.lang.String, java.lang.String) gprint()} method for more details. + * This gprint implementation allows a specific base value to be specified for this particular gprint only, the specified + * base value can be different than the global base value used through the entire graph for the drawing. The resulting value of the gprint + * will be formatted according to the specified base value. + * </p> + * + * @param sourceName Graph source name + * @param consolFun Consolidation function to be used for calculation ("AVERAGE", "MIN", "MAX" or "LAST") + * @param format Format string. For example: "speed is @5.2 @sbits/sec@c", "temperature = @0 degrees" + * @param base Base value for the formatting, defaults to the graphing base value + * @throws RrdException Thrown in case of JRobin specific error + */ + public void gprint( String sourceName, String consolFun, String format, double base ) throws RrdException + { + addComment( new Gprint(sourceName, consolFun, format, base) ); + } /** Index: Gprint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Gprint.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Gprint.java 19 Apr 2004 22:35:00 -0000 1.4 --- Gprint.java 26 Apr 2004 22:28:33 -0000 1.5 *************** *** 52,55 **** --- 52,56 ---- private int numDec = 3; // Show 3 decimal values by default private int strLen = -1; + private double baseValue = -1; // Default: use global base value private boolean normalScale = false; private boolean uniformScale = false; *************** *** 62,67 **** * Constructs a Gprint object based on a string of text (with a specific placement * marker in), a source from which to retrieve a value, and a consolidation function that ! * specifies which value to retrieve. Possible consolidation functions are <code>AVERAGE, MAX, MIN, FIRST</code> ! * and <code>LAST</code>. * @param sourceName Name of the datasource from which to retrieve the consolidated value. * @param consolFunc Consolidation function to use. --- 63,68 ---- * Constructs a Gprint object based on a string of text (with a specific placement * marker in), a source from which to retrieve a value, and a consolidation function that ! * specifies which value to retrieve. Possible consolidation functions are <code>AVERAGE, MAX, MIN, FIRST, LAST</code> ! * and <code>TOTAL</code>. * @param sourceName Name of the datasource from which to retrieve the consolidated value. * @param consolFunc Consolidation function to use. *************** *** 94,97 **** --- 95,116 ---- } + /** + * Constructs a Gprint object based on a string of text (with a specific placement + * marker in), a source from which to retrieve a value, and a consolidation function that + * specifies which value to retrieve. Possible consolidation functions are <code>AVERAGE, MAX, MIN, FIRST</code> + * and <code>LAST</code>. + * @param sourceName Name of the datasource from which to retrieve the consolidated value. + * @param consolFunc Consolidation function to use. + * @param text String of text with a placement marker for the resulting value. + * @param base Base value to use for formatting the value that needs to be printed. + * @throws RrdException Thrown in case of a JRobin specific error. + */ + Gprint( String sourceName, String consolFunc, String text, double base ) throws RrdException + { + this( sourceName, consolFunc, text ); + + baseValue = base; + } + // ================================================================ *************** *** 114,117 **** --- 133,141 ---- double value = sources[ ((Integer) sourceIndex.get(sourceName)).intValue() ].getAggregate( aggregate ); + // See if we need to use a specific value for the formatting + double oldBase = vFormat.getBase(); + if ( baseValue != -1 ) + vFormat.setBase( baseValue ); + vFormat.setFormat( value, numDec, strLen ); vFormat.setScaling( normalScale, uniformScale ); *************** *** 131,134 **** --- 155,162 ---- oList.set( i, str ); } + + // Reset the base value of the formatter + if ( baseValue != -1 ) + vFormat.setBase( oldBase ); } catch (Exception e) { *************** *** 183,186 **** --- 211,216 ---- xml.writeTag("cf", Source.aggregates[aggregate]); xml.writeTag("format", text); + if ( baseValue != -1 ) + xml.writeTag( "base", baseValue ); xml.closeTag(); // gprint } |