Ejemplo n.º 1
0
  protected void drawHAxis(Graphics g) {

    Graphics lg;

    int i;

    int j;

    int x0, y0, x1, y1;

    int direction;

    // int tempOffset;
    double minor_step;

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

    Color c;

    double val;

    double minor;

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

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

    // System.out.print("\ndrawing til x: "+amax.x);
    minor_step = label_step / (minor_tic_count + 1);

    val = label_start;

    ylocations = new int[labels.length];

    for (i = 0; i < labels.length; i++) {

      // if( val >= vmin && val <= vmax ) {
      y0 = amin.y;

      // x0 = amin.x + (int)( ( val - minimum ) * scale);
      // x0 = amin.x + (int)(( (amax.x - amin.x - endLength(g))/( labels[0].length-1 ))*i);
      x0 = amin.x + (int) (((amax.x - amin.x) / (labels.length - 1)) * i);

      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)) && (!(i == labels.length - 1 && dropLastGridLine))) {
          g.drawLine(x0, y0, x0, y0 + data_window.height * direction);
        }

        g.setColor(c);
      }

      x1 = x0;

      y1 = y0 + major_tic_size * direction;

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

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

      ylocations[i] = x0;

      // }
      minor = val + minor_step;

      /*
       *
       * for(j=0; j<minor_tic_count; j++) {
       *
       * //if( minor >= vmin && minor <= vmax ) {
       *
       * y0 = amin.y;
       *
       * x0 = amin.x + (int)( ( minor - minimum ) * scale);
       *
       * if( paintGrid ) {
       *
       * c = g.getColor();
       *
       * if(gridcolor != null) g.setColor(gridcolor);
       *
       * g.drawLine(x0,y0,x0,y0+data_window.height*direction);
       *
       * g.setColor(c);
       *
       * }
       *
       * x1 = x0;
       *
       * y1 = y0 + minor_tic_size*direction;
       *
       * g.drawLine(x0,y0,x1,y1);
       *
       * if(TICS_IN_BOTH_ENDS)
       * g.drawLine(x0,y0+data_window.height*direction,x0,y0+data_window.height*direction+minor_tic_size);
       *
       * // }
       *
       * minor += minor_step;
       *
       * }
       *
       */
      val += label_step;
    }

    /*
     *
     * if(position == TOP ) {
     *
     * tempOffset = - label.getLeading(g) - label.getDescent(g);
     *
     * } else {
     *
     * tempOffset = + label.getLeading(g) + label.getAscent(g);
     *
     * }
     *
     */
    val = label_start;

    g.setFont(font);

    Graphics2D g2D = (Graphics2D) g;

    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    FontMetrics fm = g.getFontMetrics(font);

    int labelWidth = fm.getHeight();

    //       int labelWidth=16;
    // System.out.print("\n"+labelWidth);
    // int additionalSpace = 0;
    // if(rotation=40) additionalSpace =
    //         double height = Math.sin(DEG2RAD*rotation)*labelWidth;
    //          double additionalSpace = labelWidth/Math.sin(DEG2RAD*(rotation));
    double additionalSpace = 0;

    int height = 0;

    //
    int visibleLabs = 0;

    for (int k = 1; k < labels[0].length; k++) {

      if (visibleLabels[k]) {
        visibleLabs++;
      }
    }

    int beg = (visibleLabs * labelWidth) - (4 * (visibleLabs - 1));

    beg = beg / 2;

    Color before = g.getColor();

    for (i = 0; i < labels.length; i++) {

      if (groupColors != null) {
        g.setColor(groupColors[i]);
      } else {
        g.setColor(Color.GRAY); // new Color(180, 180, 180));
      }

      y0 = amin.y + offset;

      // x0 = amin.x + (int)(( (amax.x - amin.x)/( labels[0].length))*i);
      x0 = amin.x + (int) (((amax.x - amin.x) / (labels.length - 1)) * i);

      // x0 = amin.x + (int)(( (amax.x - amin.x - endLength(g))/( labels[0].length-1 ))*i);
      // int labellength =((int)((amax.x - amin.x)/( labels[0].length)))*labels[0].length ;
      // int endpoint = amin.x +endLength(g)+labellength;
      // g.drawLine( endpoint,y0-4,endpoint,y0+4 );
      x0 = x0 - beg;

      // x0=x0-beg;
      for (j = 0; j < labels[0].length; j++) {

        if (visibleLabels[j + 1]) {

          drawRotatedLabel(labels[i][j], g, false, x0, y0, rotation);

          x0 += (labelWidth);
        }
      }
    }

    g.setColor(before);

    // Graphics2D g2=(Graphics2D)g;
    // g2.rotate(45);
    if (!title.isNull()) {

      if (position == TOP) {

        y0 =
            amin.y
                - label.getLeading(g)
                - label.getDescent(g)
                - title.getLeading(g)
                - title.getDescent(g);

      } else {

        y0 =
            amax.y
                + label.getLeading(g)
                + label.getAscent(g)
                + title.getLeading(g)
                + title.getAscent(g);
      }

      x0 = amin.x + (amax.x - amin.x) / 2;

      // y0=amax.y+width+3;
      y0 = amax.y + this.getMaxLabelWidth(g) + 6 - (title.getHeight(g));

      // Graphics2D g2D = (Graphics2D) g;
      // g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
      // RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      // title.setFont(null);
      if (axiscolor != null) {
        title.setColor(axiscolor);
      }

      title.draw(g, x0, y0, ChartLabel.CENTER);
    }
  }
Ejemplo n.º 2
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);
      }
    }
  }