Exemple #1
0
  /**
   * This paints the entire plot. It calls the draw methods of all the attached axis and data sets.
   * The order of drawing is - Axis first, data legends next, data last.
   *
   * @params g Graphics state.
   */
  public void paint(Graphics g) {
    int i;
    Graphics lg = g.create();
    Rectangle r = bounds();

    /* The r.x and r.y returned from bounds is relative to the
     ** parents space so set them equal to zero.
     */
    r.x = 0;
    r.y = 0;

    if (DefaultBackground == null) DefaultBackground = this.getBackground();
    if (DataBackground == null) DataBackground = this.getBackground();

    //        System.out.println("Graph2D paint method called!");

    if (!paintAll) return;

    r.x += borderLeft;
    r.y += borderTop;
    r.width -= borderLeft + borderRight;
    r.height -= borderBottom + borderTop;

    paintFirst(lg, r);

    if (!axis.isEmpty()) r = drawAxis(lg, r);
    else {
      if (clearAll) {
        Color c = g.getColor();
        g.setColor(DataBackground);
        g.fillRect(r.x, r.y, r.width, r.height);
        g.setColor(c);
      }
      drawFrame(lg, r.x, r.y, r.width, r.height);
    }

    paintBeforeData(lg, r);

    if (!dataset.isEmpty()) {

      datarect.x = r.x;
      datarect.y = r.y;
      datarect.width = r.width;
      datarect.height = r.height;

      for (i = 0; i < dataset.size(); i++) {
        ((DataSet) dataset.elementAt(i)).draw_data(lg, r);
      }
    }

    paintLast(lg, r);

    lg.dispose();
  }
Exemple #2
0
  /** Detach All attached Axes. */
  public void detachAxes() {
    int i;

    if (axis == null | axis.isEmpty()) return;

    for (i = 0; i < axis.size(); i++) {
      ((Axis) axis.elementAt(i)).detachAll();
      ((Axis) axis.elementAt(i)).g2d = null;
    }

    axis.removeAllElements();
  }
Exemple #3
0
  /**
   * Get the Minimum Y value of all attached DataSets.
   *
   * @return The minimum value
   */
  public double getYmin() {
    DataSet d;
    double min = 0.0;

    if (dataset == null | dataset.isEmpty()) return min;
    for (int i = 0; i < dataset.size(); i++) {
      d = ((DataSet) dataset.elementAt(i));
      if (i == 0) min = d.getYmin();
      else min = Math.min(min, d.getYmin());
    }

    return min;
  }
Exemple #4
0
  /**
   * Get the Maximum Y value of all attached DataSets.
   *
   * @return The maximum value
   */
  public double getYmax() {
    DataSet d;
    double max = 0.0;

    if (dataset == null | dataset.isEmpty()) return max;
    for (int i = 0; i < dataset.size(); i++) {
      d = ((DataSet) dataset.elementAt(i));
      if (i == 0) max = d.getYmax();
      else max = Math.max(max, d.getYmax());
    }

    return max;
  }
Exemple #5
0
  /** Detach All the DataSets from the class. */
  public void detachDataSets() {
    DataSet d;
    int i;

    if (dataset == null | dataset.isEmpty()) return;

    for (i = 0; i < dataset.size(); i++) {
      d = ((DataSet) dataset.elementAt(i));
      if (d.xaxis != null) d.xaxis.detachDataSet(d);
      if (d.yaxis != null) d.yaxis.detachDataSet(d);
    }

    dataset.removeAllElements();
  }
Exemple #6
0
  /**
   * Force the plot to have an aspect ratio of 1 by forcing the axes to have the same range. If the
   * range of the axes are very different some extremely odd things can occur. All axes are forced
   * to have the same range, so more than 2 axis is pointless.
   */
  protected Rectangle ForceSquare(Graphics g, Rectangle r) {
    Axis a;
    Rectangle dr;
    int x = r.x;
    int y = r.y;
    int width = r.width;
    int height = r.height;

    double xmin;
    double xmax;
    double ymin;
    double ymax;

    double xrange = 0.0;
    double yrange = 0.0;
    double range;

    double aspect;

    if (dataset == null | dataset.isEmpty()) return r;

    /*
     **          Force all the axis to have the same range. This of course
     **          means that anything other than one xaxis and one yaxis
     **          is a bit pointless.
     */
    for (int i = 0; i < axis.size(); i++) {
      a = (Axis) axis.elementAt(i);
      range = a.maximum - a.minimum;
      if (a.isVertical()) {
        yrange = Math.max(range, yrange);
      } else {
        xrange = Math.max(range, xrange);
      }
    }

    if (xrange <= 0 | yrange <= 0) return r;

    if (xrange > yrange) range = xrange;
    else range = yrange;

    for (int i = 0; i < axis.size(); i++) {
      a = (Axis) axis.elementAt(i);
      a.maximum = a.minimum + range;
    }
    /*
     **          Get the new data rectangle
     */
    dr = getDataRectangle(g, r);
    /*
     **          Modify the data rectangle so that it is square.
     */
    if (dr.width > dr.height) {
      x += (dr.width - dr.height) / 2.0;
      width -= dr.width - dr.height;
    } else {
      y += (dr.height - dr.width) / 2.0;
      height -= dr.height - dr.width;
    }

    return new Rectangle(x, y, width, height);
  }