use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
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.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class TextTitle 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();
g2.setFont(this.font);
this.content = TextUtilities.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) heightRange.getUpperBound();
g2.setFont(this.font);
this.content = TextUtilities.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.");
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class TextTitle method drawVertical.
/**
* Draws a the title vertically within the specified area. This method
* will be called from the {@link #draw(Graphics2D, Rectangle2D) draw}
* method.
*
* @param g2 the graphics device.
* @param area the area for the title.
*/
protected void drawVertical(Graphics2D g2, Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlockAnchor anchor = null;
float y = 0.0f;
VerticalAlignment verticalAlignment = getVerticalAlignment();
if (verticalAlignment == VerticalAlignment.TOP) {
y = (float) titleArea.getY();
anchor = TextBlockAnchor.TOP_RIGHT;
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
y = (float) titleArea.getMaxY();
anchor = TextBlockAnchor.TOP_LEFT;
} else if (verticalAlignment == VerticalAlignment.CENTER) {
y = (float) titleArea.getCenterY();
anchor = TextBlockAnchor.TOP_CENTER;
}
float x = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.LEFT) {
x = (float) titleArea.getX();
} else if (position == RectangleEdge.RIGHT) {
x = (float) titleArea.getMaxX();
if (verticalAlignment == VerticalAlignment.TOP) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
} else if (verticalAlignment == VerticalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
} else if (verticalAlignment == VerticalAlignment.BOTTOM) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
}
this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
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.
*
* @since 1.0.9
*/
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 = TextUtilities.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 = TextUtilities.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.");
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class StatisticalBarRenderer method drawVerticalItem.
/**
* Draws an item for a plot with a vertical orientation.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the data area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the data.
* @param visibleRow the visible row index.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
* @param selected is the item selected?
*
* @since 1.2.0
*/
protected void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, StatisticalCategoryDataset dataset, int visibleRow, int row, int column, boolean selected) {
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
// BAR X
double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation);
int seriesCount = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : getRowCount();
int categoryCount = getColumnCount();
if (seriesCount > 1) {
double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
rectX = rectX + visibleRow * (state.getBarWidth() + seriesGap);
} else {
rectX = rectX + visibleRow * state.getBarWidth();
}
// BAR Y
Number meanValue = dataset.getMeanValue(row, column);
if (meanValue == null) {
return;
}
double value = meanValue.doubleValue();
double base = 0.0;
double lclip = rangeAxis.getLowerBound();
double uclip = rangeAxis.getUpperBound();
if (uclip <= 0.0) {
// cases 1, 2, 3 and 4
if (value >= uclip) {
// bar is not visible
return;
}
base = uclip;
if (value <= lclip) {
value = lclip;
}
} else if (lclip <= 0.0) {
// cases 5, 6, 7 and 8
if (value >= uclip) {
value = uclip;
} else {
if (value <= lclip) {
value = lclip;
}
}
} else {
// cases 9, 10, 11 and 12
if (value <= lclip) {
// bar is not visible
return;
}
base = rangeAxis.getLowerBound();
if (value >= uclip) {
value = uclip;
}
}
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
double rectY = Math.min(transY2, transY1);
double rectWidth = state.getBarWidth();
double rectHeight = Math.abs(transY2 - transY1);
Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
Paint itemPaint = getItemPaint(row, column, selected);
GradientPaintTransformer t = getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = getItemOutlineStroke(row, column, selected);
Paint paint = getItemOutlinePaint(row, column, selected);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
// standard deviation lines
Number n = dataset.getStdDevValue(row, column);
if (n != null) {
double valueDelta = n.doubleValue();
double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
if (this.errorIndicatorPaint != null) {
g2.setPaint(this.errorIndicatorPaint);
} else {
g2.setPaint(getItemOutlinePaint(row, column, selected));
}
if (this.errorIndicatorStroke != null) {
g2.setStroke(this.errorIndicatorStroke);
} else {
g2.setStroke(getItemOutlineStroke(row, column, selected));
}
Line2D line = null;
line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal);
g2.draw(line);
line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d, highVal);
g2.draw(line);
line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d, lowVal);
g2.draw(line);
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column, selected);
if (generator != null && isItemLabelVisible(row, column, selected)) {
drawItemLabelForBar(g2, plot, dataset, row, column, selected, generator, bar, (value < 0.0));
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, bar, dataset, row, column, selected);
}
}
Aggregations