Example #1
0
  /** Calculate the rectangle occupied by the data */
  protected Rectangle getDataRectangle(Graphics g, Rectangle r) {
    Axis a;
    int waxis;
    int x = r.x;
    int y = r.y;
    int width = r.width;
    int height = r.height;

    for (int i = 0; i < axis.size(); i++) {
      a = ((Axis) axis.elementAt(i));

      waxis = a.getAxisWidth(g);

      switch (a.getAxisPos()) {
        case Axis.LEFT:
          x += waxis;
          width -= waxis;
          break;
        case Axis.RIGHT:
          width -= waxis;
          break;
        case Axis.TOP:
          y += waxis;
          height -= waxis;
          break;
        case Axis.BOTTOM:
          height -= waxis;
          break;
      }
    }

    return new Rectangle(x, y, width, height);
  }
Example #2
0
  /**
   * Draw the Axis. As each axis is drawn and aligned less of the canvas is avaliable to plot the
   * data. The returned Rectangle is the canvas area that the data is plotted in.
   */
  protected Rectangle drawAxis(Graphics g, Rectangle r) {
    Axis a;
    int waxis;
    Rectangle dr;
    int x;
    int y;
    int width;
    int height;

    if (square) r = ForceSquare(g, r);

    dr = getDataRectangle(g, r);

    x = dr.x;
    y = dr.y;
    width = dr.width;
    height = dr.height;

    if (clearAll) {
      Color c = g.getColor();
      g.setColor(DataBackground);
      g.fillRect(x, y, width, height);
      g.setColor(c);
    }

    // Draw a frame around the data area (If requested)
    if (frame) drawFrame(g, x, y, width, height);

    // Now draw the axis in the order specified aligning them with the final
    // data area.
    for (int i = 0; i < axis.size(); i++) {
      a = ((Axis) axis.elementAt(i));

      a.data_window = new Dimension(width, height);

      switch (a.getAxisPos()) {
        case Axis.LEFT:
          r.x += a.width;
          r.width -= a.width;
          a.positionAxis(r.x, r.x, y, y + height);
          if (r.x == x) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
        case Axis.RIGHT:
          r.width -= a.width;
          a.positionAxis(r.x + r.width, r.x + r.width, y, y + height);
          if (r.x + r.width == x + width) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
        case Axis.TOP:
          r.y += a.width;
          r.height -= a.width;
          a.positionAxis(x, x + width, r.y, r.y);
          if (r.y == y) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
        case Axis.BOTTOM:
          r.height -= a.width;
          a.positionAxis(x, x + width, r.y + r.height, r.y + r.height);
          if (r.y + r.height == y + height) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
      }
    }

    return r;
  }