From: Arne V. <cob...@us...> - 2004-04-21 09:50:20
|
Update of /cvsroot/jrobin/src/org/jrobin/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21125/src/org/jrobin/graph Modified Files: RrdGraph.java RrdGraphDef.java TimeGrid.java Grapher.java TimeAxisUnit.java ValueGrid.java Log Message: JRobin 1.3.1 DEBUG UPDATE - testing purposes - Improved Value Grid calculation - Added setFirstDayOfWeek option to RrdGraphDef Index: Grapher.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/Grapher.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Grapher.java 19 Apr 2004 22:35:00 -0000 1.9 --- Grapher.java 21 Apr 2004 09:49:01 -0000 1.10 *************** *** 304,310 **** { // Get the rrdDb ! src = (FetchSource) fetchSources.next(); ! String rrdFile = src.getRrdFile(); ! rrd = rrdGraph.getRrd( rrdFile ); // If the endtime is 0, use the last time a database was updated --- 304,310 ---- { // Get the rrdDb ! src = (FetchSource) fetchSources.next(); ! String rrdFile = src.getRrdFile(); ! rrd = rrdGraph.getRrd( rrdFile ); // If the endtime is 0, use the last time a database was updated *************** *** 520,524 **** vGrid = new ValueGrid( range, lowerValue, upperValue, graphDef.getValueAxis(), graphDef.getBaseValue() ); ! tGrid = new TimeGrid( graphDef.getStartTime(), ( graphDef.getEndTime() != 0 ? graphDef.getEndTime() : calculatedEndTime ), graphDef.getTimeAxis() ); lowerValue = vGrid.getLowerValue(); --- 520,524 ---- 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() ); lowerValue = vGrid.getLowerValue(); Index: ValueGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/ValueGrid.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ValueGrid.java 19 Apr 2004 22:35:00 -0000 1.5 --- ValueGrid.java 21 Apr 2004 09:49:01 -0000 1.6 *************** *** 149,153 **** double left = shifted % scaleValues[scaleIndex + 1]; shifted = shifted / scaleValues[++scaleIndex]; ! // While rest > 10, divide by 10 while ( shifted > 10.0 ) { --- 149,153 ---- double left = shifted % scaleValues[scaleIndex + 1]; shifted = shifted / scaleValues[++scaleIndex]; ! // While rest > 10, divide by 10 while ( shifted > 10.0 ) { *************** *** 162,170 **** left = left / scaleValues[scaleIndex]; ! if ( left > 0.9 || left == 0.00 ) { scaleIndex--; mod = 1.0; } // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) --- 162,173 ---- left = left / scaleValues[scaleIndex]; ! ! ! if ( left == 0.00 ) { scaleIndex--; mod = 1.0; } + // Create nice grid based on 'fixed' ranges if ( shifted <= 1.5 ) Index: RrdGraph.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraph.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RrdGraph.java 30 Mar 2004 22:57:45 -0000 1.6 --- RrdGraph.java 21 Apr 2004 09:48:54 -0000 1.7 *************** *** 369,386 **** RrdDb getRrd( String rrdFile ) throws IOException, RrdException { ! if ( pool != null ) { return pool.requestRrdDb( rrdFile ); - } else ! return new RrdDb( rrdFile ); } ! void releaseRrd(RrdDb rrdDb) throws RrdException, IOException { ! if(pool != null) { pool.release(rrdDb); ! } ! else { rrdDb.close(); - } } --- 369,384 ---- RrdDb getRrd( String rrdFile ) throws IOException, RrdException { ! if ( pool != null ) return pool.requestRrdDb( rrdFile ); else ! return new RrdDb( rrdFile, true ); } ! void releaseRrd(RrdDb rrdDb) throws RrdException, IOException ! { ! if ( pool != null ) pool.release(rrdDb); ! else rrdDb.close(); } Index: TimeAxisUnit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeAxisUnit.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TimeAxisUnit.java 19 Apr 2004 22:35:00 -0000 1.5 --- TimeAxisUnit.java 21 Apr 2004 09:49:01 -0000 1.6 *************** *** 49,66 **** // Indices in the calendarUnit table ! /** constant for seconds */ ! public static final int SECOND = 0; ! /** constant for minutes */ ! public static final int MINUTE = 1; ! /** constant for hours */ ! public static final int HOUR = 2; ! /** constant for days */ ! public static final int DAY = 3; ! /** constant for weeks */ ! public static final int WEEK = 4; ! /** constant for months */ ! public static final int MONTH = 5; ! /** constant for years */ ! public static final int YEAR = 6; private static final String[] UNIT_NAMES = { --- 49,68 ---- // Indices in the calendarUnit table ! public static final int SECOND = 0; /** constant for seconds */ ! public static final int MINUTE = 1; /** constant for minutes */ ! public static final int HOUR = 2; /** constant for hours */ ! public static final int DAY = 3; /** constant for days */ ! public static final int WEEK = 4; /** constant for weeks */ ! public static final int MONTH = 5; /** constant for months */ ! public static final int YEAR = 6; /** constant for years */ ! ! // Days of the week ! public static final int MONDAY = Calendar.MONDAY; ! public static final int TUESDAY = Calendar.TUESDAY; ! public static final int WEDNESDAY = Calendar.WEDNESDAY; ! public static final int THURSDAY = Calendar.THURSDAY; ! public static final int FRIDAY = Calendar.FRIDAY; ! public static final int SATURDAY = Calendar.SATURDAY; ! public static final int SUNDAY = Calendar.SUNDAY; private static final String[] UNIT_NAMES = { *************** *** 75,78 **** --- 77,82 ---- private boolean centerLabels = false; private SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.ENGLISH ); + + private int firstDayOfWeek = MONDAY; // first day of a week *************** *** 95,102 **** * @param dateFormat Format to use to convert the specific time into a label string. * @param centerLabels True if labels (major grid) should be centered between two major grid lines. */ TimeAxisUnit( int minGridTimeUnit, int minGridUnitSteps, int majGridTimeUnit, int majGridUnitSteps, ! SimpleDateFormat dateFormat, boolean centerLabels ) { this.minGridTimeUnit = minGridTimeUnit; --- 99,107 ---- * @param dateFormat Format to use to convert the specific time into a label string. * @param centerLabels True if labels (major grid) should be centered between two major grid lines. + * @param firstDayOfWeek First day of a calendar week. */ TimeAxisUnit( int minGridTimeUnit, int minGridUnitSteps, int majGridTimeUnit, int majGridUnitSteps, ! SimpleDateFormat dateFormat, boolean centerLabels, int firstDayOfWeek ) { this.minGridTimeUnit = minGridTimeUnit; *************** *** 106,109 **** --- 111,115 ---- this.dateFormat = new SimpleDateFormat( dateFormat.toPattern(), Locale.ENGLISH ); this.centerLabels = centerLabels; + this.firstDayOfWeek = firstDayOfWeek; } *************** *** 240,245 **** { t.setTimeInMillis( exactStart ); - t.setFirstDayOfWeek(Calendar.MONDAY); for (int i = 0; i < HOUR && i <= unit; i++) t.set( calendarUnit[i], 0 ); --- 246,251 ---- { t.setTimeInMillis( exactStart ); + t.setFirstDayOfWeek( firstDayOfWeek ); for (int i = 0; i < HOUR && i <= unit; i++) t.set( calendarUnit[i], 0 ); Index: RrdGraphDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/RrdGraphDef.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RrdGraphDef.java 1 Mar 2004 08:50:25 -0000 1.8 --- RrdGraphDef.java 21 Apr 2004 09:48:58 -0000 1.9 *************** *** 102,105 **** --- 102,107 ---- private int chart_lpadding = Grapher.CHART_LPADDING; // padding space on the left of the chart area + private int firstDayOfWeek = TimeAxisUnit.MONDAY; // first day of a calendar week, default: monday + private double baseValue = ValueFormatter.DEFAULT_BASE; // unit base value to use (default: 1000) private int scaleIndex = ValueFormatter.NO_SCALE; // fixed units exponent value to use *************** *** 599,605 **** majGridUnitSteps, new SimpleDateFormat( dateFormat ), ! centerLabels ); } /** --- 601,618 ---- majGridUnitSteps, new SimpleDateFormat( dateFormat ), ! centerLabels , ! firstDayOfWeek ); } + + /** + * Sets the first day of a calendar week, defaults to monday if not set. + * + * @param day Weekday, 0 for sunday, 6 for saturday. + */ + public void setFirstDayOfWeek( int day ) + { + firstDayOfWeek = day; + } /** *************** *** 1192,1195 **** --- 1205,1212 ---- } + protected int getFirstDayOfWeek() { + return firstDayOfWeek; + } + protected PlotDef[] getPlotDefs() { Index: TimeGrid.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/graph/TimeGrid.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TimeGrid.java 1 Mar 2004 08:50:25 -0000 1.2 --- TimeGrid.java 21 Apr 2004 09:49:01 -0000 1.3 *************** *** 53,58 **** * @param tAxis TimeAxisUnit specified to determine the grid lines, if the given * TimeAxisUnit is null, one will be automatically determined. */ ! TimeGrid( long startTime, long endTime, TimeAxisUnit tAxis ) { this.startTime = startTime; --- 53,59 ---- * @param tAxis TimeAxisUnit specified to determine the grid lines, if the given * TimeAxisUnit is null, one will be automatically determined. + * @param firstDayOfWeek First day of a calendar week. */ ! TimeGrid( long startTime, long endTime, TimeAxisUnit tAxis, int firstDayOfWeek ) { this.startTime = startTime; *************** *** 61,65 **** // Set an appropriate time axis it not given yet ! setTimeAxis(); } --- 62,66 ---- // Set an appropriate time axis it not given yet ! setTimeAxis( firstDayOfWeek ); } *************** *** 95,100 **** * Determines a good TimeAxisUnit to use for grid calculation. * A decent grid is selected based on the timespan being used in the chart. */ ! private void setTimeAxis() { if ( tAxis != null ) --- 96,103 ---- * Determines a good TimeAxisUnit to use for grid calculation. * A decent grid is selected based on the timespan being used in the chart. + * + * @param firstDayOfWeek First day of a calendar week. */ ! private void setTimeAxis( int firstDayOfWeek ) { if ( tAxis != null ) *************** *** 104,150 **** if ( days <= 0.75 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 1, TimeAxisUnit.MINUTE, 5, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 2.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 10, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 3.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 20, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 5.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 10, TimeAxisUnit.MINUTE, 30, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 10.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 15, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 15.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 30, TimeAxisUnit.HOUR, 2, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 20.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH"), true ); } else if ( days <= 36.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 4, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 2 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 2, TimeAxisUnit.HOUR, 6, new SimpleDateFormat("HH:mm"), false ); } else if ( days <= 3 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 3, TimeAxisUnit.HOUR, 12, new SimpleDateFormat("HH:mm"), false ); } else if ( days < 8 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, new SimpleDateFormat("EEE dd"), true); } else if ( days <= 14 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 12, TimeAxisUnit.DAY, 1, new SimpleDateFormat("dd"), true ); } else if ( days <= 43 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.DAY, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("'week' ww"), true ); } else if ( days <= 157 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.WEEK, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("ww"), true ); } else { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, new SimpleDateFormat("MMM"), true ); } } --- 107,153 ---- if ( days <= 0.75 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 1, TimeAxisUnit.MINUTE, 5, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 2.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 10, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 3.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 5, TimeAxisUnit.MINUTE, 20, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 5.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 10, TimeAxisUnit.MINUTE, 30, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 10.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 15, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 15.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MINUTE, 30, TimeAxisUnit.HOUR, 2, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 20.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 1, new SimpleDateFormat("HH"), true, firstDayOfWeek ); } else if ( days <= 36.0 / 24.0 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 1, TimeAxisUnit.HOUR, 4, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 2 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 2, TimeAxisUnit.HOUR, 6, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days <= 3 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 3, TimeAxisUnit.HOUR, 12, new SimpleDateFormat("HH:mm"), false, firstDayOfWeek ); } else if ( days < 8 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 6, TimeAxisUnit.DAY, 1, new SimpleDateFormat("EEE dd"), true, firstDayOfWeek ); } else if ( days <= 14 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.HOUR, 12, TimeAxisUnit.DAY, 1, new SimpleDateFormat("dd"), true, firstDayOfWeek ); } else if ( days <= 43 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.DAY, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("'week' ww"), true, firstDayOfWeek ); } else if ( days <= 157 ) { ! tAxis = new TimeAxisUnit( TimeAxisUnit.WEEK, 1, TimeAxisUnit.WEEK, 1, new SimpleDateFormat("ww"), true, firstDayOfWeek ); } else { ! tAxis = new TimeAxisUnit( TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, new SimpleDateFormat("MMM"), true, firstDayOfWeek ); } } |