use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
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} not permitted).
* @param plot the plot (ignored here).
* @param frame the dial frame (ignored here).
* @param view the view rectangle ({@code null} not permitted).
*/
@Override
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 = TextUtils.getTextBounds(valueStr, g2, fm);
// calculate the bounds of the template value
String s = this.formatter.format(this.templateValue);
Rectangle2D tb = TextUtils.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 = TextUtils.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 = this.valueAnchor.getAnchorPoint(bounds);
g2.setPaint(this.paint);
g2.setFont(this.font);
TextUtils.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor);
g2.setClip(savedClip);
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class PaintScaleLegend method arrangeRR.
/**
* Returns the content size for the title. This will reflect the fact that
* a text title positioned on the left or right of a chart will be rotated
* 90 degrees.
*
* @param g2 the graphics device.
* @param widthRange the width range.
* @param heightRange the height range.
*
* @return The content size.
*/
protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) {
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
float maxWidth = (float) widthRange.getUpperBound();
// determine the space required for the axis
AxisSpace space = this.axis.reserveSpace(g2, null, new Rectangle2D.Double(0, 0, maxWidth, 100), RectangleEdge.BOTTOM, null);
return new Size2D(maxWidth, this.stripWidth + this.axisOffset + space.getTop() + space.getBottom());
} else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
float maxHeight = (float) heightRange.getUpperBound();
AxisSpace space = this.axis.reserveSpace(g2, null, new Rectangle2D.Double(0, 0, 100, maxHeight), RectangleEdge.RIGHT, null);
return new Size2D(this.stripWidth + this.axisOffset + space.getLeft() + space.getRight(), maxHeight);
} else {
throw new RuntimeException("Unrecognised position.");
}
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class JFreeChart 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} not permitted).
* @param g2 the graphics device ({@code null} not permitted).
* @param area the chart area, excluding any existing titles
* ({@code null} 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}).
*/
protected EntityCollection drawTitle(Title t, Graphics2D g2, Rectangle2D area, boolean entities) {
Args.nullNotPermitted(t, "t");
Args.nullNotPermitted(area, "area");
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);
switch(position) {
case 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));
break;
}
case 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);
break;
}
case 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());
break;
}
case 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());
break;
}
default:
{
throw new RuntimeException("Unrecognised title position.");
}
}
EntityCollection result = null;
if (retValue instanceof EntityBlockResult) {
EntityBlockResult ebr = (EntityBlockResult) retValue;
result = ebr.getEntityCollection();
}
return result;
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CompositeTitle method arrange.
/**
* Arranges the contents of the block, within the given constraints, and
* returns the block size.
*
* @param g2 the graphics device.
* @param constraint the constraint ({@code null} not permitted).
*
* @return The block size (in Java2D units, never {@code null}).
*/
@Override
public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
RectangleConstraint contentConstraint = toContentConstraint(constraint);
Size2D contentSize = this.container.arrange(g2, contentConstraint);
return new Size2D(calculateTotalWidth(contentSize.getWidth()), calculateTotalHeight(contentSize.getHeight()));
}
use of org.jfree.chart.block.Size2D in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class TextTitle method arrangeFN.
/**
* Arranges the content for this title assuming a fixed width and no bounds
* on the height, and returns the required size. This will reflect the
* fact that a text title positioned on the left or right of a chart will
* be rotated by 90 degrees.
*
* @param g2 the graphics target.
* @param w the width.
*
* @return The content size.
*/
protected Size2D arrangeFN(Graphics2D g2, double w) {
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
float maxWidth = (float) w;
g2.setFont(this.font);
this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
if (this.expandToFitSpace) {
return new Size2D(maxWidth, contentSize.getHeight());
} else {
return contentSize;
}
} else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
float maxWidth = Float.MAX_VALUE;
g2.setFont(this.font);
this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
this.content.setLineAlignment(this.textAlignment);
Size2D contentSize = this.content.calculateDimensions(g2);
// transpose the dimensions, because the title is rotated
if (this.expandToFitSpace) {
return new Size2D(contentSize.getHeight(), maxWidth);
} else {
return new Size2D(contentSize.height, contentSize.width);
}
} else {
throw new RuntimeException("Unrecognised exception.");
}
}
Aggregations