Example usage for org.jfree.chart.axis AxisState getMax

List of usage examples for org.jfree.chart.axis AxisState getMax

Introduction

In this page you can find the example usage for org.jfree.chart.axis AxisState getMax.

Prototype

public double getMax() 

Source Link

Document

Returns the maximum width/height.

Usage

From source file:com.newatlanta.bluedragon.CategoryAxis.java

public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge,
        AxisSpace space) {// w  ww .j  a v a  2  s. com

    // create a new space object if one wasn't supplied...
    if (space == null) {
        space = new AxisSpace();
    }

    // if the axis is not visible, no additional space is required...
    if (!isVisible()) {
        return space;
    }

    // calculate the max size of the tick labels (if visible)...
    double tickLabelHeight = 0.0;
    double tickLabelWidth = 0.0;
    if (isTickLabelsVisible()) {
        g2.setFont(getTickLabelFont());
        AxisState state = new AxisState();
        // we call refresh ticks just to get the maximum width or height
        if (RectangleEdge.isTopOrBottom(edge)) {
            // BEGIN fix for category labels that wrap
            // If space has been reserved to the left and right then we need to
            // reduce the plot area
            // by this amount so that the space needed by category labels that wrap
            // on to multiple lines
            // will be calculated properly.
            Rectangle2D newPlotArea = new Rectangle2D.Double(plotArea.getX(), plotArea.getY(),
                    plotArea.getWidth() - space.getLeft() - space.getRight(), plotArea.getHeight());
            refreshTicks(g2, state, newPlotArea, edge);
            // END fix for category labels that wrap
        } else {
            refreshTicks(g2, state, plotArea, edge);
        }
        if (edge == RectangleEdge.TOP) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.BOTTOM) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.LEFT) {
            tickLabelWidth = state.getMax();
        } else if (edge == RectangleEdge.RIGHT) {
            tickLabelWidth = state.getMax();
        }
    }

    // get the axis label size and update the space object...
    Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
    double labelHeight = 0.0;
    double labelWidth = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelHeight + this.getCategoryLabelPositionOffset(), edge);
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth + this.getCategoryLabelPositionOffset(), edge);
    }
    return space;

}

From source file:hudson.util.NoOverlapCategoryAxis.java

@Override
protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea,
        RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {

    if (state == null) {
        throw new IllegalArgumentException("Null 'state' argument.");
    }/*from w ww. j av a  2s.com*/

    if (isTickLabelsVisible()) {
        java.util.List ticks = refreshTicks(g2, state, plotArea, edge);
        state.setTicks(ticks);

        // remember the last drawn label so that we can avoid drawing overlapping labels.
        Rectangle2D r = null;

        int categoryIndex = 0;
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {

            CategoryTick tick = (CategoryTick) iterator.next();
            g2.setFont(getTickLabelFont(tick.getCategory()));
            g2.setPaint(getTickLabelPaint(tick.getCategory()));

            CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
            double x0 = 0.0;
            double x1 = 0.0;
            double y0 = 0.0;
            double y1 = 0.0;
            if (edge == RectangleEdge.TOP) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                y0 = y1 - state.getMax();
            } else if (edge == RectangleEdge.BOTTOM) {
                x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                y0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                y1 = y0 + state.getMax();
            } else if (edge == RectangleEdge.LEFT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x1 = state.getCursor() - this.getCategoryLabelPositionOffset();
                x0 = x1 - state.getMax();
            } else if (edge == RectangleEdge.RIGHT) {
                y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
                y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
                x0 = state.getCursor() + this.getCategoryLabelPositionOffset();
                x1 = x0 - state.getMax();
            }
            Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
            if (r == null || !r.intersects(area)) {
                Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor());
                TextBlock block = tick.getLabel();
                block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                        position.getAngle());
                if (plotState != null && plotState.getOwner() != null) {
                    EntityCollection entities = plotState.getOwner().getEntityCollection();
                    if (entities != null) {
                        String tooltip = getCategoryLabelToolTip(tick.getCategory());
                        entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null));
                    }
                }
                r = bounds.getBounds2D();
            }

            categoryIndex++;
        }

        if (edge.equals(RectangleEdge.TOP)) {
            double h = state.getMax();
            state.cursorUp(h);
        } else if (edge.equals(RectangleEdge.BOTTOM)) {
            double h = state.getMax();
            state.cursorDown(h);
        } else if (edge == RectangleEdge.LEFT) {
            double w = state.getMax();
            state.cursorLeft(w);
        } else if (edge == RectangleEdge.RIGHT) {
            double w = state.getMax();
            state.cursorRight(w);
        }
    }
    return state;
}