Beispiel #1
0
  @Override
  public void paint(Graphics2D g2d, Rectangle rect) {
    super.paint(g2d, rect);

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, options.getAlpha()));

    for (int i = 0; i < vars.length; i++) {
      Var v = vars[i];
      if (v.rowCount() == 0) {
        continue;
      }
      double[] p = new double[] {0.25, 0.5, 0.75};
      double[] q = Quantiles.from(v, p).values();
      double iqr = q[2] - q[0];
      double innerFence = 1.5 * iqr;
      double outerFence = 3 * iqr;

      double x1 = i + 0.5 - 0.3;
      double x2 = i + 0.5;
      double x3 = i + 0.5 + 0.3;

      // first we fill the space

      g2d.setColor(options.getColor(i));
      g2d.fill(
          new Rectangle2D.Double(
              xScale(x1), yScale(q[2]), xScale(x3) - xScale(x1), yScale(q[0]) - yScale(q[2])));

      g2d.setColor(ColorPalette.STANDARD.getColor(0));

      // median
      g2d.setStroke(new BasicStroke(options.getLwd() * 2));
      g2d.draw(new Line2D.Double(xScale(x1), yScale(q[1]), xScale(x3), yScale(q[1])));

      // box
      g2d.setStroke(new BasicStroke(options.getLwd()));

      g2d.draw(new Line2D.Double(xScale(x1), yScale(q[0]), xScale(x3), yScale(q[0])));
      g2d.draw(new Line2D.Double(xScale(x1), yScale(q[2]), xScale(x3), yScale(q[2])));
      g2d.draw(new Line2D.Double(xScale(x1), yScale(q[0]), xScale(x1), yScale(q[2])));
      g2d.draw(new Line2D.Double(xScale(x3), yScale(q[0]), xScale(x3), yScale(q[2])));

      // outliers
      double upperwhisker = q[2];
      double lowerqhisker = q[0];
      for (int j = 0; j < v.rowCount(); j++) {
        double point = v.value(j);
        if ((point > q[2] + outerFence) || (point < q[0] - outerFence)) {
          // big outlier
          g2d.setStroke(new BasicStroke(options.getLwd()));
          PchPalette.STANDARD.draw(
              g2d, xScale(x2), yScale(point), options.getSz(i), options.getPch(1));
          continue;
        }
        if ((point > q[2] + innerFence) || (point < q[0] - innerFence)) {
          // outlier
          g2d.setStroke(new BasicStroke(options.getLwd()));
          PchPalette.STANDARD.draw(
              g2d, xScale(x2), yScale(point), options.getSz(i), options.getPch(0));
          continue;
        }
        if ((point > upperwhisker) && (point < q[2] + innerFence)) {
          upperwhisker = Math.max(upperwhisker, point);
        }
        if ((point < lowerqhisker) && (point >= q[0] - innerFence)) {
          lowerqhisker = Math.min(lowerqhisker, point);
        }
      }

      // whiskers
      g2d.draw(
          new Line2D.Double(xScale(x1), yScale(upperwhisker), xScale(x3), yScale(upperwhisker)));
      g2d.draw(
          new Line2D.Double(xScale(x1), yScale(lowerqhisker), xScale(x3), yScale(lowerqhisker)));

      g2d.setStroke(
          new BasicStroke(
              options.getLwd(),
              BasicStroke.CAP_BUTT,
              BasicStroke.JOIN_MITER,
              1f,
              new float[] {8},
              0));
      g2d.draw(new Line2D.Double(xScale(x2), yScale(q[2]), xScale(x2), yScale(upperwhisker)));
      g2d.draw(new Line2D.Double(xScale(x2), yScale(q[0]), xScale(x2), yScale(lowerqhisker)));
    }
  }
Beispiel #2
0
 public double f(double x) {
   return Math.sin(x);
 }