/**
   * Draws the axis on a Java 2D graphics device (such as the screen or a printer).
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param cursor the cursor location.
   * @param plotArea the area within which the axis should be drawn (<code>null</code> not
   *     permitted).
   * @param dataArea the area within which the plot is being drawn (<code>null</code> not
   *     permitted).
   * @param edge the location of the axis (<code>null</code> not permitted).
   * @param plotState collects information about the plot (<code>null</code> permitted).
   * @return the axis state (never <code>null</code>).
   */
  public AxisState draw(
      Graphics2D g2,
      double cursor,
      Rectangle2D plotArea,
      Rectangle2D dataArea,
      RectangleEdge edge,
      PlotRenderingInfo plotState) {

    // if the axis is not visible, don't draw it...
    if (!isVisible()) {
      return new AxisState(cursor);
    }

    // calculate the adjusted data area taking into account the 3D effect...
    // this assumes that there is a 3D renderer, all this 3D effect is a bit of an
    // ugly hack...
    CategoryPlot plot = (CategoryPlot) getPlot();

    Rectangle2D adjustedDataArea = new Rectangle2D.Double();
    if (plot.getRenderer() instanceof Effect3D) {
      Effect3D e3D = (Effect3D) plot.getRenderer();
      double adjustedX = dataArea.getMinX();
      double adjustedY = dataArea.getMinY();
      double adjustedW = dataArea.getWidth() - e3D.getXOffset();
      double adjustedH = dataArea.getHeight() - e3D.getYOffset();

      if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
        adjustedY += e3D.getYOffset();
      } else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
        adjustedX += e3D.getXOffset();
      }
      adjustedDataArea.setRect(adjustedX, adjustedY, adjustedW, adjustedH);
    } else {
      adjustedDataArea.setRect(dataArea);
    }

    // draw the category labels and axis label
    AxisState state = new AxisState(cursor);
    state = drawCategoryLabels(g2, plotArea, adjustedDataArea, edge, state, plotState);
    state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);

    return state;
  }
Example #2
0
  /**
   * Draws the axis on a Java 2D graphics device (such as the screen or a printer).
   *
   * @param g2 the graphics device.
   * @param cursor the cursor.
   * @param plotArea the area for drawing the axes and data.
   * @param dataArea the area for drawing the data (a subset of the plotArea).
   * @param edge the axis location.
   * @param plotState collects information about the plot (<code>null</code> permitted).
   * @return The updated cursor value.
   */
  public AxisState draw(
      Graphics2D g2,
      double cursor,
      Rectangle2D plotArea,
      Rectangle2D dataArea,
      RectangleEdge edge,
      PlotRenderingInfo plotState) {

    // if the axis is not visible, don't draw it...
    if (!isVisible()) {
      AxisState state = new AxisState(cursor);
      // even though the axis is not visible, we need ticks for the
      // gridlines...
      List ticks = refreshTicks(g2, state, dataArea, edge);
      state.setTicks(ticks);
      return state;
    }

    // calculate the adjusted data area taking into account the 3D effect...
    double xOffset = 0.0;
    double yOffset = 0.0;
    Plot plot = getPlot();
    if (plot instanceof CategoryPlot) {
      CategoryPlot cp = (CategoryPlot) plot;
      CategoryItemRenderer r = cp.getRenderer();
      if (r instanceof Effect3D) {
        Effect3D e3D = (Effect3D) r;
        xOffset = e3D.getXOffset();
        yOffset = e3D.getYOffset();
      }
    }

    double adjustedX = dataArea.getMinX();
    double adjustedY = dataArea.getMinY();
    double adjustedW = dataArea.getWidth() - xOffset;
    double adjustedH = dataArea.getHeight() - yOffset;

    if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
      adjustedY += yOffset;
    } else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
      adjustedX += xOffset;
    }
    Rectangle2D adjustedDataArea =
        new Rectangle2D.Double(adjustedX, adjustedY, adjustedW, adjustedH);

    // draw the tick marks and labels...
    AxisState info = drawTickMarksAndLabels(g2, cursor, plotArea, adjustedDataArea, edge);

    // draw the axis label...
    info = drawLabel(getLabel(), g2, plotArea, dataArea, edge, info);

    return info;
  }