src/org/math/plot/canvas/Plot2DCanvas.java

00001 package org.math.plot.canvas;
00002 
00003 import java.awt.*;
00004 
00005 import org.math.plot.plotObjects.*;
00006 import org.math.plot.plots.*;
00007 import org.math.plot.render.*;
00008 
00009 import static org.math.plot.plotObjects.Base.*;
00010 import static org.math.plot.utils.Array.*;
00011 import static org.math.plot.utils.Histogram.*;
00012 
00018 public class Plot2DCanvas extends PlotCanvas {
00019 
00020         // public final static String PARALLELHISTOGRAM = "PARALLELHISTOGRAM";
00021 
00022         private static final long serialVersionUID = 1L;
00023 
00024         public Plot2DCanvas() {
00025                 super();
00026                 ActionMode = ZOOM;
00027         }
00028 
00029         public Plot2DCanvas(Base b, BasePlot bp) {
00030                 super(b, bp);
00031                 ActionMode = ZOOM;
00032         }
00033 
00034         public Plot2DCanvas(double[] min, double[] max, String[] axesScales, String[] axesLabels) {
00035                 super(min, max, axesScales, axesLabels);
00036                 ActionMode = ZOOM;
00037         }
00038 
00039         public void initDrawer() {
00040                 draw = new AWTDrawer2D(this);
00041         }
00042 
00043         public void initBasenGrid(double[] min, double[] max) {
00044                 initBasenGrid(min, max, new String[] { LINEAR, LINEAR }, new String[] { "X", "Y" });
00045         }
00046 
00047         public void initBasenGrid() {
00048                 initBasenGrid(new double[] { 0, 0 }, new double[] { 1, 1 });
00049         }
00050 
00051         private static double[][] convertY(double[] XY) {
00052                 double[] x = increment(XY.length, 1, 1);
00053                 return mergeColumns(x, XY);
00054         }
00055 
00056         private static double[][] convertXY(double[]... XY) {
00057                 if (XY.length == 2 && XY[0].length != 2)
00058                         return mergeColumns(XY[0], XY[1]);
00059                 else
00060                         return XY;
00061         }
00062 
00063         public int addScatterPlot(String name, Color c, double[] Y) {
00064                 return addPlot(new ScatterPlot(name, c,  convertY(Y)));
00065         }
00066         
00067         public int addScatterPlot(String name, Color c, double[][] XY) {
00068                 return addPlot(new ScatterPlot(name, c, convertXY(XY)));
00069         }
00070         
00071         public int addScatterPlot(String name, Color c, double[] X, double[] Y) {
00072                 return addPlot(new ScatterPlot(name, c, convertXY(X,Y)));
00073         }
00074 
00075         public int addLinePlot(String name, Color c, double[] Y) {
00076                 return addPlot(new LinePlot(name, c, convertY(Y)));
00077         }
00078         
00079         public int addLinePlot(String name, Color c, double[][] XY) {
00080                 return addPlot(new LinePlot(name, c, convertXY(XY)));
00081         }
00082         
00083         public int addLinePlot(String name, Color c, double[] X, double[] Y) {
00084                 return addPlot(new LinePlot(name, c, convertXY(X,Y)));
00085         }
00086 
00087         public int addBarPlot(String name, Color c, double[] Y) {
00088                 return addPlot(new BarPlot(name, c, convertY(Y)));
00089         }
00090         
00091         public int addBarPlot(String name, Color c, double[][] XY) {
00092                 return addPlot(new BarPlot(name, c, convertXY(XY)));
00093         }
00094         
00095         public int addBarPlot(String name, Color c, double[] X, double[] Y) {
00096                 return addPlot(new BarPlot(name, c, convertXY(X,Y)));
00097         }
00098 
00099         public int addStaircasePlot(String name, Color c, double[] Y) {
00100                 return addPlot(new StaircasePlot(name, c, convertY(Y)));
00101         }
00102         
00103         public int addStaircasePlot(String name, Color c, double[][] XY) {
00104                 return addPlot(new StaircasePlot(name, c, convertXY(XY)));
00105         }
00106         
00107         public int addStaircasePlot(String name, Color c, double[] X, double[] Y) {
00108                 return addPlot(new StaircasePlot(name, c, convertXY(X,Y)));
00109         }
00110         
00111 
00112         public int addBoxPlot(String name, Color c, double[][] XY, double[][] dX) {
00113                 return addPlot(new BoxPlot2D(XY, dX, c, name));
00114         }
00115 
00116         public int addBoxPlot(String name, Color c, double[][] XYdX) {
00117                 return addPlot(new BoxPlot2D(getColumnsRangeCopy(XYdX, 0, 1), getColumnsRangeCopy(XYdX, 2, 3), c, name));
00118         }
00119 
00120         public int addHistogramPlot(String name, Color c, double[][] XY, double[] dX) {
00121                 return addPlot(new HistogramPlot2D(name, c, XY, dX));
00122         }
00123 
00124         public int addHistogramPlot(String name, Color c, double[][] XY, double dX) {
00125                 return addPlot(new HistogramPlot2D(name, c, XY, dX));
00126         }
00127 
00128         public int addHistogramPlot(String name, Color c, double[][] XYdX) {
00129                 return addPlot(new HistogramPlot2D(name, c, getColumnsRangeCopy(XYdX, 0, 1), getColumnCopy(XYdX, 2)));
00130         }
00131 
00132         public int addHistogramPlot(String name, Color c, double[] X, int n) {
00133                 double[][] XY = histogram_classes(X, n);
00134                 return addPlot(new HistogramPlot2D(name, c, XY, XY[1][0] - XY[0][0]));
00135         }
00136 
00137         public int addHistogramPlot(String name, Color c, double[] X, double... bounds) {
00138                 double[][] XY = histogram_classes(X, bounds);
00139                 return addPlot(new HistogramPlot2D(name, c, XY, XY[1][0] - XY[0][0]));
00140         }
00141 
00142         public int addHistogramPlot(String name, Color c, double[] X, double min, double max, int n) {
00143                 double[][] XY = histogram_classes(X, min, max, n);
00144                 return addPlot(new HistogramPlot2D(name, c, XY, XY[1][0] - XY[0][0]));
00145         }
00146 
00147         public int addCloudPlot(String name, Color c, double[][] sampleXY, int nX, int nY) {
00148                 double[][] XYh = histogram_classes_2D(sampleXY, nX, nY);
00149                 return addPlot(new CloudPlot2D(name, c, XYh, XYh[1][0] - XYh[0][0], XYh[nX][1] - XYh[0][1]));
00150         }
00151         
00152         public static void main(String[] args) {
00153                 /*
00154                  * Plot2DPanel p2d = new Plot2DPanel(DoubleArray.random(10, 2), "plot
00155                  * 1", PlotPanel.SCATTER); new FrameView(p2d);
00156                  * p2d.addPlot(DoubleArray.random(10, 2), "plot 2", PlotPanel.SCATTER);
00157                  * p2d.grid.getAxe(0).darkLabel.setCorner(0.5, -10);
00158                  * p2d.grid.getAxe(1).darkLabel.setCorner(0, -0.5);
00159                  */
00160         }
00161 }

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