From: <sa...@us...> - 2004-02-26 12:40:32
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12847 Modified Files: PlottableDemo.java Log Message: Plottable demo (final) Index: PlottableDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/PlottableDemo.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlottableDemo.java 19 Feb 2004 13:05:04 -0000 1.3 --- PlottableDemo.java 26 Feb 2004 12:24:45 -0000 1.4 *************** *** 1,2 **** --- 1,3 ---- + import org.jrobin.graph.*; import org.jrobin.core.RrdException; *************** *** 6,12 **** import java.io.IOException; import java.util.Date; class PlottableDemo { ! public static void main(String[] args) throws RrdException, IOException { final long t0 = new Date().getTime() / 1000L, dt = 86400L; final int n = 10; --- 7,19 ---- import java.io.IOException; import java.util.Date; + import java.util.GregorianCalendar; class PlottableDemo { ! private PlottableDemo() throws RrdException, IOException { ! createGraph1(); ! createGraph2(); ! } ! ! private void createGraph1() throws RrdException, IOException { final long t0 = new Date().getTime() / 1000L, dt = 86400L; final int n = 10; *************** *** 14,18 **** Plottable p = new Plottable() { public double getValue(long t) { ! double x = (t - t0) / (double)(t1 - t0); return Math.exp(-x * 2) * Math.cos(x * 7 * Math.PI); } --- 21,25 ---- Plottable p = new Plottable() { public double getValue(long t) { ! double x = (t - t0) / (double) (t1 - t0); return Math.exp(-x * 2) * Math.cos(x * 7 * Math.PI); } *************** *** 21,25 **** long t[] = new long[n]; double x[] = new double[n]; ! for(int i = 0; i < n; i++) { t[i] = t0 + i * dt; x[i] = p.getValue(t[i]); --- 28,32 ---- long t[] = new long[n]; double x[] = new double[n]; ! for (int i = 0; i < n; i++) { t[i] = t0 + i * dt; x[i] = p.getValue(t[i]); *************** *** 40,46 **** gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); ! String filename = Util.getJRobinDemoPath("plottable.png"); g.saveAsPNG(filename, 400, 200); ! System.out.println("Graph saved to " + filename); } } --- 47,88 ---- gdef.setTimeAxis(TimeAxisUnit.DAY, 1, TimeAxisUnit.DAY, 1, "dd", true); RrdGraph g = new RrdGraph(gdef); ! String filename = Util.getJRobinDemoPath("plottable1.png"); g.saveAsPNG(filename, 400, 200); ! System.out.println("Graph1 saved to " + filename); ! } ! ! private void createGraph2() throws RrdException, IOException { ! GregorianCalendar[] timestamps = { ! new GregorianCalendar(2004, 2, 1, 0, 0, 0), ! new GregorianCalendar(2004, 2, 1, 2, 0, 0), ! new GregorianCalendar(2004, 2, 1, 7, 0, 0), ! new GregorianCalendar(2004, 2, 1, 14, 0, 0), ! new GregorianCalendar(2004, 2, 1, 17, 0, 0), ! new GregorianCalendar(2004, 2, 1, 19, 0, 0), ! new GregorianCalendar(2004, 2, 1, 23, 0, 0), ! new GregorianCalendar(2004, 2, 1, 24, 0, 0) ! }; ! double[] values = {100, 250, 230, 370, 350, 300, 340, 350}; ! LinearInterpolator linear = new LinearInterpolator(timestamps, values); ! linear.setInterpolationMethod(LinearInterpolator.INTERPOLATE_LEFT); ! CubicSplineInterpolator spline = new CubicSplineInterpolator(timestamps, values); ! RrdGraphDef gDef = new RrdGraphDef(timestamps[0], timestamps[timestamps.length - 1]); ! gDef.setTitle("Plottable demonstration"); ! gDef.setTimeAxisLabel("time"); ! gDef.setVerticalLabel("water level [inches]"); ! gDef.datasource("linear", linear); ! gDef.datasource("spline", spline); ! gDef.area("spline", Color.ORANGE, "Spline interpolation"); ! gDef.line("linear", Color.RED, "Linear inteprolation@r", 2); ! gDef.gprint("spline", "AVERAGE", "Average spline value: @0 inches@r"); ! gDef.gprint("linear", "AVERAGE", "Average linear value: @0 inches@r"); ! RrdGraph graph = new RrdGraph(gDef); ! String filename = Util.getJRobinDemoPath("plottable2.png"); ! graph.saveAsPNG(filename, 300, 100); ! System.out.println("Graph2 saved to " + filename); ! } ! ! public static void main(String[] args) throws RrdException, IOException { ! new PlottableDemo(); } } |