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

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

Introduction

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

Prototype

public AxisState(double cursor) 

Source Link

Document

Creates a new axis state.

Usage

From source file:net.sourceforge.processdash.ui.lib.chart.DiscLegendAxis.java

/**
 * The superclass' drawAxisLine() method draws the axis line for the entire
 *  dataArea's length. Since we want the line to end at the height of the maximum
 *  shown tick, we create a new Rectangle2D with the appropriate dimensions.
 *//*  w  w w .  j  a v  a  2 s  .  c  o m*/
@Override
protected void drawAxisLine(Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge) {

    // In the original flow of events, the refreshing of the ticks is made after
    //  drawing the axis line. Since this implementation needs the ticks to be
    //  set properly, we force a tick refresh.
    AxisState state = new AxisState(cursor);
    refreshTicks(g2, state, dataArea, edge);

    double amountBetweenTicks = getTickUnit().getSize();
    int tickCount = calculateVisibleTickCount() - 1;
    double lowestTickValue = calculateLowestVisibleTickValue();

    double minY = valueToJava2D(lowestTickValue + tickCount * amountBetweenTicks, dataArea, edge);
    double maxY = valueToJava2D(lowestTickValue, dataArea, edge);
    double height = maxY - minY;

    Rectangle2D axisLineArea = new Rectangle2D.Double(dataArea.getX(), minY, dataArea.getWidth(), height);

    super.drawAxisLine(g2, cursor, axisLineArea, edge);
}

From source file:org.jstockchart.axis.TimeseriesDateAxis.java

protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea,
        Rectangle2D dataArea, RectangleEdge edge) {

    AxisState state = new AxisState(cursor);

    if (isAxisLineVisible()) {
        drawAxisLine(g2, cursor, dataArea, edge);
    }/*from   ww  w . ja  v a2  s  . c om*/

    List ticks = refreshTicks(g2, state, dataArea, edge);
    state.setTicks(ticks);
    g2.setFont(getTickLabelFont());
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        if (isTickLabelsVisible()) {
            g2.setPaint(getTickLabelPaint());
            float[] anchorPoint = calculateAnchorPoint(tick, cursor, dataArea, edge);
            //System.out.println("label:"+tick.getText());
            String tickLabel = tick.getText();
            if (tickLabel == "13:00") {
                TextUtilities.drawRotatedString("/", g2, anchorPoint[0] - 2, anchorPoint[1],
                        tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor());
            }
            if (hideTickLabel != null) {
                if (!hideTickLabel.contains(tickLabel)) {
                    TextUtilities.drawRotatedString(tickLabel, g2, anchorPoint[0], anchorPoint[1],
                            tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor());
                }
            } else {
                TextUtilities.drawRotatedString(tick.getText(), g2, anchorPoint[0], anchorPoint[1],
                        tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor());
            }

        }

        if ((isTickMarksVisible() && tick.getTickType().equals(TickType.MAJOR))
                || (isMinorTickMarksVisible() && tick.getTickType().equals(TickType.MINOR))) {

            double ol = (tick.getTickType().equals(TickType.MINOR)) ? getMinorTickMarkOutsideLength()
                    : getTickMarkOutsideLength();

            double il = (tick.getTickType().equals(TickType.MINOR)) ? getMinorTickMarkInsideLength()
                    : getTickMarkInsideLength();

            float xx = (float) valueToJava2D(tick.getValue(), dataArea, edge);
            Line2D mark = null;
            g2.setStroke(getTickMarkStroke());
            g2.setPaint(getTickMarkPaint());
            if (edge == RectangleEdge.LEFT) {
                mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
            } else if (edge == RectangleEdge.RIGHT) {
                mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
            } else if (edge == RectangleEdge.TOP) {
                mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
            } else if (edge == RectangleEdge.BOTTOM) {
                mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
            }
            g2.draw(mark);
        }
    }

    // need to work out the space used by the tick labels...
    // so we can update the cursor...
    double used = 0.0;
    if (isTickLabelsVisible()) {
        if (edge == RectangleEdge.LEFT) {
            used += findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorLeft(used);
        } else if (edge == RectangleEdge.RIGHT) {
            used = findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorRight(used);
        } else if (edge == RectangleEdge.TOP) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorUp(used);
        } else if (edge == RectangleEdge.BOTTOM) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels());
            state.cursorDown(used);
        }
    }

    return state;
}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Draws the axis on a Java 2D graphics device (such as the screen or a 
 * printer)./*  w  ww.j a va 2  s . com*/
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param cursor  the cursor location (determines where to draw the axis).
 * @param plotArea  the area within which the axes and plot should be drawn.
 * @param dataArea  the area within which the data should be drawn.
 * @param edge  the axis location (<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) {

    AxisState state = null;
    // if the axis is not visible, don't draw it...
    if (!isVisible()) {
        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;
    }
    state = drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge);
    state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);
    return state;
}