use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class StandardXYItemRenderer 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 data 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) {
boolean itemVisible = getItemVisible(series, item);
// setup for collecting optional entity info...
Shape entityArea = null;
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
PlotOrientation orientation = plot.getOrientation();
Paint paint = getItemPaint(series, item);
Stroke seriesStroke = getItemStroke(series, item);
g2.setPaint(paint);
g2.setStroke(seriesStroke);
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(x1) || Double.isNaN(y1)) {
itemVisible = false;
}
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
if (getPlotLines()) {
if (this.drawSeriesLineAsPath) {
State s = (State) state;
if (s.getSeriesIndex() != series) {
// we are starting a new series path
s.seriesPath.reset();
s.lastPointGood = false;
s.setSeriesIndex(series);
}
// update path to reflect latest point
if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
float x = (float) transX1;
float y = (float) transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
x = (float) transY1;
y = (float) transX1;
}
if (s.isLastPointGood()) {
// TODO: check threshold
s.seriesPath.lineTo(x, y);
} else {
s.seriesPath.moveTo(x, y);
}
s.setLastPointGood(true);
} else {
s.setLastPointGood(false);
}
if (item == dataset.getItemCount(series) - 1) {
if (s.seriesIndex == series) {
// draw path
g2.setStroke(lookupSeriesStroke(series));
g2.setPaint(lookupSeriesPaint(series));
g2.draw(s.seriesPath);
}
}
} else if (item != 0 && itemVisible) {
// get the previous data point...
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
boolean drawLine = true;
if (getPlotDiscontinuous()) {
// only draw a line if the gap between the current and
// previous data point is within the threshold
int numX = dataset.getItemCount(series);
double minX = dataset.getXValue(series, 0);
double maxX = dataset.getXValue(series, numX - 1);
if (this.gapThresholdType == UnitType.ABSOLUTE) {
drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
} else {
drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
}
}
if (drawLine) {
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
// only draw if we have good values
if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
return;
}
if (orientation == PlotOrientation.HORIZONTAL) {
state.workingLine.setLine(transY0, transX0, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
state.workingLine.setLine(transX0, transY0, transX1, transY1);
}
if (state.workingLine.intersects(dataArea)) {
g2.draw(state.workingLine);
}
}
}
}
}
// to do for non-visible items...
if (!itemVisible) {
return;
}
if (getBaseShapesVisible()) {
Shape shape = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtils.createTranslatedShape(shape, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtils.createTranslatedShape(shape, transX1, transY1);
}
if (shape.intersects(dataArea)) {
if (getItemShapeFilled(series, item)) {
g2.fill(shape);
} else {
g2.draw(shape);
}
}
entityArea = shape;
}
if (getPlotImages()) {
Image image = getImage(plot, series, item, transX1, transY1);
if (image != null) {
Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null));
}
}
double xx = transX1;
double yy = transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = transY1;
yy = transX1;
}
// draw the item label if there is one...
if (isItemLabelVisible(series, item)) {
drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
}
int datasetIndex = plot.indexOf(dataset);
updateCrosshairValues(crosshairState, x1, y1, datasetIndex, transX1, transY1, orientation);
// add an entity for the item...
if (entities != null && ShapeUtils.isPointInRect(dataArea, xx, yy)) {
addEntity(entities, entityArea, dataset, series, item, xx, yy);
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class WindItemRenderer method drawItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param plotArea the area within which the plot is being drawn.
* @param info optional information collection.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the horizontal axis.
* @param rangeAxis the vertical 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 plotArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
WindDataset windData = (WindDataset) dataset;
Paint seriesPaint = getItemPaint(series, item);
Stroke seriesStroke = getItemStroke(series, item);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
// get the data point...
Number x = windData.getX(series, item);
Number windDir = windData.getWindDirection(series, item);
Number wforce = windData.getWindForce(series, item);
double windForce = wforce.doubleValue();
double wdirt = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0);
double ax1, ax2, ay1, ay2, rax2, ray2;
RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
ax1 = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation);
ay1 = rangeAxis.valueToJava2D(0.0, plotArea, rangeAxisLocation);
rax2 = x.doubleValue() + (windForce * Math.cos(wdirt) * 8000000.0);
ray2 = windForce * Math.sin(wdirt);
ax2 = domainAxis.valueToJava2D(rax2, plotArea, domainAxisLocation);
ay2 = rangeAxis.valueToJava2D(ray2, plotArea, rangeAxisLocation);
int diri = windDir.intValue();
int forcei = wforce.intValue();
String dirforce = diri + "-" + forcei;
Line2D line = new Line2D.Double(ax1, ay1, ax2, ay2);
g2.draw(line);
g2.setPaint(Color.BLUE);
g2.setFont(new Font("Dialog", 1, 9));
g2.drawString(dirforce, (float) ax1, (float) ay1);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
double alx2, aly2, arx2, ary2;
double ralx2, raly2, rarx2, rary2;
double aldir = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0 - 5.0);
ralx2 = wforce.doubleValue() * Math.cos(aldir) * 8000000 * 0.8 + x.doubleValue();
raly2 = wforce.doubleValue() * Math.sin(aldir) * 0.8;
alx2 = domainAxis.valueToJava2D(ralx2, plotArea, domainAxisLocation);
aly2 = rangeAxis.valueToJava2D(raly2, plotArea, rangeAxisLocation);
line = new Line2D.Double(alx2, aly2, ax2, ay2);
g2.draw(line);
double ardir = Math.toRadians(windDir.doubleValue() * (-30.0) - 90.0 + 5.0);
rarx2 = wforce.doubleValue() * Math.cos(ardir) * 8000000 * 0.8 + x.doubleValue();
rary2 = wforce.doubleValue() * Math.sin(ardir) * 0.8;
arx2 = domainAxis.valueToJava2D(rarx2, plotArea, domainAxisLocation);
ary2 = rangeAxis.valueToJava2D(rary2, plotArea, rangeAxisLocation);
line = new Line2D.Double(arx2, ary2, ax2, ay2);
g2.draw(line);
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class AreaRenderer method drawItem.
/**
* Draw a single data item.
*
* @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 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) {
// do nothing if item is not visible or null
if (!getItemVisible(row, column)) {
return;
}
Number value = dataset.getValue(row, column);
if (value == null) {
return;
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge axisEdge = plot.getDomainAxisEdge();
int count = dataset.getColumnCount();
float x0 = (float) domainAxis.getCategoryStart(column, count, dataArea, axisEdge);
float x1 = (float) domainAxis.getCategoryMiddle(column, count, dataArea, axisEdge);
float x2 = (float) domainAxis.getCategoryEnd(column, count, dataArea, axisEdge);
x0 = Math.round(x0);
x1 = Math.round(x1);
x2 = Math.round(x2);
if (this.endType == AreaRendererEndType.TRUNCATE) {
if (column == 0) {
x0 = x1;
} else if (column == getColumnCount() - 1) {
x2 = x1;
}
}
double yy1 = value.doubleValue();
double yy0 = 0.0;
if (this.endType == AreaRendererEndType.LEVEL) {
yy0 = yy1;
}
if (column > 0) {
Number n0 = dataset.getValue(row, column - 1);
if (n0 != null) {
yy0 = (n0.doubleValue() + yy1) / 2.0;
}
}
double yy2 = 0.0;
if (column < dataset.getColumnCount() - 1) {
Number n2 = dataset.getValue(row, column + 1);
if (n2 != null) {
yy2 = (n2.doubleValue() + yy1) / 2.0;
}
} else if (this.endType == AreaRendererEndType.LEVEL) {
yy2 = yy1;
}
RectangleEdge edge = plot.getRangeAxisEdge();
float y0 = (float) rangeAxis.valueToJava2D(yy0, dataArea, edge);
float y1 = (float) rangeAxis.valueToJava2D(yy1, dataArea, edge);
float y2 = (float) rangeAxis.valueToJava2D(yy2, dataArea, edge);
float yz = (float) rangeAxis.valueToJava2D(0.0, dataArea, edge);
double labelXX = x1;
double labelYY = y1;
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
GeneralPath area = new GeneralPath();
if (orientation == PlotOrientation.VERTICAL) {
area.moveTo(x0, yz);
area.lineTo(x0, y0);
area.lineTo(x1, y1);
area.lineTo(x2, y2);
area.lineTo(x2, yz);
} else if (orientation == PlotOrientation.HORIZONTAL) {
area.moveTo(yz, x0);
area.lineTo(y0, x0);
area.lineTo(y1, x1);
area.lineTo(y2, x2);
area.lineTo(yz, x2);
double temp = labelXX;
labelXX = labelYY;
labelYY = temp;
}
area.closePath();
g2.setPaint(getItemPaint(row, column));
g2.fill(area);
// draw the item labels if there are any...
if (isItemLabelVisible(row, column)) {
drawItemLabel(g2, orientation, dataset, row, column, labelXX, labelYY, (value.doubleValue() < 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), yy1, datasetIndex, x1, y1, orientation);
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, area);
}
}
use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class GanttRenderer method drawTasks.
/**
* Draws the tasks/subtasks for one item.
*
* @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 drawTasks(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
int count = dataset.getSubIntervalCount(row, column);
if (count == 0) {
drawTask(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column);
}
PlotOrientation orientation = plot.getOrientation();
for (int subinterval = 0; subinterval < count; subinterval++) {
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
// value 0
Number value0 = dataset.getStartValue(row, column, subinterval);
if (value0 == null) {
return;
}
double translatedValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
// value 1
Number value1 = dataset.getEndValue(row, column, subinterval);
if (value1 == null) {
return;
}
double translatedValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
if (translatedValue1 < translatedValue0) {
double temp = translatedValue1;
translatedValue1 = translatedValue0;
translatedValue0 = temp;
}
double rectStart = calculateBarW0(plot, plot.getOrientation(), dataArea, domainAxis, state, row, column);
double rectLength = Math.abs(translatedValue1 - translatedValue0);
double rectBreadth = state.getBarWidth();
// DRAW THE BARS...
Rectangle2D bar = null;
RectangleEdge barBase = null;
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
bar = new Rectangle2D.Double(translatedValue0, rectStart, rectLength, rectBreadth);
barBase = RectangleEdge.LEFT;
} else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
bar = new Rectangle2D.Double(rectStart, translatedValue0, rectBreadth, rectLength);
barBase = RectangleEdge.BOTTOM;
}
Rectangle2D completeBar = null;
Rectangle2D incompleteBar = null;
Number percent = dataset.getPercentComplete(row, column, subinterval);
double start = getStartPercent();
double end = getEndPercent();
if (percent != null) {
double p = percent.doubleValue();
if (orientation == PlotOrientation.HORIZONTAL) {
completeBar = new Rectangle2D.Double(translatedValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start));
incompleteBar = new Rectangle2D.Double(translatedValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
} else if (orientation == PlotOrientation.VERTICAL) {
completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, translatedValue0 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p);
incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, translatedValue0, rectBreadth * (end - start), rectLength * (1 - p));
}
}
if (getShadowsVisible()) {
getBarPainter().paintBarShadow(g2, this, row, column, bar, barBase, true);
}
getBarPainter().paintBar(g2, this, row, column, bar, barBase);
if (completeBar != null) {
g2.setPaint(getCompletePaint());
g2.fill(completeBar);
}
if (incompleteBar != null) {
g2.setPaint(getIncompletePaint());
g2.fill(incompleteBar);
}
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
g2.setStroke(getItemStroke(row, column));
g2.setPaint(getItemOutlinePaint(row, column));
g2.draw(bar);
}
if (subinterval == count - 1) {
// submit the current data point as a crosshair candidate
int datasetIndex = plot.indexOf(dataset);
Comparable columnKey = dataset.getColumnKey(column);
Comparable rowKey = dataset.getRowKey(row);
double xx = domainAxis.getCategorySeriesMiddle(columnKey, rowKey, dataset, getItemMargin(), dataArea, plot.getDomainAxisEdge());
updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value1.doubleValue(), datasetIndex, xx, translatedValue1, orientation);
}
// collect entity and tool tip information...
if (state.getInfo() != null) {
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 GanttRenderer method drawTask.
/**
* Draws a single task.
*
* @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 drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, GanttCategoryDataset dataset, int row, int column) {
PlotOrientation orientation = plot.getOrientation();
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;
value1 = value0;
}
double rectStart = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);
double rectBreadth = state.getBarWidth();
double rectLength = Math.abs(java2dValue1 - java2dValue0);
Rectangle2D bar = null;
RectangleEdge barBase = null;
if (orientation == PlotOrientation.HORIZONTAL) {
bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth);
barBase = RectangleEdge.LEFT;
} else if (orientation == PlotOrientation.VERTICAL) {
bar = new Rectangle2D.Double(rectStart, java2dValue1, rectBreadth, rectLength);
barBase = RectangleEdge.BOTTOM;
}
Rectangle2D completeBar = null;
Rectangle2D incompleteBar = null;
Number percent = dataset.getPercentComplete(row, column);
double start = getStartPercent();
double end = getEndPercent();
if (percent != null) {
double p = percent.doubleValue();
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start));
incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start));
} else if (plot.getOrientation() == PlotOrientation.VERTICAL) {
completeBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1 + rectLength * (1 - p), rectBreadth * (end - start), rectLength * p);
incompleteBar = new Rectangle2D.Double(rectStart + start * rectBreadth, java2dValue1, rectBreadth * (end - start), rectLength * (1 - p));
}
}
if (getShadowsVisible()) {
getBarPainter().paintBarShadow(g2, this, row, column, bar, barBase, true);
}
getBarPainter().paintBar(g2, this, row, column, bar, barBase);
if (completeBar != null) {
g2.setPaint(getCompletePaint());
g2.fill(completeBar);
}
if (incompleteBar != null) {
g2.setPaint(getIncompletePaint());
g2.fill(incompleteBar);
}
// draw the outline...
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = getItemOutlineStroke(row, column);
Paint paint = getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, false);
}
// submit the current data point as a crosshair candidate
int datasetIndex = plot.indexOf(dataset);
Comparable columnKey = dataset.getColumnKey(column);
Comparable rowKey = dataset.getRowKey(row);
double xx = domainAxis.getCategorySeriesMiddle(columnKey, rowKey, dataset, getItemMargin(), dataArea, plot.getDomainAxisEdge());
updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value1.doubleValue(), datasetIndex, xx, java2dValue1, orientation);
// collect entity and tool tip information...
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
Aggregations