|
From: <cob...@us...> - 2003-11-20 09:28:43
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv32621/src/org/jrobin/graph Modified Files: RrdGraphDef.java Grapher.java Area.java Line.java Added Files: TimeAxisLabel.java Log Message: Fixed stacking on NaN bug Added TimeAxisLabel option --- NEW FILE: TimeAxisLabel.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 org.jrobin.graph; import org.jrobin.core.RrdException; /** * <p>Represents the TimeAxis label used in the graph. The TimeAxisLabel object has the same alignment * possibilities as all other text/comment objects in a graph.</p> * * @author Arne Vandamme (cob...@jr...) */ public class TimeAxisLabel extends Comment { // ================================================================ // -- Constructors // ================================================================ /** * Constructs a TimeAxisLabel object based on a text string. * @param text Text string with alignment markers representing the label. * @throws RrdException Thrown in case of a JRobin specific error. */ TimeAxisLabel( String text ) throws RrdException { this.text = text; lfToken = Comment.TKN_ACF; super.parseComment(); // If there's no line end, add centered-line end if ( !super.isCompleteLine() ) { oList.add( "" ); oList.add( super.TKN_ACF ); oList.add( "" ); oList.add( super.TKN_ALF ); this.lineCount += 2; } } } Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdGraphDef.java 10 Nov 2003 08:52:27 -0000 1.2 --- RrdGraphDef.java 20 Nov 2003 09:28:00 -0000 1.3 *************** *** 224,227 **** --- 224,254 ---- /** + * Sets horizontal (time) axis label. + * <p> + * A horizontal axis label is always center aligned by default, with an extra linefeed to add + * some space before the regular comment lines start. If you wish to remove the extra line of whitespace + * you should specify the alignment in the label using @c, @l or @r. Using the @C, @L or @R markers will + * align the text appropriately, and leave the extra line of whitespace intact. + * </p> + * <p> + * It is possible to use multiple lines and multiple alignment markers for the axis label, in that case + * you should specify alignment for every part of the label to get it to display correctly. When using multiple + * lines, no markers will be added to the end of the last line by default. + * </p> + * @param label Horizontal axis label. + */ + public void setTimeAxisLabel( String label ) throws RrdException + { + if ( label != null ) + { + TimeAxisLabel cmt = new TimeAxisLabel( label ); + commentLines += cmt.getLineCount(); + commentLineShift = (cmt.isCompleteLine() ? 0 : 1); + + comments.add( 0, cmt ); + } + } + + /** * Sets image background color. If not set, back color defaults to a very light gray. * @param backColor Graph background color. Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Grapher.java 18 Nov 2003 12:47:56 -0000 1.3 --- Grapher.java 20 Nov 2003 09:28:00 -0000 1.4 *************** *** 619,623 **** // Position the cursor just below the chart area ! int posy = y_offset + chartHeight + CHART_UPADDING + CHART_BPADDING + nfont_height; int posx = LBORDER_SPACE; --- 619,623 ---- // Position the cursor just below the chart area ! int posy = y_offset + chartHeight + CHART_UPADDING + CHART_BPADDING + ( graphDef.showMajorGridX() ? nfont_height : 0 ); int posx = LBORDER_SPACE; Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Area.java 7 Nov 2003 08:23:19 -0000 1.1 --- Area.java 20 Nov 2003 09:28:00 -0000 1.2 *************** *** 89,112 **** ny = g.getY( values[i] ); ! if ( stacked ) { ! py = stackValues[i]; ! ny += stackValues[i]; ! } ! ! 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++) ! if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! 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; --- 89,119 ---- ny = g.getY( values[i] ); ! if ( !Double.isNaN(values[i]) ) { ! if ( stacked ) { ! py = stackValues[i]; ! ny += ( stackValues[i] == Integer.MIN_VALUE ? Integer.MIN_VALUE : stackValues[i] ); ! } ! 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++) ! if ( ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! 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 ); } ! ! } + + // Special case with NaN doubles stackValues[i] = ny; Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Line.java 7 Nov 2003 08:23:19 -0000 1.1 --- Line.java 20 Nov 2003 09:28:00 -0000 1.2 *************** *** 119,122 **** --- 119,123 ---- g.drawLine( ax, ay, nx, ny ); + stackValues[i] = ny; ax = nx; |