Exemplo n.º 1
0
  /**
   * Instantiate the class. Setting the position.
   *
   * @param p Set the axis position. Must be one of Axis.BOTTOM,
   * @param drawer
   * @param labels
   * @param visibleLabels
   *     <p>Axis.TOP, Axis.LEFT, Axis.RIGHT, Axis.HORIZONTAL or Axis.VERTICAL.
   *     <p>If one of the latter two are used then Axis.BOTTOM or * Axis.LEFT is assumed.
   */
  public LabelAxis(int p, Component drawer, String[][] labels, boolean[] visibleLabels) {

    NUMBER_OF_TICS = labels.length;

    // this.labels=labels;
    setLabels(labels, visibleLabels);

    title.setFont(new Font("TIMES NEW ROMAN", 1, 12));

    this.drawer = drawer;

    setPosition(p);

    switch (position) {
      case LEFT:
      case VERTICAL:
        title.setRotation(90);

        break;

      case RIGHT:
        title.setRotation(-90);

        break;

      default:
        title.setRotation(0);

        break;
    }
  }
Exemplo n.º 2
0
 /**
  * Set the title rotation angle. Only multiples of 90 degrees allowed.
  *
  * @param a Title rotation angle in degrees.
  */
 public void setTitleRotation(int a) {
   title.setRotation(a);
 }
