use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.
the class Axis method getLabelEnclosure.
/**
* Returns a rectangle that encloses the axis label. This is typically
* used for layout purposes (it gives the maximum dimensions of the label).
*
* @param g2 the graphics device.
* @param edge the edge of the plot area along which the axis is measuring.
*
* @return The enclosing rectangle.
*/
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {
Rectangle2D result = new Rectangle2D.Double();
String axisLabel = getLabel();
if (axisLabel != null && !axisLabel.equals("")) {
FontMetrics fm = g2.getFontMetrics(getLabelFont());
Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
RectangleInsets insets = getLabelInsets();
bounds = insets.createOutsetRectangle(bounds);
double angle = getLabelAngle();
if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
angle = angle - Math.PI / 2.0;
}
double x = bounds.getCenterX();
double y = bounds.getCenterY();
AffineTransform transformer = AffineTransform.getRotateInstance(angle, x, y);
Shape labelBounds = transformer.createTransformedShape(bounds);
result = labelBounds.getBounds2D();
}
return result;
}
use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.
the class CategoryAxis method calculateTextBlockHeight.
/**
* A utility method for determining the height of a text block.
*
* @param block the text block.
* @param position the label position.
* @param g2 the graphics device.
*
* @return The height.
*/
protected double calculateTextBlockHeight(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 h = rotatedBox.getBounds2D().getHeight() + insets.getTop() + insets.getBottom();
return h;
}
use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.
the class ValueAxis method findMaximumTickLabelHeight.
/**
* A utility method for determining the height of the tallest 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 height of the tallest tick label.
*/
protected double findMaximumTickLabelHeight(List ticks, Graphics2D g2, Rectangle2D drawArea, boolean vertical) {
RectangleInsets insets = getTickLabelInsets();
Font font = getTickLabelFont();
double maxHeight = 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.getTop() + insets.getBottom() > maxHeight) {
maxHeight = labelBounds.getWidth() + insets.getTop() + insets.getBottom();
}
}
} else {
LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext());
maxHeight = metrics.getHeight() + insets.getTop() + insets.getBottom();
}
return maxHeight;
}
use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.
the class ValueAxis method calculateAnchorPoint.
/**
* Calculates the anchor point for a tick label.
*
* @param tick the tick.
* @param cursor the cursor.
* @param dataArea the data area.
* @param edge the edge on which the axis is drawn.
*
* @return The x and y coordinates of the anchor point.
*/
protected float[] calculateAnchorPoint(ValueTick tick, double cursor, Rectangle2D dataArea, RectangleEdge edge) {
RectangleInsets insets = getTickLabelInsets();
float[] result = new float[2];
if (edge == RectangleEdge.TOP) {
result[0] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
result[1] = (float) (cursor - insets.getBottom() - 2.0);
} else if (edge == RectangleEdge.BOTTOM) {
result[0] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
result[1] = (float) (cursor + insets.getTop() + 2.0);
} else if (edge == RectangleEdge.LEFT) {
result[0] = (float) (cursor - insets.getLeft() - 2.0);
result[1] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
} else if (edge == RectangleEdge.RIGHT) {
result[0] = (float) (cursor + insets.getRight() + 2.0);
result[1] = (float) valueToJava2D(tick.getValue(), dataArea, edge);
}
return result;
}
Aggregations