use of org.jfree.chart.plot.Crosshair in project jfreechart-fx by jfree.
the class CrosshairOverlayFX method paintOverlay.
@Override
public void paintOverlay(Graphics2D g2, ChartCanvas chartCanvas) {
if (chartCanvas.getRenderingInfo() == null) {
return;
}
Shape savedClip = g2.getClip();
Rectangle2D dataArea = chartCanvas.getRenderingInfo().getPlotInfo().getDataArea();
g2.clip(dataArea);
JFreeChart chart = chartCanvas.getChart();
XYPlot plot = (XYPlot) chart.getPlot();
ValueAxis xAxis = plot.getDomainAxis();
RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
Iterator iterator = getDomainCrosshairs().iterator();
while (iterator.hasNext()) {
Crosshair ch = (Crosshair) iterator.next();
if (ch.isVisible()) {
double x = ch.getValue();
double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
drawVerticalCrosshair(g2, dataArea, xx, ch);
} else {
drawHorizontalCrosshair(g2, dataArea, xx, ch);
}
}
}
ValueAxis yAxis = plot.getRangeAxis();
RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
iterator = getRangeCrosshairs().iterator();
while (iterator.hasNext()) {
Crosshair ch = (Crosshair) iterator.next();
if (ch.isVisible()) {
double y = ch.getValue();
double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge);
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
drawHorizontalCrosshair(g2, dataArea, yy, ch);
} else {
drawVerticalCrosshair(g2, dataArea, yy, ch);
}
}
}
g2.setClip(savedClip);
}
Aggregations