From: Arne V. <cob...@us...> - 2004-07-04 09:54:45
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22218/org/jrobin/graph Modified Files: Area.java ChartGraphics.java CustomArea.java CustomLine.java FetchSource.java Grapher.java Line.java PlotDef.java Source.java Stack.java Removed Files: RrdOpener.java Log Message: JRobin 1.4.0 - Fixed bug #0000042 - Minor tweaks Index: CustomLine.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomLine.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CustomLine.java 1 Mar 2004 08:50:25 -0000 1.2 --- CustomLine.java 4 Jul 2004 09:54:32 -0000 1.3 *************** *** 113,120 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! 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; --- 113,120 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( lineWidth != 1 ? new BasicStroke(lineWidth) : DEF_LINE_STROKE ); int ax, ay, nx, ny; *************** *** 161,174 **** 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() ); } --- 161,173 ---- for (int i = 0; i < xValues.length; i++) { if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = g.getInverseY(0); else if ( ay == ny ) ! stackValues[i] = g.getInverseY(ay); else ! stackValues[i] = g.getInverseY( (int) (rc * (xValues[i] - ax) + ay) ); } } ! ! g.setStroke( STROKE ); } Index: ChartGraphics.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ChartGraphics.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ChartGraphics.java 19 Apr 2004 22:35:00 -0000 1.2 --- ChartGraphics.java 4 Jul 2004 09:54:32 -0000 1.3 *************** *** 49,53 **** private double widthDelta = 1.0d, heightDelta = 3.0d; - // ================================================================ // -- Constructors --- 49,52 ---- *************** *** 146,149 **** --- 145,150 ---- else heightDelta = 1.0d; + + yStart = (yStart < 0 ? 0 : Math.abs(yStart)); } *************** *** 155,159 **** int getX( long timestamp ) { ! return new Double((timestamp - xStart) * widthDelta).intValue(); } --- 156,160 ---- int getX( long timestamp ) { ! return (int) ((timestamp - xStart) * widthDelta); } *************** *** 166,175 **** { if ( Double.isNaN(value) ) return Integer.MIN_VALUE; ! ! int tmp = new Double( (value - ( yStart < 0 ? 0 : Math.abs(yStart) ) ) * heightDelta).intValue(); ! ! return ( tmp > value * heightDelta ? tmp - 1 : tmp ); } ! /** * Sets the Stroke to use for graphing on the graphics context. --- 167,181 ---- { if ( Double.isNaN(value) ) return Integer.MIN_VALUE; ! ! return (int) ((value - yStart ) * heightDelta); } ! ! double getInverseY( int value ) ! { ! if ( value == Integer.MIN_VALUE ) return Double.NaN; ! ! return (value * 1.0d/heightDelta) + yStart; ! } ! /** * Sets the Stroke to use for graphing on the graphics context. Index: CustomArea.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/CustomArea.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CustomArea.java 1 Mar 2004 08:50:25 -0000 1.3 --- CustomArea.java 4 Jul 2004 09:54:32 -0000 1.4 *************** *** 88,92 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); --- 88,92 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); *************** *** 138,144 **** for (int i = 0; i < stackValues.length; i++) if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = 0; else ! stackValues[i] = ny; } --- 138,144 ---- for (int i = 0; i < stackValues.length; i++) if ( xValues[i] < ax || xValues[i] > nx ) ! stackValues[i] = g.getInverseY(0); else ! stackValues[i] = g.getInverseY(ny); } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Source.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Source.java 26 Apr 2004 22:28:33 -0000 1.7 --- Source.java 4 Jul 2004 09:54:32 -0000 1.8 *************** *** 167,171 **** totalTime += timeDelta; } ! lastTime = time; lastValue = value; --- 167,171 ---- totalTime += timeDelta; } ! lastTime = time; lastValue = value; Index: FetchSource.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/FetchSource.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** FetchSource.java 29 Jun 2004 09:34:39 -0000 1.7 --- FetchSource.java 4 Jul 2004 09:54:32 -0000 1.8 *************** *** 200,204 **** FetchData data = request.fetchData(); ! for (int j = 0; j < dsSize; j++) names[ data.getDsIndex(dsNames[j]) + tblPos ] = vNames[j]; --- 200,204 ---- FetchData data = request.fetchData(); ! for (int j = 0; j < dsSize; j++) names[ data.getDsIndex(dsNames[j]) + tblPos ] = vNames[j]; Index: Stack.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Stack.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Stack.java 1 Mar 2004 08:50:25 -0000 1.3 --- Stack.java 4 Jul 2004 09:54:32 -0000 1.4 *************** *** 64,68 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { PlotDef stack = null; --- 64,68 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { PlotDef stack = null; Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Area.java 1 Mar 2004 08:50:25 -0000 1.4 --- Area.java 4 Jul 2004 09:54:32 -0000 1.5 *************** *** 75,109 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) { g.setColor( color ); double[] values = source.getValues(); ! ! int ax = 0, ay = 0, py; ! int nx = 0, ny = 0, last = -1; ! for (int i = 0; i < xValues.length; i++) { py = 0; nx = xValues[i]; ! 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 ) --- 75,113 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) { g.setColor( color ); double[] values = source.getValues(); ! int len = xValues.length; ! double value; ! int ax = 0, ay = 0, nx = 0, ny = 0, py; ! ! for ( int i = 0; i < len; i++ ) { + value = values[i]; py = 0; nx = xValues[i]; ! ! if ( !Double.isNaN(value) ) { ! if ( stacked ) ! { ! py = g.getY( stackValues[i] ); ! value += stackValues[i]; } ! ! ny = g.getY( value ); ! 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 ) *************** *** 113,123 **** g.drawLine( nx, py, nx, ny ); } ! ! } // Special case with NaN doubles ! ! stackValues[i] = ny; ax = nx; ay = ny; --- 117,126 ---- g.drawLine( nx, py, nx, ny ); } ! ! } // Special case with NaN doubles ! stackValues[i] = value; ax = nx; ay = ny; Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Grapher.java 29 Jun 2004 09:34:39 -0000 1.14 --- Grapher.java 4 Jul 2004 09:54:32 -0000 1.15 *************** *** 317,327 **** // Do the actual graphing calculateSeries(); // calculate all datasources ! plotImageBackground( graphics ); // draw the image background ! plotChart( graphics ); // draw the actual chart ! plotComments( graphics ); // draw all comment lines ! plotOverlay( graphics ); // draw a possible image overlay --- 317,327 ---- // Do the actual graphing calculateSeries(); // calculate all datasources ! plotImageBackground( graphics ); // draw the image background ! plotChart( graphics ); // draw the actual chart ! plotComments( graphics ); // draw all comment lines ! plotOverlay( graphics ); // draw a possible image overlay *************** *** 610,614 **** graphics.setColor( graphDef.getFrameColor() ); graphics.drawRect( lux, luy, chartWidth, chartHeight ); ! double val; double[] tmpSeries = new double[numPoints]; --- 610,614 ---- graphics.setColor( graphDef.getFrameColor() ); graphics.drawRect( lux, luy, chartWidth, chartHeight ); ! double val; double[] tmpSeries = new double[numPoints]; *************** *** 679,683 **** } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); --- 679,683 ---- } ! vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); *************** *** 685,689 **** lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); ! // Use a special graph 'object' that takes care of resizing and reversing y coordinates ChartGraphics g = new ChartGraphics( graphics ); --- 685,689 ---- lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); ! // Use a special graph 'object' that takes care of resizing and reversing y coordinates ChartGraphics g = new ChartGraphics( graphics ); *************** *** 710,715 **** graphics.translate( graphOriginX, graphOriginY ); ! int lastPlotType = PlotDef.PLOT_LINE; ! int[] parentSeries = new int[numPoints]; // Pre calculate x positions of the corresponding timestamps --- 710,715 ---- graphics.translate( graphOriginX, graphOriginY ); ! int lastPlotType = PlotDef.PLOT_LINE; ! double[] parentSeries = new double[numPoints]; // Pre calculate x positions of the corresponding timestamps *************** *** 717,730 **** for (int i = 0; i < timestamps.length; i++) xValues[i] = g.getX(timestamps[i]); ! // Draw all graphed values ! for (int i = 0; i < plotDefs.length; i++) { plotDefs[i].draw( g, xValues, parentSeries, lastPlotType ); ! if(plotDefs[i].plotType != PlotDef.PLOT_STACK) { lastPlotType = plotDefs[i].plotType; - } } ! // Reset clipping area, origin and AA settings graphics.translate( -graphOriginX, -graphOriginY ); --- 717,729 ---- for (int i = 0; i < timestamps.length; i++) xValues[i] = g.getX(timestamps[i]); ! // Draw all graphed values ! for ( int i = 0; i < plotDefs.length; i++ ) { plotDefs[i].draw( g, xValues, parentSeries, lastPlotType ); ! if( plotDefs[i].plotType != PlotDef.PLOT_STACK ) lastPlotType = plotDefs[i].plotType; } ! // Reset clipping area, origin and AA settings graphics.translate( -graphOriginX, -graphOriginY ); Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Line.java 1 Mar 2004 08:50:25 -0000 1.4 --- Line.java 4 Jul 2004 09:54:32 -0000 1.5 *************** *** 25,33 **** package org.jrobin.graph; ! import java.awt.Color; ! import java.awt.BasicStroke; import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; /** --- 25,33 ---- package org.jrobin.graph; ! import java.awt.*; import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; + import org.jrobin.core.Util; /** *************** *** 41,45 **** // -- Members // ================================================================ ! protected int lineWidth = 1; // Default line width of 1 pixel --- 41,46 ---- // -- Members // ================================================================ ! protected static BasicStroke DEF_LINE_STROKE = new BasicStroke(1.0f); ! protected int lineWidth = 1; // Default line width of 1 pixel *************** *** 99,130 **** * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( new BasicStroke(lineWidth) ); double[] values = source.getValues(); ! ! int ax = 0, ay = 0; ! int nx = 0, ny = 0, last = -1; ! ! for (int i = 0; i < xValues.length; i++) { ! nx = xValues[i]; ! ny = g.getY( 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; ay = ny; } ! ! g.setStroke( new BasicStroke() ); } --- 100,135 ---- * @param lastPlotType Type of the previous PlotDef, used to determine PlotDef type of a stack. */ ! void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException { g.setColor( color ); ! g.setStroke( lineWidth != 1 ? new BasicStroke(lineWidth) : DEF_LINE_STROKE ); + Graphics2D gd = g.getGraphics(); double[] values = source.getValues(); ! int len = xValues.length; ! ! double value; ! int ax = 0, ay = 0, nx = 0, ny = 0; ! ! for ( int i = 0; i < len; i++ ) { ! value = values[i]; ! ! nx = xValues[i]; ! ! if ( stacked ) ! value += stackValues[i]; ! ! ny = g.getY( value ); ! ! if ( visible && !Double.isNaN(ny) && nx != 0 && ay != Integer.MIN_VALUE && ny != Integer.MIN_VALUE ) ! gd.drawLine(ax, -ay, nx, -ny); ! ! stackValues[i] = value; ax = nx; ay = ny; } ! ! g.setStroke( STROKE ); } Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/PlotDef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlotDef.java 1 Mar 2004 08:50:25 -0000 1.3 --- PlotDef.java 4 Jul 2004 09:54:32 -0000 1.4 *************** *** 25,29 **** package org.jrobin.graph; ! import java.awt.Color; import java.util.HashMap; --- 25,29 ---- package org.jrobin.graph; ! import java.awt.*; import java.util.HashMap; *************** *** 43,57 **** // -- Members // ================================================================ ! protected static final int PLOT_LINE = 0; ! protected static final int PLOT_AREA = 1; ! protected static final int PLOT_STACK = 2; ! ! protected boolean visible = true; ! protected boolean stacked = false; ! protected int plotType = PLOT_LINE; // Unknown plotdef is a line ! protected String sourceName = ""; ! protected Source source = null; ! protected Color color = Color.BLACK; // Default color is black --- 43,58 ---- // -- Members // ================================================================ ! protected static final int PLOT_LINE = 0; ! protected static final int PLOT_AREA = 1; ! protected static final int PLOT_STACK = 2; ! protected static final BasicStroke STROKE = new BasicStroke(); ! ! protected boolean visible = true; ! protected boolean stacked = false; ! protected int plotType = PLOT_LINE; // Unknown plotdef is a line ! protected String sourceName = ""; ! protected Source source = null; ! protected Color color = Color.BLACK; // Default color is black *************** *** 128,132 **** * This method is responsible for the actual drawing of the PlotDef. */ ! abstract void draw( ChartGraphics g, int[] xValues, int[] stackValues, int lastPlotType ) throws RrdException; Source getSource() { --- 129,133 ---- * This method is responsible for the actual drawing of the PlotDef. */ ! abstract void draw( ChartGraphics g, int[] xValues, double[] stackValues, int lastPlotType ) throws RrdException; Source getSource() { --- RrdOpener.java DELETED --- |