From: Arne V. <cob...@us...> - 2005-04-06 20:10:20
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8322/org/jrobin/graph Modified Files: Area.java Gprint.java Grapher.java Line.java LinearInterpolator.java PlotDef.java RrdExportDef.java RrdExporter.java RrdGraphDefTemplate.java Stack.java Log Message: - First support of DataProcessor into Graph.* package. Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Grapher.java 23 Jan 2005 20:31:26 -0000 1.21 --- Grapher.java 6 Apr 2005 20:10:10 -0000 1.22 *************** *** 39,42 **** --- 39,44 ---- import org.jrobin.core.RrdException; import org.jrobin.core.Util; + import org.jrobin.core.ConsolFuns; + import org.jrobin.data.Aggregates; /** *************** *** 131,135 **** startTime = graphDef.getStartTime(); ! endTime = graphDef.getStartTime(); } --- 133,137 ---- startTime = graphDef.getStartTime(); ! endTime = graphDef.getEndTime(); } *************** *** 341,345 **** super.calculateSeries( chartWidth ); ! numPoints = numRows; /** --- 343,353 ---- super.calculateSeries( chartWidth ); ! tsChart = processor.getTimestamps(); ! numPoints = tsChart.length; ! ! plotDefs = graphDef.getPlotDefs(); ! ! for ( int i = 0; i < plotDefs.length; i++ ) ! plotDefs[i].setProcessor( processor ); /** *************** *** 347,350 **** --- 355,359 ---- * this allows for much nicer graphing. */ + /* tsChart = new long[ chartWidth ]; plotDefs = graphDef.getPlotDefs(); *************** *** 365,368 **** --- 374,378 ---- tsChart[i] = t; } + */ } *************** *** 458,466 **** } // For autoscale, detect lower and upper limit of values for ( int i = 0; i < plotDefs.length; i++ ) { ! Source src = plotDefs[i].getSource(); ! // Only try autoscale when we do not have a rigid grid if ( !rigid && src != null ) --- 468,525 ---- } + // For autoscale, detect lower and upper limit of values for ( int i = 0; i < plotDefs.length; i++ ) { ! String srcName = plotDefs[i].getSourceName(); ! ! if ( srcName == null || "".equals( srcName ) ) continue; ! ! Aggregates agg = processor.getAggregates( srcName ); ! ! // Only try autoscale when we do not have a rigid grid ! if ( !rigid ) ! { ! double min = agg.getMin(); ! double max = agg.getMax(); ! ! // If the plotdef is a stack, evaluate ALL previous values to find a possible max ! if ( plotDefs[i].plotType == PlotDef.PLOT_STACK && i >= 1 ) ! { ! if ( plotDefs[i - 1].plotType == PlotDef.PLOT_STACK ) { // Use this source plus stack of previous ones ! ! for (int j = 0; j < tmpSeries.length; j++) ! { ! val = tmpSeries[j] + plotDefs[i].getValue(j, timestamps); ! ! if ( val < lowerValue ) lowerValue = val; ! if ( val > upperValue ) upperValue = val; ! ! tmpSeries[j] = val; ! } ! } ! else { // Use this source plus the previous one ! ! 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; ! if ( val > upperValue ) upperValue = val; ! ! tmpSeries[j] = val; ! } ! ! } ! } ! else // Only use min/max of a single datasource ! { ! if ( min < lowerValue ) lowerValue = min; ! if ( max > upperValue ) upperValue = max; ! } ! } ! ! /*Source src = plotDefs[i].getSource(); ! // Only try autoscale when we do not have a rigid grid if ( !rigid && src != null ) *************** *** 503,507 **** if ( max > upperValue ) upperValue = max; } ! } } --- 562,566 ---- if ( max > upperValue ) upperValue = max; } ! }*/ } *************** *** 509,513 **** vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( startTime, endTime, graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); ! lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); --- 568,572 ---- vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); tGrid = new TimeGrid( startTime, endTime, graphDef.getTimeAxis(), graphDef.getFirstDayOfWeek() ); ! lowerValue = vGrid.getLowerValue(); upperValue = vGrid.getUpperValue(); *************** *** 724,728 **** } else if ( clist[i].commentType == Comment.CMT_GPRINT ) ! ((Gprint) clist[i]).setValue( sources, sourceIndex, valueFormat ); ArrayList tknpairs = clist[i].getTokens(); --- 783,787 ---- } else if ( clist[i].commentType == Comment.CMT_GPRINT ) ! ((Gprint) clist[i]).setValue( processor, valueFormat );//.setValue( sources, sourceIndex, valueFormat ); ArrayList tknpairs = clist[i].getTokens(); Index: RrdExportDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExportDef.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdExportDef.java 21 Sep 2004 08:42:10 -0000 1.4 --- RrdExportDef.java 6 Apr 2005 20:10:10 -0000 1.5 *************** *** 33,36 **** --- 33,37 ---- import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; + import org.jrobin.data.DataProcessor; /** *************** *** 69,72 **** --- 70,75 ---- protected ArrayList edefList = new ArrayList( 3 ); // holds the list of export data objects + private DataProcessor processor = new DataProcessor(); + // ================================================================ // -- Constructors *************** *** 127,135 **** public void setTimePeriod( long startTime, long endTime ) throws RrdException { ! if ( startTime < 0 || ( endTime != 0 && endTime <= startTime ) ) ! throw new RrdException( "Invalid start/end time: " + startTime + "/" + endTime ); ! ! this.startTime = startTime; ! this.endTime = endTime; } --- 130,134 ---- public void setTimePeriod( long startTime, long endTime ) throws RrdException { ! processor.setTimePeriod( startTime, endTime ); } *************** *** 166,170 **** public void setResolution( long resolution ) { ! this.resolution = resolution; } --- 165,169 ---- public void setResolution( long resolution ) { ! processor.setFetchRequestResolution( resolution ); } *************** *** 188,194 **** public void datasource( String name, String file, String dsName, String consolFunc ) throws RrdException { ! fetchSources.add( name, file, dsName, consolFunc ); ! ! numDefs++; } --- 187,191 ---- public void datasource( String name, String file, String dsName, String consolFunc ) throws RrdException { ! processor.addDatasource( name, file, dsName, consolFunc ); } *************** *** 213,219 **** public void datasource( String name, String file, String dsName, String consolFunc, String backend ) throws RrdException { ! fetchSources.add( name, file, dsName, consolFunc, backend ); ! ! numDefs++; } --- 210,214 ---- public void datasource( String name, String file, String dsName, String consolFunc, String backend ) throws RrdException { ! processor.addDatasource( name, file, dsName, consolFunc, backend ); } *************** *** 226,232 **** public void setDatasources( FetchSourceList datasourceList ) { fetchSources = datasourceList; ! numDefs = fetchSources.defCount(); } --- 221,229 ---- public void setDatasources( FetchSourceList datasourceList ) { + throw new RuntimeException( "Unsupported method: setDatasources(FetchSourceList)" ); // TODO Reimplement FetchSourceList functionality + /* fetchSources = datasourceList; ! numDefs = fetchSources.defCount();*/ } *************** *** 255,259 **** public void datasource( String name, String rpn ) { ! cdefList.add( new Cdef(name, rpn) ); } --- 252,256 ---- public void datasource( String name, String rpn ) { ! processor.addDatasource( name, rpn ); } *************** *** 269,274 **** public void datasource( String name, String defName, String consolFunc ) throws RrdException { ! cdefList.add( new Sdef(name, defName, consolFunc) ); ! numSdefs++; } --- 266,270 ---- public void datasource( String name, String defName, String consolFunc ) throws RrdException { ! processor.addDatasource( name, defName, consolFunc ); } *************** *** 282,286 **** public void datasource( String name, Plottable plottable ) { ! pdefList.add( new Pdef(name, plottable) ); } --- 278,282 ---- public void datasource( String name, Plottable plottable ) { ! processor.addDatasource( name, plottable ); } *************** *** 295,299 **** public void datasource( String name, Plottable plottable, int index ) { ! pdefList.add( new Pdef(name, plottable, index) ); } --- 291,295 ---- public void datasource( String name, Plottable plottable, int index ) { ! processor.addDatasource( name, plottable, index ); } *************** *** 308,312 **** public void datasource( String name, Plottable plottable, String sourceName ) { ! pdefList.add( new Pdef(name, plottable, sourceName) ); } --- 304,308 ---- public void datasource( String name, Plottable plottable, String sourceName ) { ! processor.addDatasource( name, plottable, sourceName ); } *************** *** 318,322 **** public void addExportData( ExportData edata ) { ! edefList.add( edata ); } --- 314,319 ---- public void addExportData( ExportData edata ) { ! throw new RuntimeException( "Unsupported method: addExportData(ExportData)" ); // TODO Reimplement ExportData functionality ! //edefList.add( edata ); } *************** *** 378,382 **** public void exportXmlTemplate( OutputStream stream ) { ! XmlWriter xml = new XmlWriter( stream ); xml.startTag("rrd_export_def"); --- 375,380 ---- public void exportXmlTemplate( OutputStream stream ) { ! throw new RuntimeException( "Unsupported method: exportXmlTemplate(OutputStream)" ); // TODO Reimplement XmlTemplate functionality ! /*XmlWriter xml = new XmlWriter( stream ); xml.startTag("rrd_export_def"); *************** *** 423,427 **** xml.flush(); ! xml.flush(); } --- 421,425 ---- xml.flush(); ! xml.flush();*/ } *************** *** 467,480 **** // -- Protected (package) methods // ================================================================ protected long getStartTime() { ! return startTime; } protected long getEndTime() { ! return endTime; } protected long getResolution() { ! return resolution; } --- 465,482 ---- // -- Protected (package) methods // ================================================================ + protected DataProcessor getProcessor() { + return processor; + } + protected long getStartTime() { ! return processor.getStartingTimestamp(); } protected long getEndTime() { ! return processor.getEndingTimestamp(); } protected long getResolution() { ! return processor.getFetchRequestResolution(); } Index: Line.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Line.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Line.java 9 Jul 2004 12:22:15 -0000 1.6 --- Line.java 6 Apr 2005 20:10:10 -0000 1.7 *************** *** 106,109 **** --- 106,110 ---- Graphics2D gd = g.getGraphics(); + values = processor.getValues( sourceName ); int len = values.length; Index: RrdExporter.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdExporter.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdExporter.java 23 Jan 2005 20:31:26 -0000 1.9 --- RrdExporter.java 6 Apr 2005 20:10:10 -0000 1.10 *************** *** 30,33 **** --- 30,34 ---- import org.jrobin.core.*; + import org.jrobin.data.DataProcessor; /** *************** *** 49,52 **** --- 50,55 ---- protected HashMap sourceIndex; + protected DataProcessor processor; + RrdExporter( RrdExportDef def ) { *************** *** 64,67 **** --- 67,71 ---- { this.def = def; + processor = def.getProcessor(); } *************** *** 83,86 **** --- 87,93 ---- protected void calculateSeries( int maxRows ) throws RrdException, IOException { + processor.processData(); + /* + FetchSourceList fetchSources; ValueExtractor ve; *************** *** 444,450 **** this.startTime = startTime; this.endTime = ( changingEndTime ? finalEndTime : endTime ); } ! private Source getSource( String name ) throws RrdException { if ( !sourceIndex.containsKey(name) ) --- 451,458 ---- this.startTime = startTime; this.endTime = ( changingEndTime ? finalEndTime : endTime ); + */ } ! /*private Source getSource( String name ) throws RrdException { if ( !sourceIndex.containsKey(name) ) *************** *** 452,456 **** return sources[ ( (Integer) sourceIndex.get(name) ).intValue() ]; ! } /** --- 460,464 ---- return sources[ ( (Integer) sourceIndex.get(name) ).intValue() ]; ! }*/ /** *************** *** 464,468 **** protected ExportData createExportData() throws RrdException { ! if ( sources == null) throw new RrdException( "Sources not calculated, no data to return." ); --- 472,477 ---- protected ExportData createExportData() throws RrdException { ! throw new RuntimeException( "Unsupported method createExportData()" ); // TODO Reimplement ExportData creation ! /* if ( sources == null) throw new RrdException( "Sources not calculated, no data to return." ); *************** *** 494,501 **** System.arraycopy( timestamps, 0, reducedTs, 0, reducedNumRows ); ! return new ExportData( reducedTs, sourceSet, legends ); } ! private Def createReducedDef( Source origSrc ) { Def src = new Def( origSrc.getName(), reducedNumRows, reducedNumRows ); --- 503,510 ---- System.arraycopy( timestamps, 0, reducedTs, 0, reducedNumRows ); ! return new ExportData( reducedTs, sourceSet, legends );*/ } ! /*private Def createReducedDef( Source origSrc ) { Def src = new Def( origSrc.getName(), reducedNumRows, reducedNumRows ); *************** *** 506,510 **** return src; ! } /** --- 515,519 ---- return src; ! }*/ /** Index: Stack.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Stack.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Stack.java 9 Jul 2004 12:22:15 -0000 1.5 --- Stack.java 6 Apr 2005 20:10:10 -0000 1.6 *************** *** 74,78 **** else if ( lastPlotType == PlotDef.PLOT_AREA ) stack = new Area( source, values, color, true, visible ); ! stack.draw( g, xValues, stackValues, lastPlotType ); } --- 74,81 ---- else if ( lastPlotType == PlotDef.PLOT_AREA ) stack = new Area( source, values, color, true, visible ); ! ! stack.sourceName = sourceName; ! stack.processor = processor; ! stack.draw( g, xValues, stackValues, lastPlotType ); } Index: RrdGraphDefTemplate.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDefTemplate.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RrdGraphDefTemplate.java 27 Jul 2004 12:30:17 -0000 1.11 --- RrdGraphDefTemplate.java 6 Apr 2005 20:10:10 -0000 1.12 *************** *** 637,641 **** rrdGraphDef.setCanvasColor(Color.decode(colorStr)); } ! // LEFT PADDING else if(option.equals("left_padding")) { int padding = getValueAsInt(optionNode); --- 637,641 ---- rrdGraphDef.setCanvasColor(Color.decode(colorStr)); } ! // HORIZONTAL_LEFT PADDING else if(option.equals("left_padding")) { int padding = getValueAsInt(optionNode); Index: PlotDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/PlotDef.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PlotDef.java 25 Jul 2004 12:28:49 -0000 1.6 --- PlotDef.java 6 Apr 2005 20:10:10 -0000 1.7 *************** *** 30,33 **** --- 30,34 ---- import org.jrobin.core.RrdException; import org.jrobin.core.XmlWriter; + import org.jrobin.data.DataProcessor; /** *************** *** 58,61 **** --- 59,64 ---- protected double[] values = null; + protected DataProcessor processor = null; + // ================================================================ // -- Constructors *************** *** 99,103 **** // ================================================================ // -- Protected methods ! // ================================================================ /** * Sets the Source for this PlotDef, based on the internal datasource name. --- 102,110 ---- // ================================================================ // -- Protected methods ! // ================================================================ ! void setProcessor( DataProcessor processor ) { ! this.processor = processor; ! } ! /** * Sets the Source for this PlotDef, based on the internal datasource name. *************** *** 131,137 **** * @return Double value of the datapoint. */ ! double getValue( int tblPos, long[] timestamps ) { ! return source.get( tblPos ); } --- 138,145 ---- * @return Double value of the datapoint. */ ! double getValue( int tblPos, long[] timestamps ) throws RrdException { ! return processor.getValues( sourceName )[tblPos]; ! //return source.get( tblPos ); } Index: LinearInterpolator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/LinearInterpolator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** LinearInterpolator.java 9 Jun 2004 09:44:48 -0000 1.3 --- LinearInterpolator.java 6 Apr 2005 20:10:10 -0000 1.4 *************** *** 44,51 **** */ public class LinearInterpolator extends Plottable { ! /** constant used to specify LEFT interpolation. * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_LEFT = 0; ! /** constant used to specify RIGHT interpolation. * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_RIGHT = 1; --- 44,51 ---- */ public class LinearInterpolator extends Plottable { ! /** constant used to specify HORIZONTAL_LEFT interpolation. * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_LEFT = 0; ! /** constant used to specify HORIZONTAL_RIGHT interpolation. * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_RIGHT = 1; Index: Area.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Area.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Area.java 9 Jul 2004 12:22:14 -0000 1.6 --- Area.java 6 Apr 2005 20:10:10 -0000 1.7 *************** *** 26,29 **** --- 26,30 ---- import org.jrobin.core.XmlWriter; + import org.jrobin.core.RrdException; import java.awt.*; *************** *** 75,82 **** * @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 ); int len = values.length; --- 76,84 ---- * @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 ); + values = processor.getValues( sourceName ); int len = values.length; Index: Gprint.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Gprint.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Gprint.java 21 Sep 2004 08:42:10 -0000 1.8 --- Gprint.java 6 Apr 2005 20:10:10 -0000 1.9 *************** *** 33,36 **** --- 33,37 ---- import org.jrobin.core.XmlWriter; import org.jrobin.core.ConsolFuns; + import org.jrobin.data.DataProcessor; /** *************** *** 50,55 **** private static final Pattern VALUE_PATTERN = Pattern.compile(VALUE_MARKER); ! private String sourceName; ! private int aggregate; private int numDec = 3; // Show 3 decimal values by default private int strLen = -1; --- 51,57 ---- private static final Pattern VALUE_PATTERN = Pattern.compile(VALUE_MARKER); ! private String sourceName, aggName; ! private DataProcessor processor; ! private int aggregate; private int numDec = 3; // Show 3 decimal values by default private int strLen = -1; *************** *** 84,88 **** this.commentType = Comment.CMT_GPRINT; this.sourceName = sourceName; ! if ( consolFunc.equalsIgnoreCase(CF_AVERAGE) || consolFunc.equalsIgnoreCase("AVG") ) aggregate = Source.AGG_AVERAGE; --- 86,91 ---- this.commentType = Comment.CMT_GPRINT; this.sourceName = sourceName; ! this.aggName = consolFunc; ! if ( consolFunc.equalsIgnoreCase(CF_AVERAGE) || consolFunc.equalsIgnoreCase("AVG") ) aggregate = Source.AGG_AVERAGE; *************** *** 132,141 **** * @throws RrdException Thrown in case of a JRobin specific error. */ ! void setValue( Source[] sources, HashMap sourceIndex, ValueFormatter vFormat ) throws RrdException { ! try ! { ! 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(); --- 135,146 ---- * @throws RrdException Thrown in case of a JRobin specific error. */ ! //void setValue( Source[] sources, HashMap sourceIndex, ValueFormatter vFormat ) throws RrdException ! void setValue( DataProcessor processor, ValueFormatter vFormat ) throws RrdException { ! /*try ! {*/ ! //double value = sources[ ((Integer) sourceIndex.get(sourceName)).intValue() ].getAggregate( aggregate ); ! double value = processor.getAggregate( sourceName, aggName ); ! // See if we need to use a specific value for the formatting double oldBase = vFormat.getBase(); *************** *** 167,174 **** if ( baseValue != -1 ) vFormat.setBase( oldBase ); ! } catch (Exception e) { throw new RrdException( "Could not find datasource: " + sourceName ); ! } } --- 172,179 ---- if ( baseValue != -1 ) vFormat.setBase( oldBase ); ! /*} catch (Exception e) { throw new RrdException( "Could not find datasource: " + sourceName ); ! }*/ } |