Exemple #1
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);
  }