Java Code Examples for org.jfree.chart.util.RectangleEdge#BOTTOM

The following examples show how to use org.jfree.chart.util.RectangleEdge#BOTTOM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cardumen_002_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds a block to the arrangement manager at the specified edge.
 *
 * @param block  the block (<code>null</code> permitted).
 * @param key  the edge (an instance of {@link RectangleEdge}) or
 *             <code>null</code> for the center block.
 */
public void add(Block block, Object key) {

    if (key == null) {
        this.centerBlock = block;
    }
    else {
        RectangleEdge edge = (RectangleEdge) key;
        if (edge == RectangleEdge.TOP) {
            this.topBlock = block;
        }
        else if (edge == RectangleEdge.BOTTOM) {
            this.bottomBlock = block;
        }
        else if (edge == RectangleEdge.LEFT) {
            this.leftBlock = block;
        }
        else if (edge == RectangleEdge.RIGHT) {
            this.rightBlock = block;
        }
    }
}
 
Example 2
Source File: Cardumen_007_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws an axis line at the current cursor position and edge.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    
    Line2D axisLine = null;
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, 
                dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, 
                dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, 
                dataArea.getMaxY());  
    }
    else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, 
                dataArea.getMaxY());  
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    g2.draw(axisLine);
    
}
 
Example 3
Source File: JGenProg2017_006_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws an axis line at the current cursor position and edge.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    
    Line2D axisLine = null;
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, 
                dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(dataArea.getX(), cursor, 
                dataArea.getMaxX(), cursor);  
    }
    else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, 
                dataArea.getMaxY());  
    }
    else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, 
                dataArea.getMaxY());  
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    g2.draw(axisLine);
    
}
 
Example 4
Source File: Arja_00149_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds a block to the arrangement manager at the specified edge.
 *
 * @param block  the block (<code>null</code> permitted).
 * @param key  the edge (an instance of {@link RectangleEdge}) or
 *             <code>null</code> for the center block.
 */
public void add(Block block, Object key) {

    if (key == null) {
        this.centerBlock = block;
    }
    else {
        RectangleEdge edge = (RectangleEdge) key;
        if (edge == RectangleEdge.TOP) {
            this.topBlock = block;
        }
        else if (edge == RectangleEdge.BOTTOM) {
            this.bottomBlock = block;
        }
        else if (edge == RectangleEdge.LEFT) {
            this.leftBlock = block;
        }
        else if (edge == RectangleEdge.RIGHT) {
            this.rightBlock = block;
        }
    }
}
 
Example 5
Source File: Arja_00149_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds a block to the arrangement manager at the specified edge.
 *
 * @param block  the block (<code>null</code> permitted).
 * @param key  the edge (an instance of {@link RectangleEdge}) or
 *             <code>null</code> for the center block.
 */
public void add(Block block, Object key) {

    if (key == null) {
        this.centerBlock = block;
    }
    else {
        RectangleEdge edge = (RectangleEdge) key;
        if (edge == RectangleEdge.TOP) {
            this.topBlock = block;
        }
        else if (edge == RectangleEdge.BOTTOM) {
            this.bottomBlock = block;
        }
        else if (edge == RectangleEdge.LEFT) {
            this.leftBlock = block;
        }
        else if (edge == RectangleEdge.RIGHT) {
            this.rightBlock = block;
        }
    }
}
 
Example 6
Source File: Cardumen_0076_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds a block to the arrangement manager at the specified edge.
 *
 * @param block  the block (<code>null</code> permitted).
 * @param key  the edge (an instance of {@link RectangleEdge}) or
 *             <code>null</code> for the center block.
 */
public void add(Block block, Object key) {

    if (key == null) {
        this.centerBlock = block;
    }
    else {
        RectangleEdge edge = (RectangleEdge) key;
        if (edge == RectangleEdge.TOP) {
            this.topBlock = block;
        }
        else if (edge == RectangleEdge.BOTTOM) {
            this.bottomBlock = block;
        }
        else if (edge == RectangleEdge.LEFT) {
            this.leftBlock = block;
        }
        else if (edge == RectangleEdge.RIGHT) {
            this.rightBlock = block;
        }
    }
}
 
Example 7
Source File: Elixir_002_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Adds a block to the arrangement manager at the specified edge.
 *
 * @param block  the block (<code>null</code> permitted).
 * @param key  the edge (an instance of {@link RectangleEdge}) or
 *             <code>null</code> for the center block.
 */
