/**
   * Draws an item label.
   *
   * @param g2 the graphics device.
   * @param orientation the orientation.
   * @param dataset the dataset.
   * @param series the series index (zero-based).
   * @param item the item index (zero-based).
   * @param x the x coordinate (in Java2D space).
   * @param y the y coordinate (in Java2D space).
   * @param negative indicates a negative value (which affects the item label position).
   */
  private void drawAdditionalItemLabel(
      Graphics2D g2,
      PlotOrientation orientation,
      XYDataset dataset,
      int series,
      int item,
      double x,
      double y) {

    if (this.additionalItemLabelGenerator == null) {
      return;
    }

    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset, series, item);

    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint =
        calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
    TextUtilities.drawRotatedString(
        label,
        g2,
        (float) anchorPoint.getX(),
        (float) anchorPoint.getY(),
        position.getTextAnchor(),
        position.getAngle(),
        position.getRotationAnchor());
  }
  /**
   * Draws an item label.
   *
   * @param g2 the graphics device.
   * @param orientation the orientation.
   * @param dataset the dataset.
   * @param row the row.
   * @param column the column.
   * @param x the x coordinate (in Java2D space).
   * @param y the y coordinate (in Java2D space).
   * @param negative indicates a negative value (which affects the item label position).
   */
  protected void drawItemLabel(
      Graphics2D g2,
      PlotOrientation orientation,
      CategoryDataset dataset,
      int row,
      int column,
      double x,
      double y,
      boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null) {
      Font labelFont = getItemLabelFont(row, column);
      Paint paint = getItemLabelPaint(row, column);
      g2.setFont(labelFont);
      g2.setPaint(paint);
      String label = generator.generateLabel(dataset, row, column);
      ItemLabelPosition position = null;
      if (!negative) {
        position = getPositiveItemLabelPosition(row, column);
      } else {
        position = getNegativeItemLabelPosition(row, column);
      }
      Point2D anchorPoint =
          calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
      TextUtilities.drawRotatedString(
          label,
          g2,
          (float) anchorPoint.getX(),
          (float) anchorPoint.getY(),
          position.getTextAnchor(),
          position.getAngle(),
          position.getRotationAnchor());
    }
  }
示例#3
0
  /**
   * Draws an item label. This method is provided as an alternative to {@link
   * #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, double, double, boolean)} so
   * that the bar can be used to calculate the label anchor point.
   *
   * @param g2 the graphics device.
   * @param dataset the dataset.
   * @param series the series index.
   * @param item the item index.
   * @param plot the plot.
   * @param generator the label generator ({@code null} permitted, in which case the method does
   *     nothing, just returns).
   * @param bar the bar.
   * @param negative a flag indicating a negative value.
   */
  protected void drawItemLabel(
      Graphics2D g2,
      XYDataset dataset,
      int series,
      int item,
      XYPlot plot,
      XYItemLabelGenerator generator,
      Rectangle2D bar,
      boolean negative) {

    if (generator == null) {
      return; // nothing to do
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
      return; // nothing to do
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
      position = getPositiveItemLabelPosition(series, item);
    } else {
      position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint =
        calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
      Shape bounds =
          TextUtilities.calculateRotatedStringBounds(
              label,
              g2,
              (float) anchorPoint.getX(),
              (float) anchorPoint.getY(),
              position.getTextAnchor(),
              position.getAngle(),
              position.getRotationAnchor());

      if (bounds != null) {
        if (!bar.contains(bounds.getBounds2D())) {
          if (!negative) {
            position = getPositiveItemLabelPositionFallback();
          } else {
            position = getNegativeItemLabelPositionFallback();
          }
          if (position != null) {
            anchorPoint =
                calculateLabelAnchorPoint(
                    position.getItemLabelAnchor(), bar, plot.getOrientation());
          }
        }
      }
    }

    if (position != null) {
      TextUtilities.drawRotatedString(
          label,
          g2,
          (float) anchorPoint.getX(),
          (float) anchorPoint.getY(),
          position.getTextAnchor(),
          position.getAngle(),
          position.getRotationAnchor());
    }
  }