use of org.jfree.chart.plot.XYCrosshairState in project graphcode2vec by graphcode2vec.
the class XYAreaRenderer2 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) {
if (!getItemVisible(series, item)) {
return;
}
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1)) {
y1 = 0.0;
}
double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
// get the previous point and the next point so we can calculate a
// "hot spot" for the area (used by the chart entity)...
double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
if (Double.isNaN(y0)) {
y0 = 0.0;
}
double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
int itemCount = dataset.getItemCount(series);
double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
if (Double.isNaN(y2)) {
y2 = 0.0;
}
double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());
double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
Polygon hotspot = null;
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
hotspot = new Polygon();
hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0));
hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0));
hotspot.addPoint((int) transY1, (int) transX1);
hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0));
hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0));
} else {
// vertical orientation
hotspot = new Polygon();
hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero);
hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0));
hotspot.addPoint((int) transX1, (int) transY1);
hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0));
hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero);
}
PlotOrientation orientation = plot.getOrientation();
Paint paint = getItemPaint(series, item, selected);
Stroke stroke = getItemStroke(series, item, selected);
g2.setPaint(paint);
g2.setStroke(stroke);
// Check if the item is the last item for the series.
// and number of items > 0. We can't draw an area for a single point.
g2.fill(hotspot);
// draw an outline around the Area.
if (isOutline()) {
g2.setStroke(lookupSeriesOutlineStroke(series));
g2.setPaint(lookupSeriesOutlinePaint(series));
g2.draw(hotspot);
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
XYCrosshairState crosshairState = state.getCrosshairState();
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, hotspot, dataset, series, item, selected, 0.0, 0.0);
}
}
use of org.jfree.chart.plot.XYCrosshairState in project graphcode2vec by graphcode2vec.
the class StackedXYAreaRenderer 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.
*
* @throws ClassCastException if <code>state</code> is not an instance of
* <code>StackedXYAreaRendererState</code> or <code>dataset</code>
* is not an instance of {@link TableXYDataset}.
*/
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) {
PlotOrientation orientation = plot.getOrientation();
StackedXYAreaRendererState areaState = (StackedXYAreaRendererState) state;
// Get the item count for the series, so that we can know which is the
// end of the series.
TableXYDataset tdataset = (TableXYDataset) dataset;
int itemCount = tdataset.getItemCount();
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
boolean nullPoint = false;
if (Double.isNaN(y1)) {
y1 = 0.0;
nullPoint = true;
}
// Get height adjustment based on stack and translate to Java2D values
double ph1 = getPreviousHeight(tdataset, series, item);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
double transY1 = rangeAxis.valueToJava2D(y1 + ph1, dataArea, plot.getRangeAxisEdge());
Paint seriesPaint = getItemPaint(series, item, selected);
Stroke seriesStroke = getItemStroke(series, item, selected);
if (pass == 0) {
if (item == 0) {
// Create a new Area for the series
areaState.setSeriesArea(new Polygon());
areaState.setLastSeriesPoints(areaState.getCurrentSeriesPoints());
areaState.setCurrentSeriesPoints(new Stack());
// start from previous height (ph1)
double transY2 = rangeAxis.valueToJava2D(ph1, dataArea, plot.getRangeAxisEdge());
// The first point is (x, 0)
if (orientation == PlotOrientation.VERTICAL) {
areaState.getSeriesArea().addPoint((int) transX1, (int) transY2);
} else if (orientation == PlotOrientation.HORIZONTAL) {
areaState.getSeriesArea().addPoint((int) transY2, (int) transX1);
}
}
// Add each point to Area (x, y)
if (orientation == PlotOrientation.VERTICAL) {
Point point = new Point((int) transX1, (int) transY1);
areaState.getSeriesArea().addPoint((int) point.getX(), (int) point.getY());
areaState.getCurrentSeriesPoints().push(point);
} else if (orientation == PlotOrientation.HORIZONTAL) {
areaState.getSeriesArea().addPoint((int) transY1, (int) transX1);
}
if (getPlotLines()) {
if (item > 0) {
// get the previous data point...
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
double ph0 = getPreviousHeight(tdataset, series, item - 1);
double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
double transY0 = rangeAxis.valueToJava2D(y0 + ph0, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.VERTICAL) {
areaState.getLine().setLine(transX0, transY0, transX1, transY1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
areaState.getLine().setLine(transY0, transX0, transY1, transX1);
}
g2.draw(areaState.getLine());
}
}
// items > 0. We can't draw an area for a single point.
if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
double transY2 = rangeAxis.valueToJava2D(ph1, dataArea, plot.getRangeAxisEdge());
if (orientation == PlotOrientation.VERTICAL) {
// Add the last point (x,0)
areaState.getSeriesArea().addPoint((int) transX1, (int) transY2);
} else if (orientation == PlotOrientation.HORIZONTAL) {
// Add the last point (x,0)
areaState.getSeriesArea().addPoint((int) transY2, (int) transX1);
}
// polygon
if (series != 0) {
Stack points = areaState.getLastSeriesPoints();
while (!points.empty()) {
Point point = (Point) points.pop();
areaState.getSeriesArea().addPoint((int) point.getX(), (int) point.getY());
}
}
// Fill the polygon
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
g2.fill(areaState.getSeriesArea());
// Draw an outline around the Area.
if (isOutline()) {
g2.setStroke(lookupSeriesOutlineStroke(series));
g2.setPaint(lookupSeriesOutlinePaint(series));
g2.draw(areaState.getSeriesArea());
}
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
XYCrosshairState crosshairState = state.getCrosshairState();
updateCrosshairValues(crosshairState, x1, ph1 + y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
} else if (pass == 1) {
// On second pass render shapes and collect entity and tooltip
// information
Shape shape = null;
if (getPlotShapes()) {
shape = getItemShape(series, item, selected);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
}
if (!nullPoint) {
if (getShapePaint() != null) {
g2.setPaint(getShapePaint());
} else {
g2.setPaint(seriesPaint);
}
if (getShapeStroke() != null) {
g2.setStroke(getShapeStroke());
} else {
g2.setStroke(seriesStroke);
}
g2.draw(shape);
}
} else {
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
shape = new Rectangle2D.Double(transX1 - 3, transY1 - 3, 6.0, 6.0);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
shape = new Rectangle2D.Double(transY1 - 3, transX1 - 3, 6.0, 6.0);
}
}
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, shape, dataset, series, item, selected, 0.0, 0.0);
}
}
}
use of org.jfree.chart.plot.XYCrosshairState 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.plot.XYCrosshairState in project graphcode2vec by graphcode2vec.
the class XYStepAreaRenderer 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) {
PlotOrientation orientation = plot.getOrientation();
// Get the item count for the series, so that we can know which is the
// end of the series.
int itemCount = dataset.getItemCount(series);
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);
double x = x1;
double y = Double.isNaN(y1) ? getRangeBase() : y1;
double transX1 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
double transY1 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
// avoid possible sun.dc.pr.PRException: endPath: bad path
transY1 = restrictValueToDataArea(transY1, plot, dataArea);
if (this.pArea == null && !Double.isNaN(y1)) {
// Create a new Area for the series
this.pArea = new Polygon();
// start from Y = rangeBase
double transY2 = rangeAxis.valueToJava2D(getRangeBase(), dataArea, plot.getRangeAxisEdge());
// avoid possible sun.dc.pr.PRException: endPath: bad path
transY2 = restrictValueToDataArea(transY2, plot, dataArea);
// The first point is (x, this.baseYValue)
if (orientation == PlotOrientation.VERTICAL) {
this.pArea.addPoint((int) transX1, (int) transY2);
} else if (orientation == PlotOrientation.HORIZONTAL) {
this.pArea.addPoint((int) transY2, (int) transX1);
}
}
double transX0 = 0;
double transY0 = restrictValueToDataArea(getRangeBase(), plot, dataArea);
double x0;
double y0;
if (item > 0) {
// get the previous data point...
x0 = dataset.getXValue(series, item - 1);
y0 = Double.isNaN(y1) ? y1 : dataset.getYValue(series, item - 1);
x = x0;
y = Double.isNaN(y0) ? getRangeBase() : y0;
transX0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
transY0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
// avoid possible sun.dc.pr.PRException: endPath: bad path
transY0 = restrictValueToDataArea(transY0, plot, dataArea);
if (Double.isNaN(y1)) {
// NULL value -> insert point on base line
// instead of 'step point'
transX1 = transX0;
transY0 = transY1;
}
if (transY0 != transY1) {
// not just a horizontal bar but need to perform a 'step'.
if (orientation == PlotOrientation.VERTICAL) {
this.pArea.addPoint((int) transX1, (int) transY0);
} else if (orientation == PlotOrientation.HORIZONTAL) {
this.pArea.addPoint((int) transY0, (int) transX1);
}
}
}
Shape shape = null;
if (!Double.isNaN(y1)) {
// Add each point to Area (x, y)
if (orientation == PlotOrientation.VERTICAL) {
this.pArea.addPoint((int) transX1, (int) transY1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
this.pArea.addPoint((int) transY1, (int) transX1);
}
if (getShapesVisible()) {
shape = getItemShape(series, item, selected);
if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
}
if (isShapesFilled()) {
g2.fill(shape);
} else {
g2.draw(shape);
}
} else {
if (orientation == PlotOrientation.VERTICAL) {
shape = new Rectangle2D.Double(transX1 - 2, transY1 - 2, 4.0, 4.0);
} else if (orientation == PlotOrientation.HORIZONTAL) {
shape = new Rectangle2D.Double(transY1 - 2, transX1 - 2, 4.0, 4.0);
}
}
}
// a single point.
if (getPlotArea() && item > 0 && this.pArea != null && (item == (itemCount - 1) || Double.isNaN(y1))) {
double transY2 = rangeAxis.valueToJava2D(getRangeBase(), dataArea, plot.getRangeAxisEdge());
// avoid possible sun.dc.pr.PRException: endPath: bad path
transY2 = restrictValueToDataArea(transY2, plot, dataArea);
if (orientation == PlotOrientation.VERTICAL) {
// Add the last point (x,0)
this.pArea.addPoint((int) transX1, (int) transY2);
} else if (orientation == PlotOrientation.HORIZONTAL) {
// Add the last point (x,0)
this.pArea.addPoint((int) transY2, (int) transX1);
}
// fill the polygon
g2.fill(this.pArea);
// draw an outline around the Area.
if (isOutline()) {
g2.setStroke(plot.getOutlineStroke());
g2.setPaint(plot.getOutlinePaint());
g2.draw(this.pArea);
}
// start new area when needed (see above)
this.pArea = null;
}
// do we need to update the crosshair values?
if (!Double.isNaN(y1)) {
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, shape, dataset, series, item, selected, transX1, transY1);
}
}
use of org.jfree.chart.plot.XYCrosshairState 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