use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ImageTitle method drawHorizontal.
/**
* Draws the title on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param chartArea the area within which the title (and plot) should be
* drawn.
*
* @return The size of the area used by the title.
*/
protected Size2D drawHorizontal(Graphics2D g2, Rectangle2D chartArea) {
double startY;
double topSpace;
double bottomSpace;
double leftSpace;
double rightSpace;
double w = getWidth();
double h = getHeight();
RectangleInsets padding = getPadding();
topSpace = padding.calculateTopOutset(h);
bottomSpace = padding.calculateBottomOutset(h);
leftSpace = padding.calculateLeftOutset(w);
rightSpace = padding.calculateRightOutset(w);
if (getPosition() == RectangleEdge.TOP) {
startY = chartArea.getY() + topSpace;
} else {
startY = chartArea.getY() + chartArea.getHeight() - bottomSpace - h;
}
// what is our alignment?
double startX = 0.0;
switch(getHorizontalAlignment()) {
case CENTER:
startX = chartArea.getX() + leftSpace + chartArea.getWidth() / 2.0 - w / 2.0;
break;
case LEFT:
startX = chartArea.getX() + leftSpace;
break;
case RIGHT:
startX = chartArea.getX() + chartArea.getWidth() - rightSpace - w;
break;
default:
throw new IllegalStateException("Unexpected horizontal alignment.");
}
g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ImageTitle method drawVertical.
/**
* Draws the title on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device.
* @param chartArea the area within which the title (and plot) should be
* drawn.
*
* @return The size of the area used by the title.
*/
protected Size2D drawVertical(Graphics2D g2, Rectangle2D chartArea) {
double startX;
double topSpace = 0.0;
double bottomSpace = 0.0;
double leftSpace = 0.0;
double rightSpace = 0.0;
double w = getWidth();
double h = getHeight();
RectangleInsets padding = getPadding();
if (padding != null) {
topSpace = padding.calculateTopOutset(h);
bottomSpace = padding.calculateBottomOutset(h);
leftSpace = padding.calculateLeftOutset(w);
rightSpace = padding.calculateRightOutset(w);
}
if (getPosition() == RectangleEdge.LEFT) {
startX = chartArea.getX() + leftSpace;
} else {
startX = chartArea.getMaxX() - rightSpace - w;
}
// what is our alignment?
double startY = 0.0;
switch(getVerticalAlignment()) {
case CENTER:
startY = chartArea.getMinY() + topSpace + chartArea.getHeight() / 2.0 - h / 2.0;
break;
case TOP:
startY = chartArea.getMinY() + topSpace;
break;
case BOTTOM:
startY = chartArea.getMaxY() - bottomSpace - h;
break;
default:
throw new IllegalStateException("Unexpected vertical alignment.");
}
g2.drawImage(this.image, (int) startX, (int) startY, (int) w, (int) h, null);
return new Size2D(chartArea.getWidth() + leftSpace + rightSpace, h + topSpace + bottomSpace);
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LogAxis 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...
Range range = getRange();
double lower = range.getLowerBound();
double upper = range.getUpperBound();
AttributedString lowerStr = createTickLabel(lower);
AttributedString upperStr = createTickLabel(upper);
double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth();
double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth();
result += Math.max(w1, w2);
}
return result;
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LogAxis 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;
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class DateAxis 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.
*/
private double estimateMaximumTickLabelWidth(Graphics2D g2, DateTickUnit unit) {
RectangleInsets tickLabelInsets = getTickLabelInsets();
double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();
Font tickLabelFont = getTickLabelFont();
FontRenderContext frc = g2.getFontRenderContext();
LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
if (isVerticalTickLabels()) {
// all tick labels have the same width (equal to the height of
// the font)...
result += lm.getHeight();
} else {
// look at lower and upper bounds...
DateRange range = (DateRange) getRange();
Date lower = range.getLowerDate();
Date upper = range.getUpperDate();
String lowerStr, upperStr;
DateFormat formatter = getDateFormatOverride();
if (formatter != null) {
lowerStr = formatter.format(lower);
upperStr = formatter.format(upper);
} else {
lowerStr = unit.dateToString(lower);
upperStr = unit.dateToString(upper);
}
FontMetrics fm = g2.getFontMetrics(tickLabelFont);
double w1 = fm.stringWidth(lowerStr);
double w2 = fm.stringWidth(upperStr);
result += Math.max(w1, w2);
}
return result;
}
Aggregations