Пример #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();
  }
Пример #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;
  }