Search in sources :

Example 21 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class NumberAxis method estimateMaximumTickLabelHeight.

/**
 * Estimates the maximum tick label height.
 *
 * @param g2  the graphics device.
 *
 * @return The maximum height.
 */
protected double estimateMaximumTickLabelHeight(Graphics2D g2) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    result += tickLabelFont.getLineMetrics("123", frc).getHeight();
    return result;
}
Also used : RectangleInsets(org.jfree.chart.util.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font)

Example 22 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class NumberAxis method estimateMaximumTickLabelWidth.

/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
protected double estimateMaximumTickLabelWidth(Graphics2D g2, TickUnit unit) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the
        // font)...
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc);
        result += lm.getHeight();
    } else {
        // look at lower and upper bounds...
        FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
        Range range = getRange();
        double lower = range.getLowerBound();
        double upper = range.getUpperBound();
        String lowerStr = "";
        String upperStr = "";
        NumberFormat formatter = getNumberFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        } else {
            lowerStr = unit.valueToString(lower);
            upperStr = unit.valueToString(upper);
        }
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }
    return result;
}
Also used : FontMetrics(java.awt.FontMetrics) RectangleInsets(org.jfree.chart.util.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Range(org.jfree.data.Range) NumberFormat(java.text.NumberFormat)

Example 23 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class Axis method drawLabel.

/**
 * Draws the axis label.
 *
 * @param label  the label text.
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param dataArea  the area inside the axes.
 * @param edge  the location of the axis.
 * @param state  the axis state (<code>null</code> not permitted).
 * @param plotState  the plot state (<code>null</code> permitted).
 *
 * @return Information about the axis.
 */
protected AxisState drawLabel(String label, Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {
    // it is unlikely that 'state' will be null, but check anyway...
    if (state == null) {
        throw new IllegalArgumentException("Null 'state' argument.");
    }
    if ((label == null) || (label.equals(""))) {
        return state;
    }
    Font font = getLabelFont();
    RectangleInsets insets = getLabelInsets();
    g2.setFont(font);
    g2.setPaint(getLabelPaint());
    FontMetrics fm = g2.getFontMetrics();
    Rectangle2D labelBounds = TextUtilities.getTextBounds(label, g2, fm);
    Shape hotspot = null;
    if (edge == RectangleEdge.TOP) {
        AffineTransform t = AffineTransform.getRotateInstance(getLabelAngle(), labelBounds.getCenterX(), labelBounds.getCenterY());
        Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
        labelBounds = rotatedLabelBounds.getBounds2D();
        float w = (float) labelBounds.getWidth();
        float h = (float) labelBounds.getHeight();
        float labelx = (float) dataArea.getCenterX();
        float labely = (float) (state.getCursor() - insets.getBottom() - h / 2.0);
        TextUtilities.drawRotatedString(label, g2, labelx, labely, TextAnchor.CENTER, getLabelAngle(), TextAnchor.CENTER);
        hotspot = new Rectangle2D.Float(labelx - w / 2.0f, labely - h / 2.0f, w, h);
        state.cursorUp(insets.getTop() + labelBounds.getHeight() + insets.getBottom());
    } else if (edge == RectangleEdge.BOTTOM) {
        AffineTransform t = AffineTransform.getRotateInstance(getLabelAngle(), labelBounds.getCenterX(), labelBounds.getCenterY());
        Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
        labelBounds = rotatedLabelBounds.getBounds2D();
        float w = (float) labelBounds.getWidth();
        float h = (float) labelBounds.getHeight();
        float labelx = (float) dataArea.getCenterX();
        float labely = (float) (state.getCursor() + insets.getTop() + h / 2.0);
        TextUtilities.drawRotatedString(label, g2, labelx, labely, TextAnchor.CENTER, getLabelAngle(), TextAnchor.CENTER);
        hotspot = new Rectangle2D.Float(labelx - w / 2.0f, labely - h / 2.0f, w, h);
        state.cursorDown(insets.getTop() + labelBounds.getHeight() + insets.getBottom());
    } else if (edge == RectangleEdge.LEFT) {
        AffineTransform t = AffineTransform.getRotateInstance(getLabelAngle() - Math.PI / 2.0, labelBounds.getCenterX(), labelBounds.getCenterY());
        Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
        labelBounds = rotatedLabelBounds.getBounds2D();
        float w = (float) labelBounds.getWidth();
        float h = (float) labelBounds.getHeight();
        float labelx = (float) (state.getCursor() - insets.getRight() - w / 2.0);
        float labely = (float) dataArea.getCenterY();
        TextUtilities.drawRotatedString(label, g2, labelx, labely, TextAnchor.CENTER, getLabelAngle() - Math.PI / 2.0, TextAnchor.CENTER);
        hotspot = new Rectangle2D.Float(labelx - w / 2.0f, labely - h / 2.0f, w, h);
        state.cursorLeft(insets.getLeft() + labelBounds.getWidth() + insets.getRight());
    } else if (edge == RectangleEdge.RIGHT) {
        AffineTransform t = AffineTransform.getRotateInstance(getLabelAngle() + Math.PI / 2.0, labelBounds.getCenterX(), labelBounds.getCenterY());
        Shape rotatedLabelBounds = t.createTransformedShape(labelBounds);
        labelBounds = rotatedLabelBounds.getBounds2D();
        float w = (float) labelBounds.getWidth();
        float h = (float) labelBounds.getHeight();
        float labelx = (float) (state.getCursor() + insets.getLeft() + w / 2.0);
        float labely = (float) (dataArea.getY() + dataArea.getHeight() / 2.0);
        TextUtilities.drawRotatedString(label, g2, labelx, labely, TextAnchor.CENTER, getLabelAngle() + Math.PI / 2.0, TextAnchor.CENTER);
        hotspot = new Rectangle2D.Float(labelx - w / 2.0f, labely - h / 2.0f, w, h);
        state.cursorRight(insets.getLeft() + labelBounds.getWidth() + insets.getRight());
    }
    if (plotState != null && hotspot != null) {
        ChartRenderingInfo owner = plotState.getOwner();
        if (owner != null) {
            EntityCollection entities = owner.getEntityCollection();
            if (entities != null) {
                entities.add(new AxisLabelEntity(this, hotspot, this.labelToolTip, this.labelURL));
            }
        }
    }
    return state;
}
Also used : Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) AxisLabelEntity(org.jfree.chart.entity.AxisLabelEntity) Font(java.awt.Font) EntityCollection(org.jfree.chart.entity.EntityCollection) FontMetrics(java.awt.FontMetrics) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) RectangleInsets(org.jfree.chart.util.RectangleInsets) AffineTransform(java.awt.geom.AffineTransform)