public void add(Block block, Object key) {

    if (key == null) {
        this.centerBlock = block;
    }
    else {
        RectangleEdge edge = (RectangleEdge) key;
        if (edge == RectangleEdge.TOP) {
            this.topBlock = block;
        }
        else if (edge == RectangleEdge.BOTTOM) {
            this.bottomBlock = block;
        }
        else if (edge == RectangleEdge.LEFT) {
            this.leftBlock = block;
        }
        else if (edge == RectangleEdge.RIGHT) {
            this.rightBlock = block;
        }
    }
}
 
Example 8
Source File: AxisSpace.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds space to the top, bottom, left or right edge of the plot area.
 *
 * @param space  the space (in Java2D units).
 * @param edge  the edge (<code>null</code> not permitted).
 */
public void add(double space, RectangleEdge edge) {
    if (edge == null) {
        throw new IllegalArgumentException("Null 'edge' argument.");
    }
    if (edge == RectangleEdge.TOP) {
        this.top += space;
    }
    else if (edge == RectangleEdge.BOTTOM) {
        this.bottom += space;
    }
    else if (edge == RectangleEdge.LEFT) {
        this.left += space;
    }
    else if (edge == RectangleEdge.RIGHT) {
        this.right += space;
    }
    else {
        throw new IllegalStateException("Unrecognised 'edge' argument.");
    }
}
 
Example 9
Source File: Plot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adjusts the supplied y-value.
 *
 * @param y  the x-value.
 * @param h1  height 1.
 * @param h2  height 2.
 * @param edge  the edge (top or bottom).
 *
 * @return The adjusted y-value.
 */
protected double getRectY(double y, double h1, double h2, 
                          RectangleEdge edge) {

    double result = y;
    if (edge == RectangleEdge.TOP) {
        result = result + h1;
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result = result + h2;
    }
    return result;

}
 
Example 10
Source File: AxisSpace.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculates the reserved area.
 *
 * @param area  the area.
 * @param edge  the edge.
 *
 * @return The reserved area.
 */
public Rectangle2D reserved(Rectangle2D area, RectangleEdge edge) {
    Rectangle2D result = null;
    if (edge == RectangleEdge.TOP) {
        result = new Rectangle2D.Double(
            area.getX(), area.getY(), area.getWidth(), this.top
        );
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result = new Rectangle2D.Double(
            area.getX(), area.getMaxY() - this.top,
            area.getWidth(), this.bottom
        );
    }
    else if (edge == RectangleEdge.LEFT) {
        result = new Rectangle2D.Double(
            area.getX(), area.getY(), this.left, area.getHeight()
        );
    }
    else if (edge == RectangleEdge.RIGHT) {
        result = new Rectangle2D.Double(
            area.getMaxX() - this.right, area.getY(),
            this.right, area.getHeight()
        );
    }
    return result;
}
 
Example 11
Source File: CyclicNumberAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the axis.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param cursor  the cursor position.
 * @param plotArea  the plot area (<code>null</code> not permitted).
 * @param dataArea  the data area (<code>null</code> not permitted).
 * @param edge  the edge (<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 ret = super.draw(
        g2, cursor, plotArea, dataArea, edge, plotState
    );
    if (isAdvanceLineVisible()) {
        double xx = valueToJava2D(
            getRange().getUpperBound(), dataArea, edge
        );
        Line2D mark = null;
        g2.setStroke(getAdvanceLineStroke());
        g2.setPaint(getAdvanceLinePaint());
        if (edge == RectangleEdge.LEFT) {
            mark = new Line2D.Double(
                cursor, xx, cursor + dataArea.getWidth(), xx
            );
        }
        else if (edge == RectangleEdge.RIGHT) {
            mark = new Line2D.Double(
                cursor - dataArea.getWidth(), xx, cursor, xx
            );
        }
        else if (edge == RectangleEdge.TOP) {
            mark = new Line2D.Double(
                xx, cursor + dataArea.getHeight(), xx, cursor
            );
        }
        else if (edge == RectangleEdge.BOTTOM) {
            mark = new Line2D.Double(
                xx, cursor, xx, cursor - dataArea.getHeight()
            );
        }
        g2.draw(mark);
    }
    return ret;
}
 
Example 12
Source File: NumberAxis3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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, plotState);

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

    return info;

}
 
Example 13
Source File: CyclicNumberAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the tick marks and labels.
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the plot area.
 * @param dataArea  the area inside the axes.
 * @param edge  the side on which the axis is displayed.
 * @param info  the plot rendering info.
 *
 * @return The axis state.
 */
protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor,
        Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge,
        PlotRenderingInfo info) {

    this.internalMarkerWhenTicksOverlap = false;
    AxisState ret = super.drawTickMarksAndLabels(g2, cursor, plotArea,
            dataArea, edge, info);

    // continue and separate the labels only if necessary
    if (!this.internalMarkerWhenTicksOverlap) {
        return ret;
    }

    double ol = getTickMarkOutsideLength();
    FontMetrics fm = g2.getFontMetrics(getTickLabelFont());

    if (isVerticalTickLabels()) {
        ol = fm.getMaxAdvance();
    }
    else {
        ol = fm.getHeight();
    }

    double il = 0;
    if (isTickMarksVisible()) {
        float xx = (float) valueToJava2D(getRange().getUpperBound(),
                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);
    }
    return ret;
}
 
Example 14
Source File: CategoryAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Estimates the space required for the axis, given a specific drawing area.
 *
 * @param g2  the graphics device (used to obtain font information).
 * @param plot  the plot that the axis belongs to.
 * @param plotArea  the area within which the axis should be drawn.
 * @param edge  the axis location (top or bottom).
 * @param space  the space already reserved.
 *
 * @return The space required to draw the axis.
 */
public AxisSpace reserveSpace(Graphics2D g2, Plot plot,
                              Rectangle2D plotArea,
                              RectangleEdge edge, AxisSpace space) {

    // 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
        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.categoryLabelPositionOffset, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth
                + this.categoryLabelPositionOffset, edge);
    }
    return space;

}
 
Example 15
Source File: PeriodAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
                                       Rectangle2D dataArea,
                                       RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0 = dataArea.getX();
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass,
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(new Double(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 16
Source File: CategoryAxis3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Java 2D coordinate for a category.
 *
 * @param anchor  the anchor point.
 * @param category  the category index.
 * @param categoryCount  the category count.
 * @param area  the data area.
 * @param edge  the location of the axis.
 *
 * @return The coordinate.
 */
public double getCategoryJava2DCoordinate(CategoryAnchor anchor,
                                          int category,
                                          int categoryCount,
                                          Rectangle2D area,
                                          RectangleEdge edge) {

    double result = 0.0;
    Rectangle2D adjustedArea = area;
    CategoryPlot plot = (CategoryPlot) getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof Effect3D) {
        Effect3D e3D = (Effect3D) renderer;
        double adjustedX = area.getMinX();
        double adjustedY = area.getMinY();
        double adjustedW = area.getWidth() - e3D.getXOffset();
        double adjustedH = area.getHeight() - e3D.getYOffset();

        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
            adjustedY += e3D.getYOffset();
        }
        else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
            adjustedX += e3D.getXOffset();
        }
        adjustedArea = new Rectangle2D.Double(adjustedX, adjustedY,
                adjustedW, adjustedH);
    }

    if (anchor == CategoryAnchor.START) {
        result = getCategoryStart(category, categoryCount, adjustedArea,
                edge);
    }
    else if (anchor == CategoryAnchor.MIDDLE) {
        result = getCategoryMiddle(category, categoryCount, adjustedArea,
                edge);
    }
    else if (anchor == CategoryAnchor.END) {
        result = getCategoryEnd(category, categoryCount, adjustedArea,
                edge);
    }
    return result;

}
 
Example 17
Source File: StandardXYBarPainter.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a shadow for the bar.
 *
 * @param bar  the bar shape.
 * @param xOffset  the x-offset for the shadow.
 * @param yOffset  the y-offset for the shadow.
 * @param base  the edge that is the base of the bar.
 * @param pegShadow  peg the shadow to the base?
 *
 * @return A rectangle for the shadow.
 */
private Rectangle2D createShadow(RectangularShape bar, double xOffset,
        double yOffset, RectangleEdge base, boolean pegShadow) {
    double x0 = bar.getMinX();
    double x1 = bar.getMaxX();
    double y0 = bar.getMinY();
    double y1 = bar.getMaxY();
    if (base == RectangleEdge.TOP) {
        x0 += xOffset;
        x1 += xOffset;
        if (!pegShadow) {
            y0 += yOffset;
        }
        y1 += yOffset;
    }
    else if (base == RectangleEdge.BOTTOM) {
        x0 += xOffset;
        x1 += xOffset;
        y0 += yOffset;
        if (!pegShadow) {
            y1 += yOffset;
        }
    }
    else if (base == RectangleEdge.LEFT) {
        if (!pegShadow) {
            x0 += xOffset;
        }
        x1 += xOffset;
        y0 += yOffset;
        y1 += yOffset;
    }
    else if (base == RectangleEdge.RIGHT) {
        x0 += xOffset;
        if (!pegShadow) {
            x1 += xOffset;
        }
        y0 += yOffset;
        y1 += yOffset;
    }
    return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
}
 
