use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
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.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYPolygonAnnotation method draw.
/**
* Draws the annotation. This method is usually called by the
* {@link XYPlot} class, you shouldn't need to call it 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 the plot rendering info.
*/
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
// if we don't have at least 2 (x, y) coordinates, just return
if (this.polygon.length < 4) {
return;
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
GeneralPath area = new GeneralPath();
double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge);
double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge);
if (orientation == PlotOrientation.HORIZONTAL) {
area.moveTo((float) y, (float) x);
for (int i = 2; i < this.polygon.length; i += 2) {
x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge);
y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge);
area.lineTo((float) y, (float) x);
}
area.closePath();
} else if (orientation == PlotOrientation.VERTICAL) {
area.moveTo((float) x, (float) y);
for (int i = 2; i < this.polygon.length; i += 2) {
x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge);
y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge);
area.lineTo((float) x, (float) y);
}
area.closePath();
}
if (this.fillPaint != null) {
g2.setPaint(this.fillPaint);
g2.fill(area);
}
if (this.stroke != null && this.outlinePaint != null) {
g2.setPaint(this.outlinePaint);
g2.setStroke(this.stroke);
g2.draw(area);
}
addEntity(info, area, rendererIndex, getToolTipText(), getURL());
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYBarRenderer method drawItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the plot is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState crosshair information for the plot
* ({@code null} permitted).
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
if (!getItemVisible(series, item)) {
return;
}
IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
double value0;
double value1;
if (this.useYInterval) {
value0 = intervalDataset.getStartYValue(series, item);
value1 = intervalDataset.getEndYValue(series, item);
} else {
value0 = this.base;
value1 = intervalDataset.getYValue(series, item);
}
if (Double.isNaN(value0) || Double.isNaN(value1)) {
return;
}
if (value0 <= value1) {
if (!rangeAxis.getRange().intersects(value0, value1)) {
return;
}
} else {
if (!rangeAxis.getRange().intersects(value1, value0)) {
return;
}
}
double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());
double bottom = Math.min(translatedValue0, translatedValue1);
double top = Math.max(translatedValue0, translatedValue1);
double startX = intervalDataset.getStartXValue(series, item);
if (Double.isNaN(startX)) {
return;
}
double endX = intervalDataset.getEndXValue(series, item);
if (Double.isNaN(endX)) {
return;
}
if (startX <= endX) {
if (!domainAxis.getRange().intersects(startX, endX)) {
return;
}
} else {
if (!domainAxis.getRange().intersects(endX, startX)) {
return;
}
}
// is there an alignment adjustment to be made?
if (this.barAlignmentFactor >= 0.0 && this.barAlignmentFactor <= 1.0) {
double x = intervalDataset.getXValue(series, item);
double interval = endX - startX;
startX = x - interval * this.barAlignmentFactor;
endX = startX + interval;
}
RectangleEdge location = plot.getDomainAxisEdge();
double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location);
double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location);
double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX));
double left = Math.min(translatedStartX, translatedEndX);
if (getMargin() > 0.0) {
double cut = translatedWidth * getMargin();
translatedWidth = translatedWidth - cut;
left = left + cut / 2;
}
Rectangle2D bar = null;
PlotOrientation orientation = plot.getOrientation();
if (orientation.isHorizontal()) {
// clip left and right bounds to data area
bottom = Math.max(bottom, dataArea.getMinX());
top = Math.min(top, dataArea.getMaxX());
bar = new Rectangle2D.Double(bottom, left, top - bottom, translatedWidth);
} else if (orientation.isVertical()) {
// clip top and bottom bounds to data area
bottom = Math.max(bottom, dataArea.getMinY());
top = Math.min(top, dataArea.getMaxY());
bar = new Rectangle2D.Double(left, bottom, translatedWidth, top - bottom);
}
boolean positive = (value1 > 0.0);
boolean inverted = rangeAxis.isInverted();
RectangleEdge barBase;
if (orientation.isHorizontal()) {
if (positive && inverted || !positive && !inverted) {
barBase = RectangleEdge.RIGHT;
} else {
barBase = RectangleEdge.LEFT;
}
} else {
if (positive && !inverted || !positive && inverted) {
barBase = RectangleEdge.BOTTOM;
} else {
barBase = RectangleEdge.TOP;
}
}
if (state.getElementHinting()) {
beginElementGroup(g2, dataset.getSeriesKey(series), item);
}
if (getShadowsVisible()) {
this.barPainter.paintBarShadow(g2, this, series, item, bar, barBase, !this.useYInterval);
}
this.barPainter.paintBar(g2, this, series, item, bar, barBase);
if (state.getElementHinting()) {
endElementGroup(g2);
}
if (isItemLabelVisible(series, item)) {
XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0);
}
// update the crosshair point
double x1 = (startX + endX) / 2.0;
double y1 = dataset.getYValue(series, item);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, location);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
int datasetIndex = plot.indexOf(dataset);
updateCrosshairValues(crosshairState, x1, y1, datasetIndex, transX1, transY1, plot.getOrientation());
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, bar, dataset, series, item, 0.0, 0.0);
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYBoxAndWhiskerRenderer method drawHorizontalItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param dataArea the area within which the plot is being drawn.
* @param info collects info about the drawing.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset (must be an instance of
* {@link BoxAndWhiskerXYDataset}).
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState crosshair information for the plot
* ({@code null} permitted).
* @param pass the pass index.
*/
public void drawHorizontalItem(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
BoxAndWhiskerXYDataset boxAndWhiskerData = (BoxAndWhiskerXYDataset) dataset;
Number x = boxAndWhiskerData.getX(series, item);
Number yMax = boxAndWhiskerData.getMaxRegularValue(series, item);
Number yMin = boxAndWhiskerData.getMinRegularValue(series, item);
Number yMedian = boxAndWhiskerData.getMedianValue(series, item);
Number yAverage = boxAndWhiskerData.getMeanValue(series, item);
Number yQ1Median = boxAndWhiskerData.getQ1Value(series, item);
Number yQ3Median = boxAndWhiskerData.getQ3Value(series, item);
double xx = domainAxis.valueToJava2D(x.doubleValue(), dataArea, plot.getDomainAxisEdge());
RectangleEdge location = plot.getRangeAxisEdge();
double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
double yyAverage = 0.0;
if (yAverage != null) {
yyAverage = rangeAxis.valueToJava2D(yAverage.doubleValue(), dataArea, location);
}
double yyQ1Median = rangeAxis.valueToJava2D(yQ1Median.doubleValue(), dataArea, location);
double yyQ3Median = rangeAxis.valueToJava2D(yQ3Median.doubleValue(), dataArea, location);
double exactBoxWidth = getBoxWidth();
double width = exactBoxWidth;
double dataAreaX = dataArea.getHeight();
double maxBoxPercent = 0.1;
double maxBoxWidth = dataAreaX * maxBoxPercent;
if (exactBoxWidth <= 0.0) {
int itemCount = boxAndWhiskerData.getItemCount(series);
exactBoxWidth = dataAreaX / itemCount * 4.5 / 7;
if (exactBoxWidth < 3) {
width = 3;
} else if (exactBoxWidth > maxBoxWidth) {
width = maxBoxWidth;
} else {
width = exactBoxWidth;
}
}
g2.setPaint(getItemPaint(series, item));
Stroke s = getItemStroke(series, item);
g2.setStroke(s);
// draw the upper shadow
g2.draw(new Line2D.Double(yyMax, xx, yyQ3Median, xx));
g2.draw(new Line2D.Double(yyMax, xx - width / 2, yyMax, xx + width / 2));
// draw the lower shadow
g2.draw(new Line2D.Double(yyMin, xx, yyQ1Median, xx));
g2.draw(new Line2D.Double(yyMin, xx - width / 2, yyMin, xx + width / 2));
// draw the body
Shape box;
if (yyQ1Median < yyQ3Median) {
box = new Rectangle2D.Double(yyQ1Median, xx - width / 2, yyQ3Median - yyQ1Median, width);
} else {
box = new Rectangle2D.Double(yyQ3Median, xx - width / 2, yyQ1Median - yyQ3Median, width);
}
if (this.fillBox) {
g2.setPaint(lookupBoxPaint(series, item));
g2.fill(box);
}
g2.setStroke(getItemOutlineStroke(series, item));
g2.setPaint(getItemOutlinePaint(series, item));
g2.draw(box);
// draw median
g2.setPaint(getArtifactPaint());
g2.draw(new Line2D.Double(yyMedian, xx - width / 2, yyMedian, xx + width / 2));
// draw average - SPECIAL AIMS REQUIREMENT
if (yAverage != null) {
double aRadius = width / 4;
// before drawing it...
if ((yyAverage > (dataArea.getMinX() - aRadius)) && (yyAverage < (dataArea.getMaxX() + aRadius))) {
Ellipse2D.Double avgEllipse = new Ellipse2D.Double(yyAverage - aRadius, xx - aRadius, aRadius * 2, aRadius * 2);
g2.fill(avgEllipse);
g2.draw(avgEllipse);
}
}
// add an entity for the item...
if (entities != null && box.intersects(dataArea)) {
addEntity(entities, box, dataset, series, item, yyAverage, xx);
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYDifferenceRenderer method createPolygon.
/**
* Draws the visual representation of a polygon
*
* @param x_graphics the graphics device.
* @param x_dataArea the area within which the data is being drawn.
* @param x_plot the plot (can be used to obtain standard color
* information etc).
* @param x_domainAxis the domain (horizontal) axis.
* @param x_rangeAxis the range (vertical) axis.
* @param x_positive indicates if the polygon is positive (true) or
* negative (false).
* @param x_xValues a linked list of the x values (expects values to be
* of type Double).
* @param x_yValues a linked list of the y values (expects values to be
* of type Double).
*/
private void createPolygon(Graphics2D x_graphics, Rectangle2D x_dataArea, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, boolean x_positive, LinkedList x_xValues, LinkedList x_yValues) {
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
Object[] l_xValues = x_xValues.toArray();
Object[] l_yValues = x_yValues.toArray();
GeneralPath l_path = new GeneralPath();
if (PlotOrientation.VERTICAL == l_orientation) {
double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]), x_dataArea, l_rangeAxisLocation);
l_path.moveTo((float) l_x, (float) l_y);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]), x_dataArea, l_rangeAxisLocation);
l_path.lineTo((float) l_x, (float) l_y);
}
l_path.closePath();
} else {
double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]), x_dataArea, l_rangeAxisLocation);
l_path.moveTo((float) l_y, (float) l_x);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]), x_dataArea, l_rangeAxisLocation);
l_path.lineTo((float) l_y, (float) l_x);
}
l_path.closePath();
}
if (l_path.intersects(x_dataArea)) {
x_graphics.setPaint(x_positive ? getPositivePaint() : getNegativePaint());
x_graphics.fill(l_path);
}
}
Aggregations