use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CandlestickRenderer 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 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.
* @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) {
boolean horiz;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
horiz = true;
} else if (orientation == PlotOrientation.VERTICAL) {
horiz = false;
} else {
return;
}
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
OHLCDataset highLowData = (OHLCDataset) dataset;
double x = highLowData.getXValue(series, item);
double yHigh = highLowData.getHighValue(series, item);
double yLow = highLowData.getLowValue(series, item);
double yOpen = highLowData.getOpenValue(series, item);
double yClose = highLowData.getCloseValue(series, item);
RectangleEdge domainEdge = plot.getDomainAxisEdge();
double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge);
RectangleEdge edge = plot.getRangeAxisEdge();
double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge);
double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge);
double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge);
double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge);
double volumeWidth;
double stickWidth;
if (this.candleWidth > 0) {
// These are deliberately not bounded to minimums/maxCandleWidth to
// retain old behaviour.
volumeWidth = this.candleWidth;
stickWidth = this.candleWidth;
} else {
double xxWidth = 0;
int itemCount;
switch(this.autoWidthMethod) {
case WIDTHMETHOD_AVERAGE:
itemCount = highLowData.getItemCount(series);
if (horiz) {
xxWidth = dataArea.getHeight() / itemCount;
} else {
xxWidth = dataArea.getWidth() / itemCount;
}
break;
case WIDTHMETHOD_SMALLEST:
// Note: It would be nice to pre-calculate this per series
itemCount = highLowData.getItemCount(series);
double lastPos = -1;
xxWidth = dataArea.getWidth();
for (int i = 0; i < itemCount; i++) {
double pos = domainAxis.valueToJava2D(highLowData.getXValue(series, i), dataArea, domainEdge);
if (lastPos != -1) {
xxWidth = Math.min(xxWidth, Math.abs(pos - lastPos));
}
lastPos = pos;
}
break;
case WIDTHMETHOD_INTERVALDATA:
IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
double startPos = domainAxis.valueToJava2D(intervalXYData.getStartXValue(series, item), dataArea, plot.getDomainAxisEdge());
double endPos = domainAxis.valueToJava2D(intervalXYData.getEndXValue(series, item), dataArea, plot.getDomainAxisEdge());
xxWidth = Math.abs(endPos - startPos);
break;
}
xxWidth -= 2 * this.autoWidthGap;
xxWidth *= this.autoWidthFactor;
xxWidth = Math.min(xxWidth, this.maxCandleWidth);
volumeWidth = Math.max(Math.min(1, this.maxCandleWidth), xxWidth);
stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth);
}
Paint p = getItemPaint(series, item);
Paint outlinePaint = null;
if (this.useOutlinePaint) {
outlinePaint = getItemOutlinePaint(series, item);
}
Stroke s = getItemStroke(series, item);
g2.setStroke(s);
if (this.drawVolume) {
int volume = (int) highLowData.getVolumeValue(series, item);
double volumeHeight = volume / this.maxVolume;
double min, max;
if (horiz) {
min = dataArea.getMinX();
max = dataArea.getMaxX();
} else {
min = dataArea.getMinY();
max = dataArea.getMaxY();
}
double zzVolume = volumeHeight * (max - min);
g2.setPaint(getVolumePaint());
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
if (horiz) {
g2.fill(new Rectangle2D.Double(min, xx - volumeWidth / 2, zzVolume, volumeWidth));
} else {
g2.fill(new Rectangle2D.Double(xx - volumeWidth / 2, max - zzVolume, volumeWidth, zzVolume));
}
g2.setComposite(originalComposite);
}
if (this.useOutlinePaint) {
g2.setPaint(outlinePaint);
} else {
g2.setPaint(p);
}
double yyMaxOpenClose = Math.max(yyOpen, yyClose);
double yyMinOpenClose = Math.min(yyOpen, yyClose);
double maxOpenClose = Math.max(yOpen, yClose);
double minOpenClose = Math.min(yOpen, yClose);
// draw the upper shadow
if (yHigh > maxOpenClose) {
if (horiz) {
g2.draw(new Line2D.Double(yyHigh, xx, yyMaxOpenClose, xx));
} else {
g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose));
}
}
// draw the lower shadow
if (yLow < minOpenClose) {
if (horiz) {
g2.draw(new Line2D.Double(yyLow, xx, yyMinOpenClose, xx));
} else {
g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose));
}
}
// draw the body
Rectangle2D body;
Rectangle2D hotspot;
double length = Math.abs(yyHigh - yyLow);
double base = Math.min(yyHigh, yyLow);
if (horiz) {
body = new Rectangle2D.Double(yyMinOpenClose, xx - stickWidth / 2, yyMaxOpenClose - yyMinOpenClose, stickWidth);
hotspot = new Rectangle2D.Double(base, xx - stickWidth / 2, length, stickWidth);
} else {
body = new Rectangle2D.Double(xx - stickWidth / 2, yyMinOpenClose, stickWidth, yyMaxOpenClose - yyMinOpenClose);
hotspot = new Rectangle2D.Double(xx - stickWidth / 2, base, stickWidth, length);
}
if (yClose > yOpen) {
if (this.upPaint != null) {
g2.setPaint(this.upPaint);
} else {
g2.setPaint(p);
}
g2.fill(body);
} else {
if (this.downPaint != null) {
g2.setPaint(this.downPaint);
} else {
g2.setPaint(p);
}
g2.fill(body);
}
if (this.useOutlinePaint) {
g2.setPaint(outlinePaint);
} else {
g2.setPaint(p);
}
g2.draw(body);
// add an entity for the item...
if (entities != null) {
addEntity(entities, hotspot, 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 ClusteredXYBarRenderer method drawItem.
/**
* Draws the visual representation of a single data item. This method
* is mostly copied from the superclass, the change is that in the
* calculated space for a singe bar we draw bars for each series next to
* each other. The width of each bar is the available width divided by
* the number of series. Bars for each series are drawn in order left to
* right.
*
* @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.
* @param item the item index.
* @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 y0;
double y1;
if (getUseYInterval()) {
y0 = intervalDataset.getStartYValue(series, item);
y1 = intervalDataset.getEndYValue(series, item);
} else {
y0 = getBase();
y1 = intervalDataset.getYValue(series, item);
}
if (Double.isNaN(y0) || Double.isNaN(y1)) {
return;
}
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
double x0 = intervalDataset.getStartXValue(series, item);
double xx0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double x1 = intervalDataset.getEndXValue(series, item);
double xx1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
// this may be negative
double intervalW = xx1 - xx0;
double baseX = xx0;
if (this.centerBarAtStartValue) {
baseX = baseX - intervalW / 2.0;
}
double m = getMargin();
if (m > 0.0) {
double cut = intervalW * getMargin();
intervalW = intervalW - cut;
baseX = baseX + (cut / 2);
}
// we don't need the sign
double intervalH = Math.abs(yy0 - yy1);
PlotOrientation orientation = plot.getOrientation();
var visibleSeries = new ArrayList<Integer>();
for (int i = 0; i < dataset.getSeriesCount(); i++) {
if (isSeriesVisible(i)) {
visibleSeries.add(i);
}
}
int numSeries = visibleSeries.size();
// may be negative
double seriesBarWidth = intervalW / numSeries;
int visibleSeriesIndex = visibleSeries.indexOf(series);
Rectangle2D bar = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double barY0 = baseX + (seriesBarWidth * visibleSeriesIndex);
double barY1 = barY0 + seriesBarWidth;
double rx = Math.min(yy0, yy1);
double rw = intervalH;
double ry = Math.min(barY0, barY1);
double rh = Math.abs(barY1 - barY0);
bar = new Rectangle2D.Double(rx, ry, rw, rh);
} else if (orientation == PlotOrientation.VERTICAL) {
double barX0 = baseX + (seriesBarWidth * visibleSeriesIndex);
double barX1 = barX0 + seriesBarWidth;
double rx = Math.min(barX0, barX1);
double rw = Math.abs(barX1 - barX0);
double ry = Math.min(yy0, yy1);
double rh = intervalH;
bar = new Rectangle2D.Double(rx, ry, rw, rh);
} else {
throw new IllegalStateException();
}
boolean positive = (y1 > 0.0);
boolean inverted = rangeAxis.isInverted();
RectangleEdge barBase;
if (orientation == PlotOrientation.HORIZONTAL) {
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 (pass == 0 && getShadowsVisible()) {
getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !getUseYInterval());
}
if (pass == 1) {
getBarPainter().paintBar(g2, this, series, item, bar, barBase);
if (isItemLabelVisible(series, item)) {
XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
drawItemLabel(g2, dataset, series, item, plot, generator, bar, y1 < 0.0);
}
// add an entity for the item...
if (info != null) {
EntityCollection entities = info.getOwner().getEntityCollection();
if (entities != null) {
addEntity(entities, bar, dataset, series, item, bar.getCenterX(), bar.getCenterY());
}
}
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class IntervalBarRenderer method drawInterval.
/**
* Draws a single interval.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the data plot area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the data.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
protected void drawInterval(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, IntervalCategoryDataset dataset, int row, int column) {
int visibleRow = state.getVisibleSeriesIndex(row);
if (visibleRow < 0) {
return;
}
PlotOrientation orientation = plot.getOrientation();
double rectX = 0.0;
double rectY = 0.0;
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
// Y0
Number value0 = dataset.getEndValue(row, column);
if (value0 == null) {
return;
}
double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
// Y1
Number value1 = dataset.getStartValue(row, column);
if (value1 == null) {
return;
}
double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
if (java2dValue1 < java2dValue0) {
double temp = java2dValue1;
java2dValue1 = java2dValue0;
java2dValue0 = temp;
}
// BAR WIDTH
double rectWidth = state.getBarWidth();
// BAR HEIGHT
double rectHeight = Math.abs(java2dValue1 - java2dValue0);
RectangleEdge barBase = RectangleEdge.LEFT;
if (orientation == PlotOrientation.HORIZONTAL) {
// BAR Y
rectX = java2dValue0;
rectY = calculateBarW0(getPlot(), orientation, dataArea, domainAxis, state, visibleRow, column);
rectHeight = state.getBarWidth();
rectWidth = Math.abs(java2dValue1 - java2dValue0);
barBase = RectangleEdge.LEFT;
} else if (orientation.isVertical()) {
// BAR X
rectX = calculateBarW0(getPlot(), orientation, dataArea, domainAxis, state, visibleRow, column);
rectY = java2dValue0;
barBase = RectangleEdge.BOTTOM;
}
Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
BarPainter painter = getBarPainter();
if (state.getElementHinting()) {
beginElementGroup(g2, dataset.getRowKey(row), dataset.getColumnKey(column));
}
if (getShadowsVisible()) {
painter.paintBarShadow(g2, this, row, column, bar, barBase, false);
}
getBarPainter().paintBar(g2, this, row, column, bar, barBase);
if (state.getElementHinting()) {
endElementGroup(g2);
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LayeredBarRenderer method drawVerticalItem.
/**
* Draws the bar for a single (series, category) data item.
*
* @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 dataset.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
protected void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {
// nothing is drawn for null values...
Number dataValue = dataset.getValue(row, column);
if (dataValue == null) {
return;
}
// BAR X
double rectX = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
int seriesCount = getRowCount();
// BAR Y
double value = dataValue.doubleValue();
double base = getBase();
double lclip = getLowerClip();
double uclip = getUpperClip();
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 = getLowerClip();
if (value >= uclip) {
value = uclip;
}
}
RectangleEdge edge = plot.getRangeAxisEdge();
double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge);
double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge);
double rectY = Math.min(transY2, transY1);
double rectWidth;
double rectHeight = Math.abs(transY2 - transY1);
// draw the bar...
double shift = 0.0;
double widthFactor = 1.0;
double seriesBarWidth = getSeriesBarWidth(row);
if (!Double.isNaN(seriesBarWidth)) {
widthFactor = seriesBarWidth;
}
rectWidth = widthFactor * state.getBarWidth();
rectX = rectX + (1 - widthFactor) * state.getBarWidth() / 2.0;
if (seriesCount > 1) {
// needs to be improved !!!
shift = rectWidth * 0.20 / (seriesCount - 1);
}
Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - (seriesCount - 1 - row) * shift * 2), rectHeight);
if (state.getElementHinting()) {
beginElementGroup(g2, dataset.getRowKey(row), dataset.getColumnKey(column));
}
Paint itemPaint = getItemPaint(row, column);
GradientPaintTransformer t = getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
g2.setStroke(getItemOutlineStroke(row, column));
g2.setPaint(getItemOutlinePaint(row, column));
g2.draw(bar);
}
if (state.getElementHinting()) {
endElementGroup(g2);
}
// draw the item labels if there are any...
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, value < base);
}
// collect entity and tool tip information...
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LevelRenderer method drawItem.
/**
* Draws the bar for a single (series, category) data item.
*
* @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 dataset.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
// nothing is drawn if the row index is not included in the list with
// the indices of the visible rows...
int visibleRow = state.getVisibleSeriesIndex(row);
if (visibleRow < 0) {
return;
}
// nothing is drawn for null values...
Number dataValue = dataset.getValue(row, column);
if (dataValue == null) {
return;
}
double value = dataValue.doubleValue();
PlotOrientation orientation = plot.getOrientation();
double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
RectangleEdge edge = plot.getRangeAxisEdge();
double barL = rangeAxis.valueToJava2D(value, dataArea, edge);
// draw the bar...
Line2D line;
double x, y;
if (orientation.isHorizontal()) {
x = barL;
y = barW0 + state.getBarWidth() / 2.0;
line = new Line2D.Double(barL, barW0, barL, barW0 + state.getBarWidth());
} else {
x = barW0 + state.getBarWidth() / 2.0;
y = barL;
line = new Line2D.Double(barW0, barL, barW0 + state.getBarWidth(), barL);
}
if (state.getElementHinting()) {
beginElementGroup(g2, dataset.getRowKey(row), dataset.getColumnKey(column));
}
Stroke itemStroke = getItemStroke(row, column);
Paint itemPaint = getItemPaint(row, column);
g2.setStroke(itemStroke);
g2.setPaint(itemPaint);
g2.draw(line);
if (state.getElementHinting()) {
endElementGroup(g2);
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, orientation, dataset, row, column, x, y, (value < 0.0));
}
// submit the current data point as a crosshair candidate
int datasetIndex = plot.indexOf(dataset);
updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value, datasetIndex, barW0, barL, orientation);
// collect entity and tool tip information...
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, line.getBounds());
}
}
Aggregations