use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class Plot method resolveRangeAxisLocation.
/**
* Resolves a range axis location for a given plot orientation.
*
* @param location the location ({@code null} not permitted).
* @param orientation the orientation ({@code null} not permitted).
*
* @return The edge (never {@code null}).
*/
public static RectangleEdge resolveRangeAxisLocation(AxisLocation location, PlotOrientation orientation) {
Args.nullNotPermitted(location, "location");
Args.nullNotPermitted(orientation, "orientation");
RectangleEdge result = null;
switch(location) {
case TOP_OR_RIGHT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
break;
case TOP_OR_LEFT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
break;
case BOTTOM_OR_RIGHT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
break;
case BOTTOM_OR_LEFT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
break;
default:
break;
}
// the above should cover all the options...
if (result == null) {
throw new IllegalStateException("resolveRangeAxisLocation()");
}
return result;
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class Plot method resolveDomainAxisLocation.
/**
* Resolves a domain axis location for a given plot orientation.
*
* @param location the location ({@code null} not permitted).
* @param orientation the orientation ({@code null} not permitted).
*
* @return The edge (never {@code null}).
*/
public static RectangleEdge resolveDomainAxisLocation(AxisLocation location, PlotOrientation orientation) {
Args.nullNotPermitted(location, "location");
Args.nullNotPermitted(orientation, "orientation");
RectangleEdge result = null;
switch(location) {
case TOP_OR_RIGHT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
break;
case TOP_OR_LEFT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
break;
case BOTTOM_OR_RIGHT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
break;
case BOTTOM_OR_LEFT:
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
break;
default:
break;
}
// the above should cover all the options...
if (result == null) {
throw new IllegalStateException("resolveDomainAxisLocation()");
}
return result;
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CombinedRangeXYPlot method calculateAxisSpace.
/**
* Calculates the space required for the axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
*
* @return The space required for the axes.
*/
@Override
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
AxisSpace space = new AxisSpace();
PlotOrientation orientation = getOrientation();
// work out the space required by the domain axis...
AxisSpace fixed = getFixedRangeAxisSpace();
if (fixed != null) {
if (orientation == PlotOrientation.VERTICAL) {
space.setLeft(fixed.getLeft());
space.setRight(fixed.getRight());
} else if (orientation == PlotOrientation.HORIZONTAL) {
space.setTop(fixed.getTop());
space.setBottom(fixed.getBottom());
}
} else {
ValueAxis valueAxis = getRangeAxis();
RectangleEdge valueEdge = Plot.resolveRangeAxisLocation(getRangeAxisLocation(), orientation);
if (valueAxis != null) {
space = valueAxis.reserveSpace(g2, this, plotArea, valueEdge, space);
}
}
Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
// work out the maximum height or width of the non-shared axes...
int n = this.subplots.size();
int totalWeight = 0;
for (int i = 0; i < n; i++) {
XYPlot sub = (XYPlot) this.subplots.get(i);
totalWeight += sub.getWeight();
}
// calculate plotAreas of all sub-plots, maximum vertical/horizontal
// axis width/height
this.subplotAreas = new Rectangle2D[n];
double x = adjustedPlotArea.getX();
double y = adjustedPlotArea.getY();
double usableSize = 0.0;
if (orientation == PlotOrientation.VERTICAL) {
usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
}
for (int i = 0; i < n; i++) {
XYPlot plot = (XYPlot) this.subplots.get(i);
// calculate sub-plot area
if (orientation == PlotOrientation.VERTICAL) {
double w = usableSize * plot.getWeight() / totalWeight;
this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
x = x + w + this.gap;
} else if (orientation == PlotOrientation.HORIZONTAL) {
double h = usableSize * plot.getWeight() / totalWeight;
this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
y = y + h + this.gap;
}
AxisSpace subSpace = plot.calculateDomainAxisSpace(g2, this.subplotAreas[i], null);
space.ensureAtLeast(subSpace);
}
return space;
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class BoxAndWhiskerRenderer method drawHorizontalItem.
/**
* Draws the visual representation of a single data item when the plot has
* a horizontal orientation.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the plot is being drawn.
* @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 BoxAndWhiskerCategoryDataset}).
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
public void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {
BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;
double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
double categoryWidth = Math.abs(categoryEnd - categoryStart);
double yy = categoryStart;
int seriesCount = getRowCount();
int categoryCount = getColumnCount();
if (seriesCount > 1) {
double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1));
double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
// offset the start of the boxes if the total width used is smaller
// than the category width
double offset = (categoryWidth - usedWidth) / 2;
yy = yy + offset + (row * (state.getBarWidth() + seriesGap));
} else {
// offset the start of the box if the box width is smaller than
// the category width
double offset = (categoryWidth - state.getBarWidth()) / 2;
yy = yy + offset;
}
g2.setPaint(getItemPaint(row, column));
Stroke s = getItemStroke(row, column);
g2.setStroke(s);
RectangleEdge location = plot.getRangeAxisEdge();
Number xQ1 = bawDataset.getQ1Value(row, column);
Number xQ3 = bawDataset.getQ3Value(row, column);
Number xMax = bawDataset.getMaxRegularValue(row, column);
Number xMin = bawDataset.getMinRegularValue(row, column);
Shape box = null;
if (xQ1 != null && xQ3 != null && xMax != null && xMin != null) {
double xxQ1 = rangeAxis.valueToJava2D(xQ1.doubleValue(), dataArea, location);
double xxQ3 = rangeAxis.valueToJava2D(xQ3.doubleValue(), dataArea, location);
double xxMax = rangeAxis.valueToJava2D(xMax.doubleValue(), dataArea, location);
double xxMin = rangeAxis.valueToJava2D(xMin.doubleValue(), dataArea, location);
double yymid = yy + state.getBarWidth() / 2.0;
double halfW = (state.getBarWidth() / 2.0) * this.whiskerWidth;
// draw the box...
box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), state.getBarWidth());
if (this.fillBox) {
g2.fill(box);
}
Paint outlinePaint = getItemOutlinePaint(row, column);
if (this.useOutlinePaintForWhiskers) {
g2.setPaint(outlinePaint);
}
// draw the upper shadow...
g2.draw(new Line2D.Double(xxMax, yymid, xxQ3, yymid));
g2.draw(new Line2D.Double(xxMax, yymid - halfW, xxMax, yymid + halfW));
// draw the lower shadow...
g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid));
g2.draw(new Line2D.Double(xxMin, yymid - halfW, xxMin, yymid + halfW));
g2.setStroke(getItemOutlineStroke(row, column));
g2.setPaint(outlinePaint);
g2.draw(box);
}
// draw mean - SPECIAL AIMS REQUIREMENT...
g2.setPaint(this.artifactPaint);
// average radius
double aRadius;
if (this.meanVisible) {
Number xMean = bawDataset.getMeanValue(row, column);
if (xMean != null) {
double xxMean = rangeAxis.valueToJava2D(xMean.doubleValue(), dataArea, location);
aRadius = state.getBarWidth() / 4;
// visible before drawing it...
if ((xxMean > (dataArea.getMinX() - aRadius)) && (xxMean < (dataArea.getMaxX() + aRadius))) {
Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxMean - aRadius, yy + aRadius, aRadius * 2, aRadius * 2);
g2.fill(avgEllipse);
g2.draw(avgEllipse);
}
}
}
// draw median...
if (this.medianVisible) {
Number xMedian = bawDataset.getMedianValue(row, column);
if (xMedian != null) {
double xxMedian = rangeAxis.valueToJava2D(xMedian.doubleValue(), dataArea, location);
g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + state.getBarWidth()));
}
}
// collect entity and tool tip information...
if (state.getInfo() != null && box != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, box);
}
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYPlot method draw.
/**
* Draws the plot within the specified area on a graphics device.
*
* @param g2 the graphics device.
* @param area the plot area (in Java2D space).
* @param anchor an anchor point in Java2D space ({@code null}
* permitted).
* @param parentState the state from the parent plot, if there is one
* ({@code null} permitted).
* @param info collects chart drawing information ({@code null}
* permitted).
*/
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// if the plot area is too small, just return...
boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
this.axisOffset.trim(dataArea);
dataArea = integerise(dataArea);
if (dataArea.isEmpty()) {
return;
}
createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null);
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
Map<Axis, AxisState> axisStateMap = drawAxes(g2, area, dataArea, info);
PlotOrientation orient = getOrientation();
// clicked - the crosshairs will be driven off this point...
if (anchor != null && !dataArea.contains(anchor)) {
anchor = null;
}
CrosshairState crosshairState = new CrosshairState();
crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
crosshairState.setAnchor(anchor);
crosshairState.setAnchorX(Double.NaN);
crosshairState.setAnchorY(Double.NaN);
if (anchor != null) {
ValueAxis domainAxis = getDomainAxis();
if (domainAxis != null) {
double x;
if (orient == PlotOrientation.VERTICAL) {
x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
} else {
x = domainAxis.java2DToValue(anchor.getY(), dataArea, getDomainAxisEdge());
}
crosshairState.setAnchorX(x);
}
ValueAxis rangeAxis = getRangeAxis();
if (rangeAxis != null) {
double y;
if (orient == PlotOrientation.VERTICAL) {
y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
} else {
y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
}
crosshairState.setAnchorY(y);
}
}
crosshairState.setCrosshairX(getDomainCrosshairValue());
crosshairState.setCrosshairY(getRangeCrosshairValue());
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
AxisState domainAxisState = axisStateMap.get(getDomainAxis());
if (domainAxisState == null) {
if (parentState != null) {
domainAxisState = parentState.getSharedAxisStates().get(getDomainAxis());
}
}
AxisState rangeAxisState = axisStateMap.get(getRangeAxis());
if (rangeAxisState == null) {
if (parentState != null) {
rangeAxisState = parentState.getSharedAxisStates().get(getRangeAxis());
}
}
if (domainAxisState != null) {
drawDomainTickBands(g2, dataArea, domainAxisState.getTicks());
}
if (rangeAxisState != null) {
drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
}
if (domainAxisState != null) {
drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
drawZeroDomainBaseline(g2, dataArea);
}
if (rangeAxisState != null) {
drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
drawZeroRangeBaseline(g2, dataArea);
}
Graphics2D savedG2 = g2;
BufferedImage dataImage = null;
boolean suppressShadow = Boolean.TRUE.equals(g2.getRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION));
if (this.shadowGenerator != null && !suppressShadow) {
dataImage = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
g2 = dataImage.createGraphics();
g2.translate(-dataArea.getX(), -dataArea.getY());
g2.setRenderingHints(savedG2.getRenderingHints());
}
// draw the markers that are associated with a specific dataset...
for (XYDataset<S> dataset : this.datasets.values()) {
int datasetIndex = indexOf(dataset);
drawDomainMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND);
}
for (XYDataset<S> dataset : this.datasets.values()) {
int datasetIndex = indexOf(dataset);
drawRangeMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND);
}
// now draw annotations and render data items...
boolean foundData = false;
DatasetRenderingOrder order = getDatasetRenderingOrder();
List<Integer> rendererIndices = getRendererIndices(order);
List<Integer> datasetIndices = getDatasetIndices(order);
// draw background annotations
for (int i : rendererIndices) {
XYItemRenderer renderer = getRenderer(i);
if (renderer != null) {
ValueAxis domainAxis = getDomainAxisForDataset(i);
ValueAxis rangeAxis = getRangeAxisForDataset(i);
renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
}
}
// render data items...
for (int datasetIndex : datasetIndices) {
foundData = render(g2, dataArea, datasetIndex, info, crosshairState) || foundData;
}
// draw foreground annotations
for (int i : rendererIndices) {
XYItemRenderer renderer = getRenderer(i);
if (renderer != null) {
ValueAxis domainAxis = getDomainAxisForDataset(i);
ValueAxis rangeAxis = getRangeAxisForDataset(i);
renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
}
}
// draw domain crosshair if required...
int datasetIndex = crosshairState.getDatasetIndex();
ValueAxis xAxis = getDomainAxisForDataset(datasetIndex);
RectangleEdge xAxisEdge = getDomainAxisEdge(getDomainAxisIndex(xAxis));
if (!this.domainCrosshairLockedOnData && anchor != null) {
double xx;
if (orient == PlotOrientation.VERTICAL) {
xx = xAxis.java2DToValue(anchor.getX(), dataArea, xAxisEdge);
} else {
xx = xAxis.java2DToValue(anchor.getY(), dataArea, xAxisEdge);
}
crosshairState.setCrosshairX(xx);
}
setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
if (isDomainCrosshairVisible()) {
double x = getDomainCrosshairValue();
Paint paint = getDomainCrosshairPaint();
Stroke stroke = getDomainCrosshairStroke();
drawDomainCrosshair(g2, dataArea, orient, x, xAxis, stroke, paint);
}
// draw range crosshair if required...
ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
RectangleEdge yAxisEdge = getRangeAxisEdge(getRangeAxisIndex(yAxis));
if (!this.rangeCrosshairLockedOnData && anchor != null) {
double yy;
if (orient == PlotOrientation.VERTICAL) {
yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge);
} else {
yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge);
}
crosshairState.setCrosshairY(yy);
}
setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
if (isRangeCrosshairVisible()) {
double y = getRangeCrosshairValue();
Paint paint = getRangeCrosshairPaint();
Stroke stroke = getRangeCrosshairStroke();
drawRangeCrosshair(g2, dataArea, orient, y, yAxis, stroke, paint);
}
if (!foundData) {
drawNoDataMessage(g2, dataArea);
}
for (int i : rendererIndices) {
drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
for (int i : rendererIndices) {
drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
drawAnnotations(g2, dataArea, info);
if (this.shadowGenerator != null && !suppressShadow) {
BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage);
g2 = savedG2;
g2.drawImage(shadowImage, (int) dataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) dataArea.getY() + this.shadowGenerator.calculateOffsetY(), null);
g2.drawImage(dataImage, (int) dataArea.getX(), (int) dataArea.getY(), null);
}
g2.setClip(originalClip);
g2.setComposite(originalComposite);
drawOutline(g2, dataArea);
}
Aggregations