use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class SamplingXYLineRenderer 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 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 pass the pass index.
*/
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
State s = (State) state;
// update path to reflect latest point
if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
float x = (float) transX1;
float y = (float) transY1;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
x = (float) transY1;
y = (float) transX1;
}
if (s.lastPointGood) {
if ((Math.abs(x - s.lastX) > s.dX)) {
s.seriesPath.lineTo(x, y);
if (s.lowY < s.highY) {
s.intervalPath.moveTo((float) s.lastX, (float) s.lowY);
s.intervalPath.lineTo((float) s.lastX, (float) s.highY);
}
s.lastX = x;
s.openY = y;
s.highY = y;
s.lowY = y;
s.closeY = y;
} else {
s.highY = Math.max(s.highY, y);
s.lowY = Math.min(s.lowY, y);
s.closeY = y;
}
} else {
s.seriesPath.moveTo(x, y);
s.lastX = x;
s.openY = y;
s.highY = y;
s.lowY = y;
s.closeY = y;
}
s.lastPointGood = true;
} else {
s.lastPointGood = false;
}
// if this is the last item, draw the path ...
if (item == s.getLastItemIndex()) {
// draw path
PathIterator pi = s.seriesPath.getPathIterator(null);
int count = 0;
while (!pi.isDone()) {
count++;
pi.next();
}
g2.setStroke(getItemStroke(series, item, selected));
g2.setPaint(getItemPaint(series, item, selected));
g2.draw(s.seriesPath);
g2.draw(s.intervalPath);
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
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 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 pass the pass index.
*/
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
boolean itemVisible = getItemVisible(series, item);
// setup for collecting optional entity info...
Shape entityArea = null;
EntityCollection entities = null;
if (state.getInfo() != null) {
entities = state.getInfo().getOwner().getEntityCollection();
}
PlotOrientation orientation = plot.getOrientation();
Paint paint = getItemPaint(series, item, selected);
Stroke seriesStroke = getItemStroke(series, item, selected);
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, selected);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.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, selected)) {
drawItemLabel(g2, orientation, dataset, series, item, selected, xx, yy, (y1 < 0.0));
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
XYCrosshairState crosshairState = state.getCrosshairState();
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
// add an entity for the item...
if (entities != null && ShapeUtilities.isPointInRect(xx, yy, dataArea)) {
addEntity(entities, entityArea, dataset, series, item, selected, xx, yy);
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYErrorRenderer method drawItem.
/**
* Draws the visual representation for one data item.
*
* @param g2 the graphics output target.
* @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 series the series index.
* @param item the item index.
* @param pass the pass index.
*/
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
if (pass == 0 && dataset instanceof IntervalXYDataset && getItemVisible(series, item)) {
IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
PlotOrientation orientation = plot.getOrientation();
if (this.drawXError) {
// draw the error bar for the x-interval
double x0 = ixyd.getStartXValue(series, item);
double x1 = ixyd.getEndXValue(series, item);
double y = ixyd.getYValue(series, item);
RectangleEdge edge = plot.getDomainAxisEdge();
double xx0 = domainAxis.valueToJava2D(x0, dataArea, edge);
double xx1 = domainAxis.valueToJava2D(x1, dataArea, edge);
double yy = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
Line2D line;
Line2D cap1 = null;
Line2D cap2 = null;
double adj = this.capLength / 2.0;
if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(xx0, yy, xx1, yy);
cap1 = new Line2D.Double(xx0, yy - adj, xx0, yy + adj);
cap2 = new Line2D.Double(xx1, yy - adj, xx1, yy + adj);
} else {
// PlotOrientation.HORIZONTAL
line = new Line2D.Double(yy, xx0, yy, xx1);
cap1 = new Line2D.Double(yy - adj, xx0, yy + adj, xx0);
cap2 = new Line2D.Double(yy - adj, xx1, yy + adj, xx1);
}
if (this.errorPaint != null) {
g2.setPaint(this.errorPaint);
} else {
g2.setPaint(getItemPaint(series, item, selected));
}
if (this.errorStroke != null) {
g2.setStroke(this.errorStroke);
} else {
g2.setStroke(getItemStroke(series, item, selected));
}
g2.draw(line);
g2.draw(cap1);
g2.draw(cap2);
}
if (this.drawYError) {
// draw the error bar for the y-interval
double y0 = ixyd.getStartYValue(series, item);
double y1 = ixyd.getEndYValue(series, item);
double x = ixyd.getXValue(series, item);
RectangleEdge edge = plot.getRangeAxisEdge();
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
Line2D line;
Line2D cap1 = null;
Line2D cap2 = null;
double adj = this.capLength / 2.0;
if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(xx, yy0, xx, yy1);
cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
} else {
// PlotOrientation.HORIZONTAL
line = new Line2D.Double(yy0, xx, yy1, xx);
cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
}
if (this.errorPaint != null) {
g2.setPaint(this.errorPaint);
} else {
g2.setPaint(getItemPaint(series, item, selected));
}
if (this.errorStroke != null) {
g2.setStroke(this.errorStroke);
} else {
g2.setStroke(getItemStroke(series, item, selected));
}
g2.draw(line);
g2.draw(cap1);
g2.draw(cap2);
}
}
super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, series, item, selected, pass);
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYLineAndShapeRenderer method drawShape2.
/**
* Draws the item shapes and adds chart entities (second pass). This method
* draws the shapes which mark the item positions. If <code>entities</code>
* is not <code>null</code> it will be populated with entity information
* for points that fall within the data area.
*
* @param g2 the graphics device.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain axis.
* @param dataArea the area within which the data is being drawn.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param pass the pass.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param selected is the data item selected?
* @param crosshairState the crosshair state.
* @param entities the entity collection.
*/
protected void drawShape2(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, int pass, int series, int item, boolean selected, ValueAxis domainAxis, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) {
Shape entityArea = null;
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1) || Double.isNaN(x1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
if (getItemShapeVisible(series, item)) {
Shape shape = getItemShape(series, item, selected);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
}
entityArea = shape;
if (shape.intersects(dataArea)) {
if (getItemShapeFilled(series, item)) {
if (this.useFillPaint) {
g2.setPaint(getItemFillPaint(series, item, selected));
} else {
g2.setPaint(getItemPaint(series, item, selected));
}
g2.fill(shape);
}
if (this.drawOutlines) {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(series, item, selected));
} else {
g2.setPaint(getItemPaint(series, item, selected));
}
g2.setStroke(getItemOutlineStroke(series, item, selected));
g2.draw(shape);
}
}
}
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, selected)) {
drawItemLabel(g2, orientation, dataset, series, item, selected, xx, yy, (y1 < 0.0));
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
// area...
if (entities != null && ShapeUtilities.isPointInRect(xx, yy, dataArea)) {
addEntity(entities, entityArea, dataset, series, item, selected, xx, yy);
}
}
use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.
the class XYStepRenderer 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 plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain 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 pass the pass index.
*/
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
Paint seriesPaint = getItemPaint(series, item, selected);
Stroke seriesStroke = getItemStroke(series, item, selected);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = (Double.isNaN(y1) ? Double.NaN : rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));
if (pass == 0 && item > 0) {
// get the previous data point...
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = (Double.isNaN(y0) ? Double.NaN : rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation));
if (orientation == PlotOrientation.HORIZONTAL) {
if (transY0 == transY1) {
// this represents the situation
// for drawing a horizontal bar.
drawLine(g2, state.workingLine, transY0, transX0, transY1, transX1);
} else {
// this handles the need to perform a 'step'.
// calculate the step point
double transXs = transX0 + (getStepPoint() * (transX1 - transX0));
drawLine(g2, state.workingLine, transY0, transX0, transY0, transXs);
drawLine(g2, state.workingLine, transY0, transXs, transY1, transXs);
drawLine(g2, state.workingLine, transY1, transXs, transY1, transX1);
}
} else if (orientation == PlotOrientation.VERTICAL) {
if (transY0 == transY1) {
// this represents the situation
// for drawing a horizontal bar.
drawLine(g2, state.workingLine, transX0, transY0, transX1, transY1);
} else {
// this handles the need to perform a 'step'.
// calculate the step point
double transXs = transX0 + (getStepPoint() * (transX1 - transX0));
drawLine(g2, state.workingLine, transX0, transY0, transXs, transY0);
drawLine(g2, state.workingLine, transXs, transY0, transXs, transY1);
drawLine(g2, state.workingLine, transXs, transY1, transX1, transY1);
}
}
// submit this data item as a candidate for the crosshair point
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
XYCrosshairState crosshairState = state.getCrosshairState();
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
// collect entity and tool tip information...
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, null, dataset, series, item, selected, transX1, transY1);
}
}
if (pass == 1) {
// draw the item label if there is one...
if (isItemLabelVisible(series, item, selected)) {
double xx = transX1;
double yy = transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = transY1;
yy = transX1;
}
drawItemLabel(g2, orientation, dataset, series, item, selected, xx, yy, (y1 < 0.0));
}
}
}
Aggregations