00001 package org.math.plot.plots;
00002
00003 import java.awt.*;
00004
00005 import org.math.plot.render.*;
00006
00007 public class BoxPlot2D extends Plot {
00008
00009 double[] Xmin;
00010
00011 double[] Xmax;
00012
00013 double[] Ymin;
00014
00015 double[] Ymax;
00016
00017 double[][] widths;
00018
00019 double[][] XY;
00020
00021 public BoxPlot2D(double[][] _XY, double[][] w, Color c, String n) {
00022 super(n, c);
00023 XY = _XY;
00024 widths = w;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 Xmin = new double[XY.length];
00037 Xmax = new double[XY.length];
00038 Ymin = new double[XY.length];
00039 Ymax = new double[XY.length];
00040 for (int i = 0; i < XY.length; i++) {
00041 Xmin[i] = XY[i][0] - widths[i][0] / 2;
00042 Xmax[i] = XY[i][0] + widths[i][0] / 2;
00043 Ymin[i] = XY[i][1] - widths[i][1] / 2;
00044 Ymax[i] = XY[i][1] + widths[i][1] / 2;
00045 }
00046
00047 }
00048
00049 public void plot(AbstractDrawer draw, Color c) {
00050 if (!visible)
00051 return;
00052
00053 draw.setColor(c);
00054 draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
00055 for (int i = 0; i < XY.length; i++) {
00056 draw.drawLine(new double[] { Xmin[i], Ymin[i] }, new double[] { Xmax[i], Ymin[i] });
00057 draw.drawLine(new double[] { Xmax[i], Ymin[i] }, new double[] { Xmax[i], Ymax[i] });
00058 draw.drawLine(new double[] { Xmax[i], Ymax[i] }, new double[] { Xmin[i], Ymax[i] });
00059 draw.drawLine(new double[] { Xmin[i], Ymax[i] }, new double[] { Xmin[i], Ymin[i] });
00060 draw.setDotType(AbstractDrawer.ROUND_DOT);
00061 draw.setDotRadius(AbstractDrawer.DEFAULT_DOT_RADIUS);
00062 draw.drawDot(XY[i]);
00063 }
00064 }
00065
00066 @Override
00067 public void setData(double[][] d) {
00068 XY = d;
00069 }
00070
00071 @Override
00072 public double[][] getData() {
00073 return XY;
00074 }
00075
00076 public void setDataWidth(double[][] w) {
00077 widths = w;
00078 }
00079
00080 public double[][] getDataWidth() {
00081 return widths;
00082 }
00083
00084 public void setData(double[][] d, double[][] w) {
00085 XY = d;
00086 widths = w;
00087 }
00088
00089 public double[] isSelected(int[] screenCoordTest, AbstractDrawer draw) {
00090 for (int i = 0; i < XY.length; i++) {
00091 int[] screenCoord = draw.project(XY[i]);
00092
00093 if ((screenCoord[0] + note_precision > screenCoordTest[0]) && (screenCoord[0] - note_precision < screenCoordTest[0])
00094 && (screenCoord[1] + note_precision > screenCoordTest[1]) && (screenCoord[1] - note_precision < screenCoordTest[1]))
00095 return XY[i];
00096 }
00097 return null;
00098 }
00099
00100 }