src/org/math/plot/plots/StaircasePlot.java

00001 package org.math.plot.plots;
00002 
00003 import java.awt.*;
00004 
00005 import javax.swing.*;
00006 
00007 import org.math.plot.*;
00008 import org.math.plot.render.*;
00009 
00010 public class StaircasePlot extends ScatterPlot {
00011 
00012         public boolean link = true;
00013 
00014         public StaircasePlot(String n, Color c, boolean[][] _pattern, double[][] _XY) {
00015                 super(n, c, _pattern, _XY);
00016         }
00017 
00018         public StaircasePlot(String n, Color c, int _type, int _radius, double[][] _XY) {
00019                 super(n, c, _type, _radius, _XY);
00020         }
00021 
00022         public StaircasePlot(String n, Color c, double[][] _XY) {
00023                 super(n, c, _XY);
00024         }
00025 
00026         public void plot(AbstractDrawer draw, Color c) {
00027                 if (!visible)
00028                         return;
00029 
00030                 //System.out.println(Array.toString(XY));
00031                 
00032                 draw.setColor(c);
00033                 draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
00034                 for (int i = 0; i < XY.length - 1; i++) {
00035                         double[] begin = XY[i].clone();
00036                         double[] end = XY[i + 1].clone();
00037                         end[end.length - 1] = XY[i][end.length - 1];
00038                         draw.drawLine(begin, end);
00039                 }
00040                 
00041                 //System.out.println(Array.toString(XY));
00042 
00043                 if (link) {
00044                         for (int i = 0; i < XY.length - 2; i++) {
00045                                 double[] begin = XY[i+1].clone();
00046                                 double[] end = XY[i + 1].clone();
00047                                 begin[begin.length - 1] = XY[i][begin.length - 1];
00048                                 draw.drawLine(begin, end);
00049                         }
00050                 }
00051                 //System.out.println(Array.toString(XY));
00052                 
00053         }
00054         
00055         public static void main(String[] args) {
00056                 Plot2DPanel p = new Plot2DPanel();
00057 
00058                         double[] X = new double[10];
00059                         double[] Y = new double[10];
00060                         for (int j = 0; j < X.length; j++) {
00061                                 X[j] = j;
00062                                 Y[j] = Math.random();
00063                         }
00064                         p.addStaircasePlot("toto", X,Y);
00065                 
00066                 new FrameView(p).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00067         }
00068         
00069 }

Generated on Wed Sep 5 21:44:02 2007 for jmathplot by  doxygen 1.5.1