Example 18
Source File: XYBarRenderer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state,
        Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis,
        ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        boolean selected, int pass) {

    Rectangle2D bar = createBar(g2, dataArea, plot, domainAxis,
            rangeAxis, dataset, series, item, selected);
    if (bar == null) {
        return;
    }

    boolean positive = true;
    if (this.useYInterval) {
        positive = dataset.getYValue(series, item) >= 0.0;
        // FIXME:  the above line should look at the endYValue
    }
    else {
        positive = dataset.getYValue(series, item) >= 0.0;
    }
    boolean inverted = rangeAxis.isInverted();
    RectangleEdge barBase;
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barBase = RectangleEdge.RIGHT;
        }
        else {
            barBase = RectangleEdge.LEFT;
        }
    }
    else {
        if (positive && !inverted || !positive && inverted) {
            barBase = RectangleEdge.BOTTOM;
        }
        else {
            barBase = RectangleEdge.TOP;
        }
    }
    if (getShadowsVisible()) {
        this.barPainter.paintBarShadow(g2, this, series, item, selected, 
                bar, barBase, !this.useYInterval);
    }
    this.barPainter.paintBar(g2, this, series, item, selected, bar,
            barBase);

    if (isItemLabelVisible(series, item, selected)) {
        XYItemLabelGenerator generator = getItemLabelGenerator(series,
                item, selected);
        drawItemLabelForBar(g2, plot, dataset, series, item, selected,
                generator, bar, !positive);
    }

    // update the crosshair point
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, 
            plot.getDomainAxisEdge());
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
            plot.getRangeAxisEdge());
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    XYCrosshairState crosshairState = state.getCrosshairState();
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, plot.getOrientation());

    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addEntity(entities, bar, dataset, series, item, selected, 0.0,
                0.0);
    }

}
 
Example 19
Source File: NumberAxis3D.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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, plotState);
   
    // draw the axis label...
    info = drawLabel(getLabel(), g2, plotArea, dataArea, edge, info, 
            plotState);

    return info;
    
}
 
Example 20
Source File: CategoryAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a temporary list of ticks that can be used when drawing the axis.
 *
 * @param g2  the graphics device (used to get font measurements).
 * @param state  the axis state.
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 * 
 * @return A list of ticks.
 */
public List refreshTicks(Graphics2D g2, 
                         AxisState state,
                         Rectangle2D dataArea,
                         RectangleEdge edge) {

    List ticks = new java.util.ArrayList();
    
    // sanity check for data area...
    if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) {
        return ticks;
    }

    CategoryPlot plot = (CategoryPlot) getPlot();
    List categories = plot.getCategoriesForAxis(this);
    double max = 0.0;
            
    if (categories != null) {
        CategoryLabelPosition position 
                = this.categoryLabelPositions.getLabelPosition(edge);
        float r = this.maximumCategoryLabelWidthRatio;
        if (r <= 0.0) {
            r = position.getWidthRatio();   
        }
              
        float l = 0.0f;
        if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) {
            l = (float) calculateCategorySize(categories.size(), dataArea, 
                    edge);  
        }
        else {
            if (RectangleEdge.isLeftOrRight(edge)) {
                l = (float) dataArea.getWidth();   
            }
            else {
                l = (float) dataArea.getHeight();   
            }
        }
        int categoryIndex = 0;
        Iterator iterator = categories.iterator();
        while (iterator.hasNext()) {
            Comparable category = (Comparable) iterator.next();
            TextBlock label = createLabel(category, l * r, edge, g2);
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                max = Math.max(max, calculateTextBlockHeight(label, 
                        position, g2));
            }
            else if (edge == RectangleEdge.LEFT 
                    || edge == RectangleEdge.RIGHT) {
                max = Math.max(max, calculateTextBlockWidth(label, 
                        position, g2));
            }
            Tick tick = new CategoryTick(category, label, 
                    position.getLabelAnchor(), position.getRotationAnchor(),
                    position.getAngle());
            ticks.add(tick);
            categoryIndex = categoryIndex + 1;
        }
    }
    state.setMax(max);
    return ticks;
    
}