Пример #1
0
  /**
   * Draw the axis using the passed Graphics context.
   *
   * @param g Graphics context for drawing
   */
  public void drawAxis(Graphics g) {

    Graphics lg;

    // System.out.print("\n\nmaximum before:"+maximum);
    // System.out.print("\nminimum before:"+minimum);
    if (!redraw) {
      return;
    }

    // if( amin.equals(amax) ) return;
    if (width == 0) {
      width = getAxisWidth(g);
    }

    lg = g.create();

    title.setDrawingComponent(drawer);

    label.setDrawingComponent(drawer);

    exponent.setDrawingComponent(drawer);

    if (orientation == HORIZONTAL) {

      drawHAxis(lg);

    } else {

      drawVAxis(lg);
    }

    // System.out.print("\nmaximum after:"+maximum);
    // System.out.print("\nminimum after:"+minimum);
  }
Пример #2
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;
    }
  }
Пример #3
0
  // The height of the label... (found by taking cos(angle) of the longest string)
  public int getMaxLabelWidth(Graphics g) {

    int ret = Integer.MIN_VALUE;

    Graphics2D g2D = (Graphics2D) g;

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

    FontMetrics fm = g.getFontMetrics(font);

    for (String[] label1 : labels) {
      for (int j = 0; j < labels[0].length; j++) {
        if (visibleLabels[j + 1] && fm.stringWidth(label1[j]) > ret) {
          ret = fm.stringWidth(label1[j]);
        }
      }
    }

    int titleHeight = title.getHeight(g);

    // Font f = title.getFont();
    if (ret > 0) {
      ret = (int) (ret * Math.sin(DEG2RAD * rotation));
    } else {
      ret = 0;
    }

    // System.out.print("width: "+(ret*Math.sin(DEG2RAD*rotation)));
    return ret + offset + fm.getHeight() + titleHeight;

    // return titleHeight ;
  }
Пример #4
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);
    }
  }
Пример #5
0
 /**
  * Set the font of the exponent
  *
  * @param f font.
  */
 public void setExponentFont(Font f) {
   exponent.setFont(f);
 }
Пример #6
0
 /**
  * Set the color of the exponent
  *
  * @param c Color.
  */
 public void setExponentColor(Color c) {
   exponent.setColor(c);
 }
Пример #7
0
 /**
  * Set the font of the labels.
  *
  * @param f font.
  */
 public void setLabelFont(Font f) {
   label.setFont(f);
 }
Пример #8
0
 /**
  * Set the color of the labels
  *
  * @param c Color of the labels.
  */
 public void setLabelColor(Color c) {
   label.setColor(c);
 }
Пример #9
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);
 }
Пример #10
0
 /**
  * Set the font of the title
  *
  * @param f Title font.
  */
 public void setTitleFont(Font f) {
   title.setFont(f);
 }
Пример #11
0
 /**
  * Set the color of the title
  *
  * @param c Color of the title.
  */
 public void setTitleColor(Color c) {
   title.setColor(c);
 }
Пример #12
0
 public String getTitleText() {
   return title.getText();
 }
Пример #13
0
  /**
   * Set the title of the axis
   *
   * @param s string containing text.
   */
  public void setTitleText(String s) {

    title.setText(s);
  }
Пример #14
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);
      }
    }
  }