예제 #1
0
  /**
   * Returns the content size for the title. This will reflect the fact that a text title positioned
   * on the left or right of a chart will be rotated 90 degrees.
   *
   * @param g2 the graphics device.
   * @param widthRange the width range.
   * @param heightRange the height range.
   * @return The content size.
   */
  protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) {

    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {

      float maxWidth = (float) widthRange.getUpperBound();

      // determine the space required for the axis
      AxisSpace space =
          this.axis.reserveSpace(
              g2, null, new Rectangle2D.Double(0, 0, maxWidth, 100), RectangleEdge.BOTTOM, null);

      return new Size2D(
          maxWidth, this.stripWidth + this.axisOffset + space.getTop() + space.getBottom());
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
      float maxHeight = (float) heightRange.getUpperBound();
      AxisSpace space =
          this.axis.reserveSpace(
              g2, null, new Rectangle2D.Double(0, 0, 100, maxHeight), RectangleEdge.RIGHT, null);
      return new Size2D(
          this.stripWidth + this.axisOffset + space.getLeft() + space.getRight(), maxHeight);
    } else {
      throw new RuntimeException("Unrecognised position.");
    }
  }
예제 #2
0
  /**
   * Calculates the axis space required.
   *
   * @param g2 the graphics device.
   * @param plotArea the plot area.
   * @return The space.
   */
  protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {

    AxisSpace space = new AxisSpace();
    PlotOrientation orientation = getOrientation();

    // work out the space required by the domain axis...
    AxisSpace fixed = getFixedDomainAxisSpace();
    if (fixed != null) {
      if (orientation == PlotOrientation.HORIZONTAL) {
        space.setLeft(fixed.getLeft());
        space.setRight(fixed.getRight());
      } else if (orientation == PlotOrientation.VERTICAL) {
        space.setTop(fixed.getTop());
        space.setBottom(fixed.getBottom());
      }
    } else {
      ValueAxis xAxis = getDomainAxis();
      RectangleEdge xEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation);
      if (xAxis != null) {
        space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space);
      }
    }

    Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);

    // work out the maximum height or width of the non-shared axes...
    int n = this.subplots.size();
    this.subplotAreas = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
      usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.VERTICAL) {
      usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }

    for (int i = 0; i < n; i++) {
      XYPlot plot = (XYPlot) this.subplots.get(i);

      // calculate sub-plot area
      if (orientation == PlotOrientation.HORIZONTAL) {
        double w = usableSize * plot.getWeight() / this.totalWeight;
        this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
        x = x + w + this.gap;
      } else if (orientation == PlotOrientation.VERTICAL) {
        double h = usableSize * plot.getWeight() / this.totalWeight;
        this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
        y = y + h + this.gap;
      }

      AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null);
      space.ensureAtLeast(subSpace);
    }

    return space;
  }