|
From: <cob...@us...> - 2003-10-15 21:19:13
|
Update of /cvsroot/jrobin/src/jrobin/graph In directory sc8-pr-cvs1:/tmp/cvs-serv16781/src/jrobin/graph Modified Files: RrdGraph.java RrdGraphDef.java Grapher.java PlotDef.java Added Files: Vrule.java VruleSource.java Log Message: GRAPH LIB UPDATES Add support for Vrule plotdef --- NEW FILE: Vrule.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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.graph; import java.awt.*; /** * @author cbld * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public class Vrule extends PlotDef { Vrule( long timestamp, Color color, String legend) { super( new VruleSource(timestamp), color, legend ); plotType = PlotDef.PLOT_VRULE; } Vrule( long timestamp, Color color, String legend, float lineWidth) { super( new VruleSource(timestamp), color, legend ); super.setLineWidth(lineWidth); plotType = PlotDef.PLOT_VRULE; } } --- NEW FILE: VruleSource.java --- /* ============================================================ * JRobin : Pure java implementation of RRDTool's functionality * ============================================================ * * Project Info: http://www.sourceforge.net/projects/jrobin * Project Lead: Sasa Markovic (sa...@eu...); * * (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.graph; /** * @author cbld * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */ public class VruleSource extends Source { private long timestamp = 0; VruleSource(long timestamp) { this.timestamp = timestamp; } public long getTime() { return timestamp; } // Stub void setInterval(long start, long end) { } public double getValue(long timestamp, ValueCollection values) { return Double.NaN; } } Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraph.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdGraph.java 14 Oct 2003 22:11:34 -0000 1.5 --- RrdGraph.java 15 Oct 2003 21:19:08 -0000 1.6 *************** *** 96,100 **** ImageIO.write( (RenderedImage) getBufferedImage(width, height), "png", new File(path) ); } ! /** * Saves graph in JPEG format --- 96,100 ---- ImageIO.write( (RenderedImage) getBufferedImage(width, height), "png", new File(path) ); } ! /** * Saves graph in JPEG format Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdGraphDef.java 13 Oct 2003 22:53:33 -0000 1.7 --- RrdGraphDef.java 15 Oct 2003 21:19:08 -0000 1.8 *************** *** 249,252 **** --- 249,259 ---- throw new RrdException("You have to STACK graph onto something..."); } + + void addPlot(Vrule vruleDef) throws RrdException { + plotDefs.add(vruleDef); + sources.add( vruleDef.getSource() ); + if ( vruleDef.getLegend() != null ) + addComment( new Legend(vruleDef.getColor(), vruleDef.getLegend()) ); + } void addPlot(Hrule hruleDef) throws RrdException { *************** *** 392,396 **** */ public void rule(double value, Color color, String legend) throws RrdException { ! addPlot(new Hrule(value, color, legend)); } --- 399,424 ---- */ public void rule(double value, Color color, String legend) throws RrdException { ! addPlot( new Hrule(value, color, legend) ); ! } ! ! /** ! * 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 { ! addPlot( new Vrule(timestamp.getTimeInMillis() / 1000, color, legend) ); ! } ! ! /** ! * 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, float lineWidth ) throws RrdException { ! addPlot( new Vrule(timestamp.getTimeInMillis() / 1000, color, legend, lineWidth) ); } Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/Grapher.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Grapher.java 14 Oct 2003 22:11:34 -0000 1.8 --- Grapher.java 15 Oct 2003 21:19:08 -0000 1.9 *************** *** 493,496 **** --- 493,502 ---- 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; } } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/jrobin/graph/PlotDef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlotDef.java 25 Sep 2003 21:58:05 -0000 1.3 --- PlotDef.java 15 Oct 2003 21:19:08 -0000 1.4 *************** *** 34,37 **** --- 34,39 ---- static final int PLOT_AREA = 1; static final int PLOT_STACK = 2; + static final int PLOT_VRULE = 3; + int plotType = PLOT_LINE; |