use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class TextBlock method calculateBounds.
/**
* Returns the bounds of the text block.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param anchorX the x-coordinate for the anchor point.
* @param anchorY the y-coordinate for the anchor point.
* @param anchor the text block anchor (<code>null</code> not permitted).
* @param rotateX the x-coordinate for the rotation point.
* @param rotateY the y-coordinate for the rotation point.
* @param angle the rotation angle.
*
* @return The bounds.
*/
public Shape calculateBounds(Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle) {
Size2D d = calculateDimensions(g2);
float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
Rectangle2D bounds = new Rectangle2D.Double(anchorX + offsets[0], anchorY + offsets[1], d.getWidth(), d.getHeight());
Shape rotatedBounds = ShapeUtilities.rotateShape(bounds, angle, rotateX, rotateY);
return rotatedBounds;
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class XYTitleAnnotation method draw.
/**
* Draws the annotation. This method is called by the drawing code in the
* {@link XYPlot} class, you don't normally need to call this method
* directly.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param rendererIndex the renderer index.
* @param info if supplied, this info object will be populated with
* entity information.
*/
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
PlotOrientation orientation = plot.getOrientation();
AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
Range xRange = domainAxis.getRange();
Range yRange = rangeAxis.getRange();
double anchorX = 0.0;
double anchorY = 0.0;
if (this.coordinateType == XYCoordinateType.RELATIVE) {
anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
} else {
anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
}
float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge);
float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge);
float xx = 0.0f;
float yy = 0.0f;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = j2DY;
yy = j2DX;
} else if (orientation == PlotOrientation.VERTICAL) {
xx = j2DX;
yy = j2DY;
}
double maxW = dataArea.getWidth();
double maxH = dataArea.getHeight();
if (this.coordinateType == XYCoordinateType.RELATIVE) {
if (this.maxWidth > 0.0) {
maxW = maxW * this.maxWidth;
}
if (this.maxHeight > 0.0) {
maxH = maxH * this.maxHeight;
}
}
if (this.coordinateType == XYCoordinateType.DATA) {
maxW = this.maxWidth;
maxH = this.maxHeight;
}
RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH));
Size2D size = this.title.arrange(g2, rc);
Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height);
Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor);
xx = xx - (float) anchorPoint.getX();
yy = yy - (float) anchorPoint.getY();
titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
BlockParams p = new BlockParams();
if (info != null) {
if (info.getOwner().getEntityCollection() != null) {
p.setGenerateEntities(true);
}
}
Object result = this.title.draw(g2, titleRect, p);
if (info != null) {
if (result instanceof EntityBlockResult) {
EntityBlockResult ebr = (EntityBlockResult) result;
info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection());
}
String toolTip = getToolTipText();
String url = getURL();
if (toolTip != null || url != null) {
addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url);
}
}
}
use of org.jfree.chart.util.Size2D 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;
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class DialValueIndicator method draw.
/**
* Draws the background to the specified graphics device. If the dial
* frame specifies a window, the clipping region will already have been
* set to this window before this method is called.
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param plot the plot (ignored here).
* @param frame the dial frame (ignored here).
* @param view the view rectangle (<code>null</code> not permitted).
*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {
// work out the anchor point
Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
Point2D pt = arc.getStartPoint();
// the indicator bounds is calculated from the templateValue (which
// determines the minimum size), the maxTemplateValue (which, if
// specified, provides a maximum size) and the actual value
FontMetrics fm = g2.getFontMetrics(this.font);
double value = plot.getValue(this.datasetIndex);
String valueStr = this.formatter.format(value);
Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);
// calculate the bounds of the template value
String s = this.formatter.format(this.templateValue);
Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
double minW = tb.getWidth();
double minH = tb.getHeight();
double maxW = Double.MAX_VALUE;
double maxH = Double.MAX_VALUE;
if (this.maxTemplateValue != null) {
s = this.formatter.format(this.maxTemplateValue);
tb = TextUtilities.getTextBounds(s, g2, fm);
maxW = Math.max(tb.getWidth(), minW);
maxH = Math.max(tb.getHeight(), minH);
}
double w = fixToRange(valueBounds.getWidth(), minW, maxW);
double h = fixToRange(valueBounds.getHeight(), minH, maxH);
// align this rectangle to the frameAnchor
Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor);
// add the insets
Rectangle2D fb = this.insets.createOutsetRectangle(bounds);
// draw the background
g2.setPaint(this.backgroundPaint);
g2.fill(fb);
// draw the border
g2.setStroke(this.outlineStroke);
g2.setPaint(this.outlinePaint);
g2.draw(fb);
// now find the text anchor point
Shape savedClip = g2.getClip();
g2.clip(fb);
Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
g2.setPaint(this.paint);
g2.setFont(this.font);
TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor);
g2.setClip(savedClip);
}
use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.
the class JFreeChartInfo method drawTitle.
/**
* Draws a title. The title should be drawn at the top, bottom, left or
* right of the specified area, and the area should be updated to reflect
* the amount of space used by the title.
*
* @param t the title (<code>null</code> not permitted).
* @param g2 the graphics device (<code>null</code> not permitted).
* @param area the chart area, excluding any existing titles
* (<code>null</code> not permitted).
* @param entities a flag that controls whether or not an entity
* collection is returned for the title.
*
* @return An entity collection for the title (possibly <code>null</code>).
*/
protected EntityCollection drawTitle(Title t, Graphics2D g2, Rectangle2D area, boolean entities) {
if (t == null) {
throw new IllegalArgumentException("Null 't' argument.");
}
if (area == null) {
throw new IllegalArgumentException("Null 'area' argument.");
}
Rectangle2D titleArea;
RectangleEdge position = t.getPosition();
double ww = area.getWidth();
if (ww <= 0.0) {
return null;
}
double hh = area.getHeight();
if (hh <= 0.0) {
return null;
}
RectangleConstraint constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE);
Object retValue = null;
BlockParams p = new BlockParams();
p.setGenerateEntities(entities);
if (position == RectangleEdge.TOP) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.TOP);
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX(), Math.min(area.getY() + size.height, area.getMaxY()), area.getWidth(), Math.max(area.getHeight() - size.height, 0));
} else if (position == RectangleEdge.BOTTOM) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.BOTTOM);
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX(), area.getY(), area.getWidth(), area.getHeight() - size.height);
} else if (position == RectangleEdge.RIGHT) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.RIGHT, t.getVerticalAlignment());
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX(), area.getY(), area.getWidth() - size.width, area.getHeight());
} else if (position == RectangleEdge.LEFT) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.LEFT, t.getVerticalAlignment());
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX() + size.width, area.getY(), area.getWidth() - size.width, area.getHeight());
} else {
throw new RuntimeException("Unrecognised title position.");
}
EntityCollection result = null;
if (retValue instanceof EntityBlockResult) {
EntityBlockResult ebr = (EntityBlockResult) retValue;
result = ebr.getEntityCollection();
}
return result;
}
Aggregations