Exemplo n.º 3
0
  /**
   * Draw a Vertical Axis.
   *
   * @param g Graphics context.
   */
  protected void drawVAxis(Graphics g) {

    Graphics lg;

    int i;

    int j;

    int x0, y0, x1, y1;

    int direction;

    int tempOffset = 0;

    double minor_step;

    double minor;

    Color c;

    double vmin = minimum * 1.001;

    double vmax = maximum * 1.001;

    double scale = (amax.y - amin.y) / (maximum - minimum);

    double val;

    //          System.out.println("Drawing Vertical Axis!");
    if (axiscolor != null) {
      g.setColor(axiscolor);
    }

    g.drawLine(amin.x, amin.y, amax.x, amax.y);

    if (position == RIGHT) {
      direction = -1;
    } else {
      direction = 1;
    }

    minor_step = label_step / (minor_tic_count + 1);

    val = label_start;

    for (i = 0; i < label_count; i++) {

      if (val >= vmin && val <= vmax) {

        x0 = amin.x;

        y0 = amax.y - (int) ((val - minimum) * scale);

        if (Math.abs(label_value[i]) <= 0.0001 && drawzero) {

          c = g.getColor();

          if (zerocolor != null) {
            g.setColor(zerocolor);
          }

          g.drawLine(x0, y0, x0 + data_window.width * direction, y0);

          g.setColor(c);

        } else if (paintGrid) {

          c = g.getColor();

          if (gridcolor != null) {
            g.setColor(gridcolor);
          }

          if (transparency != 255) {

            Graphics2D g2d = (Graphics2D) g;

            Paint pn = g2d.getPaint();

            if (gridcolor != null) {
              g.setColor(
                  new Color(
                      gridcolor.getRed(),
                      gridcolor.getGreen(),
                      gridcolor.getBlue(),
                      (int) transparency));
            }
          }

          if (!(i == 0 && dropFirstGridLine)) {
            g.drawLine(x0, y0, x0 + data_window.width * direction, y0);
          }

          g.setColor(c);
        }

        x1 = x0 + major_tic_size * direction;

        y1 = y0;

        g.drawLine(x0, y0, x1, y1);

        if (TICS_IN_BOTH_ENDS) {
          g.drawLine(
              x0 + data_window.width * direction - major_tic_size,
              y0,
              x0 + data_window.width * direction,
              y1);
        }
      }

      minor = val + minor_step;

      for (j = 0; j < minor_tic_count; j++) {

        if (minor >= vmin && minor <= vmax) {

          x0 = amin.x;

          y0 = amax.y - (int) ((minor - minimum) * scale);

          if (paintGrid) {

            c = g.getColor();

            if (gridcolor != null) {
              g.setColor(gridcolor);
            }

            if (transparency != 255) {

              Graphics2D g2d = (Graphics2D) g;

              Paint pn = g2d.getPaint();

              if (gridcolor != null) {
                g.setColor(
                    new Color(
                        gridcolor.getRed(),
                        gridcolor.getGreen(),
                        gridcolor.getBlue(),
                        (int) transparency));
              }
            }

            g.drawLine(x0, y0, x0 + data_window.width * direction, y0);

            g.setColor(c);
          }

          x1 = x0 + minor_tic_size * direction;

          y1 = y0;

          g.drawLine(x0, y0, x1, y1);

          if (TICS_IN_BOTH_ENDS) {
            g.drawLine(
                x0 + data_window.width * direction - minor_tic_size,
                y0,
                x0 + data_window.width * direction,
                y1);
          }
        }

        minor += minor_step;
      }

      val += label_step;
    }

    val = label_start;

    for (i = 0; i < label_count; i++) {

      if (val >= vmin && val <= vmax) {

        x0 = amin.x + tempOffset;

        y0 = amax.y - (int) ((val - minimum) * scale) + label.getAscent(g) / 2;

        if (position == RIGHT) {

          label.setText(" " + label_string[i]);

          label.draw(g, x0, y0, ChartLabel.LEFT);

        } else {

          label.setText(label_string[i] + " ");

          label.draw(g, x0, y0, ChartLabel.RIGHT);
        }
      }

      val += label_step;
    }

    /*
     *
     * if( !exponent.isNull() ) {
     *
     *
     *
     * y0 = amin.y;
     *
     *
     *
     * if(position == RIGHT ) {
     *
     * x0 = amin.x + max_label_width + exponent.charWidth(g,' ');
     *
     * exponent.draw(g,x0,y0,ChartLabel.LEFT);
     *
     * } else {
     *
     *
     *
     * x0 = amin.x - exponent.getWidth(g)-exponent.charWidth(g,' ');
     *
     * //x0 = amin.x - max_label_width - exponent.charWidth(g,' ');
     *
     * exponent.draw(g,x0,y0,ChartLabel.RIGHT);
     *
     * }
     *
     *
     *
     * }
     *
     */
    if (!title.isNull()) {

      y0 = amin.y + (amax.y - amin.y) / 2;

      if (title.getRotation() == 0 || title.getRotation() == 180) {

        if (position == RIGHT) {

          x0 = amin.x + max_label_width + title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.LEFT);

        } else {

          x0 = amin.x - max_label_width - title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.RIGHT);
        }

      } else {

        title.setJustification(ChartLabel.CENTER);

        if (position == RIGHT) {

          x0 = amin.x + max_label_width - title.getLeftEdge(g) + +title.charWidth(g, ' ');

        } else {

          x0 = amin.x - max_label_width - title.getRightEdge(g) - title.charWidth(g, ' ');
        }

        title.draw(g, x0, y0);
      }
    }

    if (!exponent.isNull()) {

      y0 = amin.y + exponent.getWidth(g);

      if (title.getRotation() == 0 || title.getRotation() == 180) {

        if (position == RIGHT) {

          x0 = amin.x + max_label_width + title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.LEFT);

        } else {

          x0 = amin.x - max_label_width - title.charWidth(g, ' ');

          title.draw(g, x0, y0, ChartLabel.RIGHT);
        }

      } else {

        if (position == RIGHT) {

          x0 = amin.x + max_label_width - title.getLeftEdge(g) + +title.charWidth(g, ' ');

        } else {

          x0 = amin.x - max_label_width - title.getRightEdge(g) - title.charWidth(g, ' ');
        }

        exponent.setBackground(Color.red);

        exponent.setRotation(90);

        exponent.setFontSize(12);

        exponent.setFontStyle(1);

        exponent.setFontName("TIMES NEW ROMAN");

        exponent.draw(g, x0, y0);
      }
    }
  }