From: <cob...@us...> - 2003-10-22 22:08:05
|
Update of /cvsroot/jrobin/src/jrobin/graph2 In directory sc8-pr-cvs1:/tmp/cvs-serv999/src/jrobin/graph2 Modified Files: RpnCalculator.java Stack.java Grapher.java Area.java ChartGraphics.java RrdGraphDef.java PlotDef.java ValueFormatter.java Added Files: CustomLine.java CustomArea.java Log Message: New graph lib Add support for custom plotdefs Finalized some features --- NEW FILE: CustomLine.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package jrobin.graph2; import java.awt.Color; import java.awt.BasicStroke; import java.util.HashMap; import jrobin.core.RrdException; /** * <p>description</p> * * @author Arne Vandamme (arn...@jr...) */ class CustomLine extends PlotDef { private long xVal1; private long xVal2; private double yVal1; private double yVal2; private double dc; CustomLine( long startTime, double startValue, long endTime, double endValue, Color color ) { this.color = color; if ( color == null ) visible = false; this.xVal1 = startTime; this.xVal2 = endTime; this.yVal1 = startValue; this.yVal2 = endValue; try { long xc = xVal2 - xVal1; if ( xc != 0 ) this.dc = ( yVal2 - yVal1 ) / xc; else this.dc = 0; } catch (Exception e) { this.dc = 0; } } CustomLine( long startTime, double startValue, long endTime, double endValue, Color color, int lineWidth ) { this( startTime, startValue, endTime, endValue, color ); this.lineWidth = lineWidth; } void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); g.setStroke( new BasicStroke(lineWidth) ); int ax, ay, nx, ny; // Get X positions if ( xVal1 == Long.MIN_VALUE ) ax = g.getMinX(); else if ( xVal1 == Long.MAX_VALUE ) ax = g.getMaxX(); else ax = g.getX( xVal1 ); if ( xVal2 == Long.MIN_VALUE ) nx = g.getMinX(); else if ( xVal2 == Long.MAX_VALUE ) nx = g.getMaxX(); else nx = g.getX( xVal2 ); // Get Y positions if ( yVal1 == Double.MIN_VALUE ) ay = g.getMinY(); else if ( yVal1 == Double.MAX_VALUE ) ay = g.getMaxY(); else ay = g.getY( yVal1 ); if ( yVal2 == Double.MIN_VALUE ) ny = g.getMinY(); else if ( yVal2 == Double.MAX_VALUE ) ny = g.getMaxY(); else ny = g.getY( yVal2 ); // Draw the line if ( visible ) g.drawLine( ax, ay, nx, ny ); // Set the stackvalues int rx = nx - ax; if ( rx != 0 ) { double rc = ((ny - ay) * 1.0d) / rx; for (int i = 0; i < xValues.length; i++) { if ( xValues[i] < ax || xValues[i] > nx ) stackValues[i] = 0; else if ( ay == ny ) stackValues[i] = ay; else stackValues[i] = new Double(rc * (xValues[i] - ax) + ay).intValue(); } } g.setStroke( new BasicStroke() ); } double getValue( int tblPos, long[] timestamps ) { long time = timestamps[tblPos]; // Out of range if ( time > xVal2 || time < xVal1 ) return Double.NaN; // Hrule if ( yVal1 == yVal2 ) return yVal1; // Vrule if ( yVal1 == Double.MIN_VALUE && yVal2 == Double.MAX_VALUE ) return Double.NaN; // No line, very rare, will usually be 'out of range' first if ( xVal1 == xVal2 ) return Double.NaN; // Custom line return ( dc * ( time - xVal1 ) + yVal1 ); } void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { // Stub } } --- NEW FILE: CustomArea.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.jrobin.org * Project Lead: Sasa Markovic (sa...@jr...) * * Developers: Sasa Markovic (sa...@jr...) * Arne Vandamme (cob...@jr...) * * (C) Copyright 2003, by Sasa Markovic. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. */ package jrobin.graph2; import java.awt.Color; import java.util.HashMap; import jrobin.core.RrdException; /** * <p>description</p> * * @author Arne Vandamme (arn...@jr...) */ class CustomArea extends PlotDef { private long xVal1; private long xVal2; private double yVal1; private double yVal2; CustomArea( long startTime, double startValue, long endTime, double endValue, Color color ) { this.color = color; if ( color == null ) visible = false; this.xVal1 = startTime; this.xVal2 = endTime; this.yVal1 = startValue; this.yVal2 = endValue; } void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); int ax, ay, nx, ny; // Get X positions if ( xVal1 == Long.MIN_VALUE ) ax = g.getMinX(); else if ( xVal1 == Long.MAX_VALUE ) ax = g.getMaxX(); else ax = g.getX( xVal1 ); if ( xVal2 == Long.MIN_VALUE ) nx = g.getMinX(); else if ( xVal2 == Long.MAX_VALUE ) nx = g.getMaxX(); else nx = g.getX( xVal2 ); // Get Y positions if ( yVal1 == Double.MIN_VALUE ) ay = g.getMinY(); else if ( yVal1 == Double.MAX_VALUE ) ay = g.getMaxY(); else ay = g.getY( yVal1 ); if ( yVal2 == Double.MIN_VALUE ) ny = g.getMinY(); else if ( yVal2 == Double.MAX_VALUE ) ny = g.getMaxY(); else ny = g.getY( yVal2 ); // Draw the area if ( visible ) { if ( ny > ay ) g.fillRect( ax, ay, nx, ny ); else g.fillRect( ax, ny, nx, ay ); } // Set the stackvalues // Always use the y value of the second specified point to stack on if ( yVal2 != Double.MAX_VALUE ) for (int i = 0; i < stackValues.length; i++) if ( xValues[i] < ax || xValues[i] > nx ) stackValues[i] = 0; else stackValues[i] = ny; } double getValue( int tblPos, long[] timestamps ) { long time = timestamps[tblPos]; // Out of range if ( time > xVal2 || time < xVal1 ) return Double.NaN; if ( yVal2 == Double.MAX_VALUE ) return Double.NaN; return yVal2; } void setSource( Source[] sources, HashMap sourceIndex ) throws RrdException { // Stub } } Index: RpnCalculator.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/RpnCalculator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RpnCalculator.java 21 Oct 2003 19:41:58 -0000 1.1 --- RpnCalculator.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 309,314 **** throw new RrdException("POP failed, stack empty"); ! Double lastValue = (Double) stack.get(last); ! stack.remove(last); return lastValue.doubleValue(); --- 309,313 ---- throw new RrdException("POP failed, stack empty"); ! Double lastValue = (Double) stack.remove(last); return lastValue.doubleValue(); Index: Stack.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/Stack.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Stack.java 21 Oct 2003 19:41:58 -0000 1.1 --- Stack.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 49,55 **** { if ( lastPlotType == PlotDef.PLOT_LINE ) ! stack = new PlotDef( source, color, true ); else if ( lastPlotType == PlotDef.PLOT_AREA ) ! stack = new Area( source, color, true ); stack.draw( g, xValues, stackValues, lastPlotType ); --- 49,55 ---- { if ( lastPlotType == PlotDef.PLOT_LINE ) ! stack = new PlotDef( source, color, true, visible ); else if ( lastPlotType == PlotDef.PLOT_AREA ) ! stack = new Area( source, color, true, visible ); stack.draw( g, xValues, stackValues, lastPlotType ); Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/Grapher.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Grapher.java 21 Oct 2003 19:41:58 -0000 1.1 --- Grapher.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 60,64 **** // Border space definitions private static final int UBORDER_SPACE = 10; ! private static final int BBORDER_SPACE = 10; private static final int LBORDER_SPACE = 10; private static final int RBORDER_SPACE = 10; --- 60,64 ---- // Border space definitions private static final int UBORDER_SPACE = 10; ! private static final int BBORDER_SPACE = 16; private static final int LBORDER_SPACE = 10; private static final int RBORDER_SPACE = 10; *************** *** 175,179 **** plotImageBackground( graphics ); ! plotChart( graphics ); --- 175,179 ---- plotImageBackground( graphics ); ! plotChart( graphics ); *************** *** 182,185 **** --- 182,188 ---- plotOverlay( graphics ); + + if ( graphDef.drawSignature ) + plotSignature( graphics ); } catch (IOException e) *************** *** 199,202 **** --- 202,215 ---- } + private void plotSignature( Graphics2D g ) + { + Font sigFont = new Font("Courier", Font.PLAIN, 10); + String sig = "www.jrobin.org"; + g.setColor( Color.GRAY ); + g.setFont( sigFont ); + + g.drawString( sig, imgWidth / 2 - (sig.length() * 5) / 2, imgHeight - 5 ); + } + private void plotOverlay( Graphics2D g ) { *************** *** 419,423 **** veList.clear(); // Clean up the fetched datasources ! // DEBUG - calculate checkpoint Util.time(1); --- 432,436 ---- veList.clear(); // Clean up the fetched datasources ! // DEBUG - calculate checkpoint Util.time(1); *************** *** 509,512 **** --- 522,528 ---- Source src = plotDefs[i].getSource(); + if ( src == null ) + continue; + double min = src.getAggregate( Source.AGG_MINIMUM ); double max = src.getAggregate( Source.AGG_MAXIMUM ); *************** *** 515,523 **** { if ( plotDefs[i - 1].plotType == PlotDef.PLOT_STACK ) { // Use this source plus stack of previous ones ! double[] curValues = plotDefs[i].source.values; ! for (int j = 0; j < curValues.length; j++) { ! val = tmpSeries[j] + curValues[j]; if ( val < lowerValue ) lowerValue = val; --- 531,539 ---- { if ( plotDefs[i - 1].plotType == PlotDef.PLOT_STACK ) { // Use this source plus stack of previous ones ! //double[] curValues = plotDefs[i].source.values; ! for (int j = 0; j < tmpSeries.length; j++) { ! val = tmpSeries[j] + plotDefs[i].getValue(j, timestamps); if ( val < lowerValue ) lowerValue = val; *************** *** 528,537 **** } else { // Use this source plus the previous one ! double[] prevValues = plotDefs[i - 1].source.values; ! double[] curValues = plotDefs[i].source.values; ! for (int j = 0; j < prevValues.length; j++) { ! val = prevValues[j] + curValues[j]; if ( val < lowerValue ) lowerValue = val; --- 544,553 ---- } else { // Use this source plus the previous one ! //double[] prevValues = plotDefs[i - 1].source.values; ! //double[] curValues = plotDefs[i].source.values; ! for (int j = 0; j < tmpSeries.length; j++) { ! val = plotDefs[i - 1].getValue(j, timestamps) + plotDefs[i].getValue(j, timestamps); if ( val < lowerValue ) lowerValue = val; *************** *** 592,631 **** lastPlotType = plotDefs[i].plotType; } - - /* - for (int i = 0; i < plotDefs.length; i++) - { - Source source = plotDefs[i].getSource(); - - g.setColor( plotDefs[i].getColor() ); - - switch ( plotDefs[i].getType() ) - { - case PlotDef.PLOT_LINE: - graphics.setStroke( new BasicStroke(plotDefs[i].getLineWidth()) ); - plotDefs[i].draw( g, xValues, parentSeries, false ); - //drawLine( g, parentSeries, source, false ); - - graphics.setStroke( new BasicStroke() ); - break; - case PlotDef.PLOT_AREA: - drawArea( g, parentSeries, source, false ); - lastPlotType = PlotDef.PLOT_AREA; - break; - case PlotDef.PLOT_STACK: - if ( lastPlotType == PlotDef.PLOT_AREA ) - drawArea( g, parentSeries, source, true ); - else - drawLine( g, parentSeries, source, true ); - break; - case PlotDef.PLOT_VRULE: - int pos = g.getX( ((VruleSource) source).getTime() ); - graphics.setStroke( new BasicStroke(plotDefs[i].getLineWidth()) ); - g.drawLine( pos, 0 - chartHeight, pos, 0 + chartHeight ); - graphics.setStroke( new BasicStroke() ); - break; - } - } - */ // Reset clipping area and origin --- 608,611 ---- *************** *** 793,798 **** return; ! // Position the cursor just below the chart area ! int posy = tfont_height + UBORDER_SPACE; //y_offset + chartHeight + CHART_UPADDING + CHART_BPADDING + nfont_height; int posx = LBORDER_SPACE; --- 773,778 ---- return; ! // Position the cursor just above the chart area ! int posy = tfont_height - 1 + UBORDER_SPACE; //y_offset + chartHeight + CHART_UPADDING + CHART_BPADDING + nfont_height; int posx = LBORDER_SPACE; *************** *** 895,900 **** } ! double fixedGridStep = Double.NaN;//= graphDef.getValueGridStep(); ! double fixedLabelStep = Double.NaN;//= graphDef.getValueLabelStep(); if ( !Double.isNaN(fixedGridStep) && !Double.isNaN(fixedLabelStep) ) --- 875,880 ---- } ! double fixedGridStep = graphDef.valueGridStep; ! double fixedLabelStep = graphDef.valueLabelStep; if ( !Double.isNaN(fixedGridStep) && !Double.isNaN(fixedLabelStep) ) *************** *** 915,919 **** if ( !lowerFromRange ) lowerValue = v.getNiceLower( lowerValue ); ! return v.getValueMarkers( lowerValue, upperValue, 1000d, graphDef.scaleIndex); //return v.getValueMarkers( lowerValue, upperValue, graphDef.getBaseValue(), graphDef.getScaleIndex() ); } --- 895,899 ---- if ( !lowerFromRange ) lowerValue = v.getNiceLower( lowerValue ); ! return v.getValueMarkers( lowerValue, upperValue, graphDef.baseValue, graphDef.scaleIndex); //return v.getValueMarkers( lowerValue, upperValue, graphDef.getBaseValue(), graphDef.getScaleIndex() ); } *************** *** 942,947 **** double days = (endTime - startTime) / 86400.0; ! //t = graphDef.getTimeAxis(); ! //vLabelCentered = graphDef.getTimeAxisCentered(); if ( t == null ) --- 922,927 ---- double days = (endTime - startTime) / 86400.0; ! t = graphDef.tAxis; ! vLabelCentered = graphDef.tAxisCentered; if ( t == null ) Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/Area.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Area.java 21 Oct 2003 19:41:58 -0000 1.1 --- Area.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 40,46 **** } ! Area( Source source, Color c, boolean stacked ) { ! super( source, c, stacked ); } --- 40,46 ---- } ! Area( Source source, Color c, boolean stacked, boolean visible ) { ! super( source, c, stacked, visible ); } *************** *** 64,79 **** } ! if (nx > ax + 1) // More than one pixel hop, draw intermediate pixels too { ! // For each pixel between nx and ax, calculate the y, plot the line ! int co = (ny - ay) / (nx - ax); ! int j = (ax > 0 ? ax : 1 ); // Skip 0 ! ! for (j = ax; j <= nx; j++) ! g.drawLine( j, py, j, ( co * (j - ax) + ay) ); } ! else if ( nx != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( nx, py, nx, ny ); ! stackValues[i] = ny; ax = nx; --- 64,82 ---- } ! if ( visible ) { ! if (nx > ax + 1) // More than one pixel hop, draw intermediate pixels too ! { ! // For each pixel between nx and ax, calculate the y, plot the line ! int co = (ny - ay) / (nx - ax); ! int j = (ax > 0 ? ax : 1 ); // Skip 0 ! ! for (j = ax; j <= nx; j++) ! g.drawLine( j, py, j, ( co * (j - ax) + ay) ); ! } ! else if ( nx != 0 && py != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! g.drawLine( nx, py, nx, ny ); } ! stackValues[i] = ny; ax = nx; Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/ChartGraphics.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ChartGraphics.java 21 Oct 2003 19:41:58 -0000 1.1 --- ChartGraphics.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 111,113 **** --- 111,133 ---- g.setStroke( s ); } + + int getMinX() + { + return 0; + } + + int getMaxX() + { + return 0 + width; + } + + int getMinY() + { + return 0; + } + + int getMaxY() + { + return 0 + height; + } } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/RrdGraphDef.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RrdGraphDef.java 21 Oct 2003 19:41:58 -0000 1.1 --- RrdGraphDef.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 34,37 **** --- 34,38 ---- import java.util.HashMap; import java.util.GregorianCalendar; + import java.text.SimpleDateFormat; import jrobin.core.Util; *************** *** 77,80 **** --- 78,82 ---- boolean antiAliasing = true; // use anti-aliasing for the chart (default: yes) boolean showLegend = true; // show legend and comments (default: yes) + boolean drawSignature = true; // show JRobin url signature (default: yes) Color backColor = new Color( 245, 245, 245 ); // variation of light gray *************** *** 99,102 **** --- 101,110 ---- BasicStroke borderStroke = null; // defaults to standard beveled border + TimeAxisUnit tAxis = null; + boolean tAxisCentered = false; + double valueGridStep = Double.NaN; + double valueLabelStep = Double.NaN; + double valueStep = 0; + double baseValue = 1000; int scaleIndex = -1; // NO_SCALE *************** *** 106,109 **** --- 114,118 ---- int commentLines = 0; int commentLineShift = 0; + HashMap fetchSources = new HashMap(); Vector cdefList = new Vector(); *************** *** 414,417 **** --- 423,431 ---- } + public void setShowSignature( boolean showSignature ) + { + this.drawSignature = showSignature; + } + /** * Set the anti-aliasing option for the drawing area of the graph. *************** *** 523,526 **** --- 537,546 ---- } + public void line( GregorianCalendar t1, double v1, GregorianCalendar t2, double v2, Color color, String legend, int lineWidth ) throws RrdException + { + plotDefs.add( new CustomLine( t1.getTimeInMillis() / 1000, v1, t2.getTimeInMillis() / 1000, v2, color, lineWidth ) ); + addLegend( legend, color ); + } + /** * Adds area plot to the graph definition, *************** *** 541,544 **** --- 561,570 ---- } + public void area( GregorianCalendar t1, double v1, GregorianCalendar t2, double v2, Color color, String legend ) throws RrdException + { + plotDefs.add( new CustomArea( t1.getTimeInMillis() / 1000, v1, t2.getTimeInMillis() / 1000, v2, color ) ); + addLegend( legend, color ); + } + /** * Adds stacked plot to the graph definition, *************** *** 560,563 **** --- 586,639 ---- /** + * Adds horizontal rule to the graph definition. + * @param value Rule posiotion. + * @param color Rule color. + * @param legend Legend to be added to the graph. + * @throws RrdException Thrown in case of JRobin specific error. + */ + public void hrule(double value, Color color, String legend) throws RrdException { + plotDefs.add( new CustomLine( Long.MIN_VALUE, value, Long.MAX_VALUE, value, color ) ); + addLegend( legend, color ); + } + + /** + * Adds horizontal rule to the graph definition. + * @param value Rule posiotion. + * @param color Rule color. + * @param legend Legend to be added to the graph. + * @param lineWidth Width of the hrule line in pixels. + * @throws RrdException Thrown in case of JRobin specific error. + */ + public void hrule(double value, Color color, String legend, int lineWidth) throws RrdException { + plotDefs.add( new CustomLine( Long.MIN_VALUE, value, Long.MAX_VALUE, value, color, lineWidth ) ); + addLegend( legend, color ); + } + + /** + * Adds a vertical rule to the graph definition. + * @param timestamp Rule position (specific moment in time) + * @param color Rule color. + * @param legend Legend to be added to the graph. + */ + public void vrule( GregorianCalendar timestamp, Color color, String legend ) throws RrdException { + long timeSecs = timestamp.getTimeInMillis() / 1000; + plotDefs.add( new CustomLine( timeSecs, Double.MIN_VALUE, timeSecs, Double.MAX_VALUE, color ) ); + addLegend( legend, color ); + } + + /** + * Adds a vertical rule to the graph definition. + * @param timestamp Rule position (specific moment in time) + * @param color Rule color. + * @param legend Legend to be added to the graph. + * @param lineWidth Width of the vrule in pixels. + */ + public void vrule( GregorianCalendar timestamp, Color color, String legend, int lineWidth ) throws RrdException { + long timeSecs = timestamp.getTimeInMillis() / 1000; + plotDefs.add( new CustomLine( timeSecs, Double.MIN_VALUE, timeSecs, Double.MAX_VALUE, color, lineWidth ) ); + addLegend( legend, color ); + } + + /** * Adds comment to the graph definition. Comments will be left, center or right aligned * if the comment ends with <code>@l</code>, <code>@c</code> or <code>@r</code>, *************** *** 655,658 **** --- 731,778 ---- } + /** + * Should write explanation of custom grid specs here + * @param gridStep + * @param labelStep + */ + public void setValueAxis( double gridStep, double labelStep ) + { + this.valueGridStep = gridStep; + this.valueLabelStep = labelStep; + } + + /** + * Should write explanation of custom grid specs here. + * @param minGridTime + * @param minGridUnits + * @param majGridTime + * @param majGridUnits + * @param df + * @param centered + */ + public void setTimeAxis( int minGridTime, + int minGridUnits, + int majGridTime, + int majGridUnits, + String df, + boolean centered ) + { + this.tAxis = new TimeAxisUnit( minGridTime, + minGridUnits, + majGridTime, + majGridUnits, + new SimpleDateFormat( df ) + ); + this.tAxisCentered = centered; + } + + /** + * Sets vertical space between value ticks. If not specified, JRobin will try to guess it. + * @param valueStep Value step between value ticks. + */ + public void setValueStep(double valueStep) { + this.valueStep = valueStep; + } + // ================================================================ // -- Protected (package) methods *************** *** 671,677 **** { return ( comments.size() > 0 ? commentLines + commentLineShift : 0 ); - //return ( comments.size() > 0 ? (commentLines > 0 ? commentLines : 1) : 0 ); } private void addComment( Comment cmt ) { --- 791,799 ---- { return ( comments.size() > 0 ? commentLines + commentLineShift : 0 ); } + // ================================================================ + // -- Private methods + // ================================================================ private void addComment( Comment cmt ) { *************** *** 683,687 **** private void addLegend( String legend, Color color ) throws RrdException { ! if ( legend != null ) addComment( new Legend(legend, color) ); } --- 805,809 ---- private void addLegend( String legend, Color color ) throws RrdException { ! if ( legend != null && color != null ) addComment( new Legend(legend, color) ); } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/PlotDef.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PlotDef.java 21 Oct 2003 19:41:58 -0000 1.1 --- PlotDef.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 53,61 **** protected Color color = Color.BLACK; // Default color is black PlotDef( String sourceName, Color color ) { this.sourceName = sourceName; ! this.color = color; } --- 53,67 ---- protected Color color = Color.BLACK; // Default color is black + // Implicit + PlotDef() { + } PlotDef( String sourceName, Color color ) { this.sourceName = sourceName; ! this.color = color; ! // If no color is given, we should not plot this source ! if ( color == null ) ! visible = false; } *************** *** 66,74 **** } ! PlotDef( Source source, Color color, boolean stacked ) { this.source = source; this.color = color; this.stacked = stacked; } --- 72,81 ---- } ! PlotDef( Source source, Color color, boolean stacked, boolean visible ) { this.source = source; this.color = color; this.stacked = stacked; + this.visible = visible; } *************** *** 84,87 **** --- 91,95 ---- } + // Default draw is a standard line void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { *************** *** 97,106 **** ny = g.getY( source.values[i] ); ! if ( stacked ) ny += stackValues[i]; ! if ( visible && nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) g.drawLine( ax, ay, nx, ny ); ! stackValues[i] = ny; ax = nx; --- 105,114 ---- ny = g.getY( source.values[i] ); ! if ( stacked && ny != Integer.MIN_VALUE ) ny += stackValues[i]; ! if ( visible && ny != Double.NaN && nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) g.drawLine( ax, ay, nx, ny ); ! stackValues[i] = ny; ax = nx; *************** *** 109,112 **** --- 117,125 ---- g.setStroke( new BasicStroke() ); + } + + double getValue( int tblPos, long[] timestamps ) + { + return source.values[tblPos]; } Index: ValueFormatter.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph2/ValueFormatter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ValueFormatter.java 21 Oct 2003 19:41:58 -0000 1.1 --- ValueFormatter.java 22 Oct 2003 21:06:53 -0000 1.2 *************** *** 59,63 **** ValueFormatter() { - } --- 59,62 ---- |