Example 24 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ValueAxis method findMaximumTickLabelWidth.

/**
 * A utility method for determining the width of the widest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels
 *                  are 'vertical'.
 *
 * @return The width of the tallest tick label.
 */
protected double findMaximumTickLabelWidth(List ticks, Graphics2D g2, Rectangle2D drawArea, boolean vertical) {
    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxWidth = 0.0;
    if (!vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) {
                maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight();
            }
        }
    } else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext());
        maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom();
    }
    return maxWidth;
}
Also used : FontMetrics(java.awt.FontMetrics) Iterator(java.util.Iterator) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.util.RectangleInsets) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font)

Example 25 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class CategoryAxis method calculateTextBlockWidth.

/**
 * A utility method for determining the width of a text block.
 *
 * @param block  the text block.
 * @param position  the position.
 * @param g2  the graphics device.
 *
 * @return The width.
 */
protected double calculateTextBlockWidth(TextBlock block, CategoryLabelPosition position, Graphics2D g2) {
    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(), 0.0f, 0.0f);
    double w = rotatedBox.getBounds2D().getWidth() + insets.getLeft() + insets.getRight();
    return w;
}
Also used : Size2D(org.jfree.chart.util.Size2D) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.util.RectangleInsets)

Aggregations

RectangleInsets (org.jfree.chart.util.RectangleInsets)44 Rectangle2D (java.awt.geom.Rectangle2D)21 Shape (java.awt.Shape)13 Font (java.awt.Font)11 FontMetrics (java.awt.FontMetrics)10 AlphaComposite (java.awt.AlphaComposite)8 Composite (java.awt.Composite)8 Paint (java.awt.Paint)8 AxisState (org.jfree.chart.axis.AxisState)8 AxisSpace (org.jfree.chart.axis.AxisSpace)7 ValueAxis (org.jfree.chart.axis.ValueAxis)7 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 Iterator (java.util.Iterator)6 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)6 RectangleEdge (org.jfree.chart.util.RectangleEdge)6 BasicStroke (java.awt.BasicStroke)4 Rectangle (java.awt.Rectangle)4 Stroke (java.awt.Stroke)4 Point2D (java.awt.geom.Point2D)4