@Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (viewPoint != null) { Shape oldClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.setClip(dataArea); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Ellipse2D.Double ellipse = new Ellipse2D.Double(viewPoint.getX() - 0.5 * markerSize, viewPoint.getY() - 0.5 * markerSize, markerSize, markerSize); g2.setPaint(fillPaint); g2.fill(ellipse); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(ellipse); Rectangle2D box = new Rectangle2D.Double(dataArea.getX() + 5, dataArea.getY() + 5, 100, 52); g2.setPaint(fillPaint); g2.fill(box); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(box); g2.drawString(String.format("x = %.3f", dataPoint.getX()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 20)); g2.drawString(String.format("y = %.3f", dataPoint.getY()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 40)); g2.setClip(oldClip); } }
@Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (viewPoint != null) { Shape oldClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.setClip(dataArea); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Ellipse2D.Double ellipse = new Ellipse2D.Double(viewPoint.getX() - 0.5 * markerSize, viewPoint.getY() - 0.5 * markerSize, markerSize, markerSize); g2.setPaint(fillPaint); g2.fill(ellipse); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(ellipse); Rectangle2D box = new Rectangle2D.Double(dataArea.getX() + 5, dataArea.getY() + 5, 100, 52); g2.setPaint(fillPaint); g2.fill(box); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(box); g2.drawString(String.format("x = %.3f", dataPoint.getX()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 20)); g2.drawString(String.format("y = %.3f", dataPoint.getY()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 40)); g2.setClip(oldClip); } }
@Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { Rectangle2D box = chartPanel.getScreenDataArea(); float sx = (float) plot.getDomainAxis().valueToJava2D(x, box, plot.getDomainAxisEdge()); float maxXLim = (float) box.getWidth() - g2.getFontMetrics().stringWidth(text); if (sx > maxXLim) { sx = maxXLim; } if (sx < box.getMinX()) { sx = (float) box.getMinX(); } float sy = (float) plot.getRangeAxis().valueToJava2D(y, chartPanel.getScreenDataArea(), plot.getRangeAxisEdge()); g2.setTransform(new AffineTransform()); g2.setColor(color); g2.setFont(font); g2.drawString(text, sx, sy); }
@Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { Rectangle2D box = chartPanel.getScreenDataArea(); float sx = (float) plot.getDomainAxis().valueToJava2D(x, box, plot.getDomainAxisEdge()); float maxXLim = (float) box.getWidth() - g2.getFontMetrics().stringWidth(text); if (sx > maxXLim) { sx = maxXLim; } if (sx < box.getMinX()) { sx = (float) box.getMinX(); } float sy = (float) plot.getRangeAxis().valueToJava2D(y, chartPanel.getScreenDataArea(), plot.getRangeAxisEdge()); g2.setTransform(new AffineTransform()); g2.setColor(color); g2.setFont(font); g2.drawString(text, sx, sy); }
private double getXFromChartEvent( final MouseEvent mouseEvent ) { final Rectangle2D plotArea = chartPanel.getScreenDataArea(); return plot.getDomainAxis().java2DToValue( mouseEvent.getX(), plotArea, plot.getDomainAxisEdge() ); }
private double getXFromChartEvent( final MouseEvent mouseEvent ) { final Rectangle2D plotArea = chartPanel.getScreenDataArea(); return plot.getDomainAxis().java2DToValue( mouseEvent.getX(), plotArea, plot.getDomainAxisEdge() ); }
/** * Draws a vertical line used to trace the mouse position to the horizontal * axis. * * @param g2 the graphics device. * @param x the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(Graphics2D g2, int x) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (this.verticalTraceLine != null) { g2.draw(this.verticalTraceLine); this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } else { this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } g2.draw(this.verticalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
/** * Draws a horizontal line used to trace the mouse position to the vertical * axis. * * @param g2 the graphics device. * @param y the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { if (this.horizontalTraceLine != null) { g2.draw(this.horizontalTraceLine); this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { this.horizontalTraceLine = new Line2D.Float( (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(this.horizontalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
private Double getPosition(MouseEvent e) { // System.err.println("Event position " + e.getX() + ", " + e.getY()); Point2D p = panel.translateScreenToJava2D(e.getPoint()); Rectangle2D plotArea = panel.getScreenDataArea(); XYPlot plot = (XYPlot) chart.getPlot(); return plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); }
public static int getChartXLocation( final Point point, final ChartPanel panel ) { final Point2D p = panel.translateScreenToJava2D( point ); final Rectangle2D plotArea = panel.getScreenDataArea(); final XYPlot plot = (XYPlot) panel.getChart().getPlot(); final double chartX = plot.getDomainAxis().java2DToValue( p.getX(), plotArea, plot.getDomainAxisEdge() ); //final double chartY = plot.getRangeAxis().java2DToValue( p.getY(), plotArea, plot.getRangeAxisEdge() ); return (int)Math.round( chartX ); }
public static int getChartXLocation( final Point point, final ChartPanel panel ) { final Point2D p = panel.translateScreenToJava2D( point ); final Rectangle2D plotArea = panel.getScreenDataArea(); final XYPlot plot = (XYPlot) panel.getChart().getPlot(); final double chartX = plot.getDomainAxis().java2DToValue( p.getX(), plotArea, plot.getDomainAxisEdge() ); //final double chartY = plot.getRangeAxis().java2DToValue( p.getY(), plotArea, plot.getRangeAxisEdge() ); return (int)Math.round( chartX ); }
(int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea( (int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {
(int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea( (int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {
private Shape createShape() { XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double vx1 = areaType == AreaType.Y_RANGE ? dataArea.getX() : point1.x; double vy1 = areaType == AreaType.X_RANGE ? dataArea.getY() : point1.y; double vx2 = areaType == AreaType.Y_RANGE ? dataArea.getX() + dataArea.getWidth() : point2.x; double vy2 = areaType == AreaType.X_RANGE ? dataArea.getY() + dataArea.getHeight() : point2.y; double x1 = plot.getDomainAxis().java2DToValue(vx1, dataArea, domainEdge); double x2 = plot.getDomainAxis().java2DToValue(vx2, dataArea, domainEdge); double y1 = plot.getRangeAxis().java2DToValue(vy1, dataArea, rangeEdge); double y2 = plot.getRangeAxis().java2DToValue(vy2, dataArea, rangeEdge); double dx = abs(x2 - x1); double dy = abs(y2 - y1); final Shape shape; if (areaType == AreaType.ELLIPSE) { shape = new Ellipse2D.Double(x1 - dx, y1 - dy, 2.0 * dx, 2.0 * dy); } else if (areaType == AreaType.RECTANGLE) { shape = new Rectangle2D.Double(x1 - dx, y1 - dy, 2.0 * dx, 2.0 * dy); } else if (areaType == AreaType.X_RANGE || areaType == AreaType.Y_RANGE) { shape = new Rectangle2D.Double(min(x1, x2), min(y1, y2), dx, dy); } else { throw new IllegalStateException("areaType = " + areaType); } return shape; }
private Shape createShape() { XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double vx1 = areaType == AreaType.Y_RANGE ? dataArea.getX() : point1.x; double vy1 = areaType == AreaType.X_RANGE ? dataArea.getY() : point1.y; double vx2 = areaType == AreaType.Y_RANGE ? dataArea.getX() + dataArea.getWidth() : point2.x; double vy2 = areaType == AreaType.X_RANGE ? dataArea.getY() + dataArea.getHeight() : point2.y; double x1 = plot.getDomainAxis().java2DToValue(vx1, dataArea, domainEdge); double x2 = plot.getDomainAxis().java2DToValue(vx2, dataArea, domainEdge); double y1 = plot.getRangeAxis().java2DToValue(vy1, dataArea, rangeEdge); double y2 = plot.getRangeAxis().java2DToValue(vy2, dataArea, rangeEdge); double dx = abs(x2 - x1); double dy = abs(y2 - y1); final Shape shape; if (areaType == AreaType.ELLIPSE) { shape = new Ellipse2D.Double(x1 - dx, y1 - dy, 2.0 * dx, 2.0 * dy); } else if (areaType == AreaType.RECTANGLE) { shape = new Rectangle2D.Double(x1 - dx, y1 - dy, 2.0 * dx, 2.0 * dy); } else if (areaType == AreaType.X_RANGE || areaType == AreaType.Y_RANGE) { shape = new Rectangle2D.Double(min(x1, x2), min(y1, y2), dx, dy); } else { throw new IllegalStateException("areaType = " + areaType); } return shape; }
/** * Returns the data area (the area inside the axes) for the plot or subplot, * with the current scaling applied. * * @param x the x-coordinate (for subplot selection). * @param y the y-coordinate (for subplot selection). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea(int x, int y) { PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D result; if (plotInfo.getSubplotCount() == 0) { result = getScreenDataArea(); } else { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(x, y)); int subplotIndex = plotInfo.getSubplotIndex(selectOrigin); if (subplotIndex == -1) { return null; } result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea()); } return result; }
/** * Returns the data area (the area inside the axes) for the plot or subplot, * with the current scaling applied. * * @param x the x-coordinate (for subplot selection). * @param y the y-coordinate (for subplot selection). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea(int x, int y) { PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D result; if (plotInfo.getSubplotCount() == 0) { result = getScreenDataArea(); } else { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(x, y)); int subplotIndex = plotInfo.getSubplotIndex(selectOrigin); if (subplotIndex == -1) { return null; } result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea()); } return result; }
@Override public void run() { if (cache.isEmpty()) { return; } jNextChart.getXYPlot().setDomainCrosshairVisible(true); double xValue = jNextChart.getXYPlot().getDomainCrosshairValue(); double yValue = jNextChart.getXYPlot().getRangeCrosshairValue(); RectangleEdge xEdge = jNextChart.getXYPlot().getDomainAxisEdge(); RectangleEdge yEdge = jNextChart.getXYPlot().getRangeAxisEdge(); Rectangle2D dataArea = jChartPanel.getScreenDataArea(); // jChartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0).getDataArea(); int x = (int) jNextChart.getXYPlot().getDomainAxis().valueToJava2D(xValue, dataArea, xEdge); int y = (int) jNextChart.getXYPlot().getRangeAxis().valueToJava2D(yValue, dataArea, yEdge); Date date = new Date((long)xValue); jIskValue.setText(iskFormat.format(yValue)); jDateValue.setText(dateFormat.format(date)); TrackerNote trackerNote = Settings.get().getTrackerNotes().get(new TrackerDate(date)); if (trackerNote != null) { jAddNote.setVisible(false); jEditNote.setVisible(true); jNote.setVisible(true); jNote.setText(trackerNote.getNote()); } else { jAddNote.setVisible(true); jEditNote.setVisible(false); jNote.setVisible(false); } jPopupMenu.show((Component)cme.getTrigger().getSource(), x, y); } });
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart();
Rectangle2D dataArea = chartPanel.getScreenDataArea(); Point point = event.getTrigger().getPoint();