List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:net.sf.mzmine.modules.visualization.twod.PointTwoDXYPlot.java
public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { // if this is not TwoDDataSet if (index != 0) return super.render(g2, dataArea, index, info, crosshairState); // prepare some necessary constants final int x = (int) dataArea.getX(); final int y = (int) dataArea.getY(); final int width = (int) dataArea.getWidth(); final int height = (int) dataArea.getHeight(); final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound(); final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound(); final double imageRTStep = (imageRTMax - imageRTMin) / width; final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound(); final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound(); final double imageMZStep = (imageMZMax - imageMZMin) / height; // This if statement below keeps the min max values at the original values when the user // zooms in. We need some variables that scall as the box size so that the points we show // have better resolution the more someone zooms in. double dynamicImageRTMin = imageRTMin; double dynamicImageRTMax = imageRTMax; double dynamicImageMZMin = imageMZMin; double dynamicImageMZMax = imageMZMax; double dynamicImageRTStep = imageRTStep; double dynamicImageMZStep = imageMZStep; if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.lowerEndpoint()) && (imageRTMax == totalRTRange.upperEndpoint()) && (imageMZMin == totalMZRange.lowerEndpoint()) && (imageMZMax == totalMZRange.upperEndpoint()) && (zoomOutBitmap.getWidth() == width) && (zoomOutBitmap.getHeight() == height)) { g2.drawImage(zoomOutBitmap, x, y, null); return true; }/*from www . j a v a 2 s .com*/ // Save current time Date renderStartTime = new Date(); // prepare a bitmap of required size //BufferedImage image = new BufferedImage(width, height, //BufferedImage.TYPE_INT_ARGB); //ArrayList<DataPoint> listOfDataPoints = new ArrayList<DataPoint>(); //ArrayList<DataPoint> listOfRTValues = new ArrayList<DataPoint>(); ArrayList<DataPoint> listOfDataPoints; ArrayList<Double> listOfRTValues; // These two function must be run in this order Range<Double> rtRangeIn = Range.closed(getDomainAxis().getRange().getLowerBound(), getDomainAxis().getRange().getUpperBound()); Range<Double> mzRangeIn = Range.closed(getRangeAxis().getRange().getLowerBound(), getRangeAxis().getRange().getUpperBound()); listOfDataPoints = dataset.getCentroidedDataPointsInRTMZRange(rtRangeIn, mzRangeIn); listOfRTValues = dataset.getrtValuesInUserRange(); // points to be plotted List plotPoints = new ArrayList(); int count = 0; // Store the current mz,rt,int values so that they can be outputed to a file if we want //currentlyPlottedMZ = new ArrayList(); //for (Iterator dpIt = listOfDataPoints.iterator(); dpIt.hasNext();) { // make a list to keep track of the intesities of each for (DataPoint curDataPoint : listOfDataPoints) { //DataPoint curDataPoint = dpIt.next(); double currentRT = listOfRTValues.get(count).doubleValue(); double currentMZ = curDataPoint.getMZ(); plotPoints.add(new Point2D.Double(currentRT, currentMZ)); count += 1; //currentlyPlottedMZ.add() } // draw image points //for (int i = 0; i < width; i++) // for (int j = 0; j < height; j++) { // Color pointColor = paletteType.getColor(values[i][j]); // //image.setRGB(i, height - j - 1, pointColor.getRGB()); // points.add(new Point2D.Float(i,j)); // } count = 0; for (Iterator i = plotPoints.iterator(); i.hasNext();) { Point2D.Double pt = (Point2D.Double) i.next(); // using the ''dynamic'' min and max will make the resolution imporve as someone zooms // in //float xPlace = (pt.x-(float)dynamicImageRTMin)/((float)dynamicImageRTStep) + x; //float yPlace = (pt.y-(float)dynamicImageMZMin)/((float)dynamicImageMZStep) + y; double xPlace = (pt.x - dynamicImageRTMin) / (dynamicImageRTStep) + (double) x; double yPlace = (double) height - (pt.y - dynamicImageMZMin) / (dynamicImageMZStep) + (double) y; //get the current intensity // use the R, G B for the intensity double curIntensity = listOfDataPoints.get(count).getIntensity(); curIntensity = curIntensity / dataset.curMaxIntensity; //g2.setColor(Color.BLACK); Color pointColor = paletteType.getColor(curIntensity); g2.setColor(pointColor); Ellipse2D dot = new Ellipse2D.Double(xPlace - 1, yPlace - 1, 2, 2); g2.fill(dot); count += 1; } //float xPlace = ((float)42.0-(float)dynamicImageRTMin)/((float)dynamicImageRTStep)+x; //float yPlace = (float)height - ((float)201.02-(float)dynamicImageMZMin)/((float)dynamicImageMZStep)+y; //Ellipse2D dot = new Ellipse2D.Float(xPlace - 1, yPlace - 1, 2, 2); //g2.fill(dot); //g2.dispose(); // if we are zoomed out, save the values if ((imageRTMin == totalRTRange.lowerEndpoint()) && (imageRTMax == totalRTRange.upperEndpoint()) && (imageMZMin == totalMZRange.lowerEndpoint()) && (imageMZMax == totalMZRange.upperEndpoint())) { //zoomOutBitmap = image; } // Paint image //g2.drawImage(image, x, y, null); //g.setColor(Color.BLACK) Date renderFinishTime = new Date(); logger.finest("Finished rendering 2D visualizer, " + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms"); return true; }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
private void configureGradientAreaFill(Graphics2D g2, XYPlot plot, PlotRenderingInfo info, Paint itemPaint, GradientLineAreaFill gradientLineAreaFill) { final Rectangle2D plotArea = info.getPlotArea(); double plotWidth = plotArea.getWidth(); double plotHeight = plotArea.getHeight(); Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency(); Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency(); if (itemPaint instanceof Color) { Color itemColor = (Color) itemPaint; int red = itemColor.getRed(); int green = itemColor.getGreen(); int blue = itemColor.getBlue(); int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0) ? Math.round(255 * mainColorTransparency.floatValue()) : 150;/*from w w w .jav a2 s.c om*/ int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0) ? Math.round(255 * bgColorTransparency.floatValue()) : 128; Color mainColor = new Color(red, green, blue, mainColorAlpha); Paint bgColor = getBackgroundPaint(); if (bgColor == null) { bgColor = plot.getBackgroundPaint(); } Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor); Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor); g2.setPaint(areaPaint); } else { g2.setPaint(itemPaint); } }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to JPEG option in the context menu. *///from w ww . ja v a 2 s . com private void handleExportToJPEG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to JPEG"); fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("JPEG", "jpg")); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { ImageIO.write(image, "jpg", out); } /*ExportUtils.writeAsJPEG(chartCanvasList.get(0).chart, (int)chartCanvasList.get(0).getWidth(), (int)chartCanvasList.get(0).getHeight(), file);*/ } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to PNG option in the context menu. *///from w ww . j a v a2s . c o m private void handleExportToPNG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to PNG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png")); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { ImageIO.write(image, "png", out); } } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java
/** * Draws a cylinder to represent one data item. * * @param g2 the graphics device./*from w w w . java2 s . co m*/ * @param state the renderer state. * @param dataArea the area for plotting the data. * @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. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); float barL0 = Math.min(transL0, transL1); float barLength = Math.abs(transL1 - transL0); // draw the bar... GeneralPath bar = new GeneralPath(); Shape top = null; if (orientation == PlotOrientation.HORIZONTAL) { bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0); bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0); Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth())); arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth()); } else { bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2)); bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2)); Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(), getYOffset(), 180, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2)); arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset()); } Paint itemPaint = getItemPaint(row, column); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); if (itemPaint instanceof GradientPaint) { g2.setPaint(((GradientPaint) itemPaint).getColor2()); } else { g2.setPaint(PaintAlpha.darker(itemPaint)); // bd } if (top != null) { g2.fill(top); } if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (top != null) { g2.draw(top); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to PDF option in the context menu. *//* w w w. j a v a 2s . co m*/ private void handleExportToPDF() { FileChooser fileChooser = new FileChooser(); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Document Format (PDF)", "pdf")); fileChooser.setTitle("Export to PDF"); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); PDDocument doc = new PDDocument(); PDPage page = new PDPage(new PDRectangle((float) canvasPositionAndSize.totalWidth, (float) canvasPositionAndSize.totalHeight)); doc.addPage(page); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false); PDXObjectImage pdImage = new PDPixelMap(doc, image); contentStream.drawImage(pdImage, 0, 0); PDPageContentStream cos = new PDPageContentStream(doc, page); cos.drawXObject(pdImage, 0, 0, pdImage.getWidth(), pdImage.getHeight()); cos.close(); doc.save(file); } catch (IOException | COSVisitorException ex) { Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex); } /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(), (int)canvas.getHeight(), file);*/ /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(), (int)canvas.getHeight(), file);*/ } }
From source file:org.jfree.experimental.chart.plot.dial.DialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//*from www. j av a2 s .c o m*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.font); String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
@Override public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) { Plot p = canvas.getChart().getPlot(); if (!(p instanceof Zoomable)) { return;// w ww .j a v a2s.c o m } boolean hZoom, vZoom; Zoomable z = (Zoomable) p; if (z.getOrientation().isHorizontal()) { hZoom = z.isRangeZoomable(); vZoom = z.isDomainZoomable(); } else { hZoom = z.isDomainZoomable(); vZoom = z.isRangeZoomable(); } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10; if (zoomTrigger1 || zoomTrigger2) { Point2D endPoint = new Point2D.Double(e.getX(), e.getY()); PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo(); if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) { boolean saved = p.isNotify(); p.setNotify(false); z.zoomDomainAxes(0, pri, endPoint); z.zoomRangeAxes(0, pri, endPoint); p.setNotify(saved); } else { double x = this.startPoint.getX(); double y = this.startPoint.getY(); double w = e.getX() - x; double h = e.getY() - y; Rectangle2D dataArea = canvas.findDataArea(this.startPoint); double maxX = dataArea.getMaxX(); double maxY = dataArea.getMaxY(); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { y = dataArea.getMinY(); w = Math.min(w, maxX - this.startPoint.getX()); h = dataArea.getHeight(); } else if (!hZoom) { x = dataArea.getMinX(); w = dataArea.getWidth(); h = Math.min(h, maxY - this.startPoint.getY()); } else { w = Math.min(w, maxX - this.startPoint.getX()); h = Math.min(h, maxY - this.startPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); boolean saved = p.isNotify(); p.setNotify(false); double pw0 = percentW(x, dataArea); double pw1 = percentW(x + w, dataArea); double ph0 = percentH(y, dataArea); double ph1 = percentH(y + h, dataArea); PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo(); if (z.getOrientation().isVertical()) { z.zoomDomainAxes(pw0, pw1, info, endPoint); z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint); } else { z.zoomRangeAxes(pw0, pw1, info, endPoint); z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint); } p.setNotify(saved); } } viewer.hideZoomRectangle(); this.startPoint = null; canvas.clearLiveHandler(); }
From source file:de.fhg.igd.mapviewer.BasicMapKit.java
/** * Zoom in and center on the given {@link GeoPosition}s * /*from w w w . j a v a2s. c o m*/ * @param positions the {@link GeoPosition}s */ public void zoomToPositions(Set<GeoPosition> positions) { if (positions.size() == 0) return; positions = equalizeEpsg(positions); int epsg = positions.iterator().next().getEpsgCode(); double minX = 0, maxX = 0, minY = 0, maxY = 0; boolean init = false; for (GeoPosition pos : positions) { if (!init) { // first pos minY = maxY = pos.getY(); minX = maxX = pos.getX(); init = true; } else { if (pos.getY() < minY) minY = pos.getY(); else if (pos.getY() > maxY) maxY = pos.getY(); if (pos.getX() < minX) minX = pos.getX(); else if (pos.getX() > maxX) maxX = pos.getX(); } } // center on positions setCenterPosition(new GeoPosition((minX + maxX) / 2.0, (minY + maxY) / 2.0, epsg)); // initial zoom int zoom = getMainMap().getTileFactory().getTileProvider().getMinimumZoom(); try { if (positions.size() >= 2) { int viewWidth = (int) getMainMap().getViewportBounds().getWidth(); int viewHeight = (int) getMainMap().getViewportBounds().getHeight(); Rectangle2D rect = generateBoundingRect(minX, minY, maxX, maxY, epsg, zoom); while ((viewWidth < rect.getWidth() || viewHeight < rect.getHeight()) && zoom < getMainMap().getTileFactory().getTileProvider().getMaximumZoom()) { zoom++; rect = generateBoundingRect(minX, minY, maxX, maxY, epsg, zoom); } } setZoom(zoom); } catch (IllegalGeoPositionException e) { log.warn("Error zooming to positions");// , e); //$NON-NLS-1$ } }
From source file:org.mwc.cmap.grideditor.chart.DataPointsDragTracker.java
public void chartMouseMoved(final ChartMouseEvent event) { if (!myDragSubject.isEmpty()) { myChartPanel.forgetZoomPoints(); // Rectangle clientArea = myChartPanel.getClientArea(); // int screenX = event.getTrigger().getX() - clientArea.x; // int screenY = event.getTrigger().getY() - clientArea.y; // [IM] don't bother with sorting out the client area offset // - we've stopped using it in the FixedChartComposite calling method final int screenX = event.getTrigger().getX(); final int screenY = event.getTrigger().getY(); // deliberately switch axes for following line, now that we've switched // the axes to put time // down the LH side. final Point2D point2d = new Point2D.Double(screenY, screenX); final XYPlot xyplot = myChartPanel.getChart().getXYPlot(); final ChartRenderingInfo renderingInfo = myChartPanel.getChartRenderingInfo(); Rectangle2D dataArea = renderingInfo.getPlotInfo().getDataArea(); // WORKAROUND: when the grid graph gets really wide, the labels on the // y-axis get stretched. // but, the dataArea value doesn't reflect this. // So, get the width values from the getScreenDataArea method - which // does reflect the scaling applied to the y axis. // - and all works well now. final Rectangle dataArea2 = myChartPanel.getScreenDataArea(); dataArea = new Rectangle2D.Double(dataArea2.x, dataArea.getY(), dataArea2.width, dataArea.getHeight()); final ValueAxis domainAxis = xyplot.getDomainAxis(); final RectangleEdge domainEdge = xyplot.getDomainAxisEdge(); final ValueAxis valueAxis = xyplot.getRangeAxis(); final RectangleEdge valueEdge = xyplot.getRangeAxisEdge(); double domainX = domainAxis.java2DToValue(point2d.getX(), dataArea, domainEdge); final double domainY = valueAxis.java2DToValue(point2d.getY(), dataArea, valueEdge); if (myAllowVerticalMovesOnly) { domainX = myDragSubject.getDraggedItem().getXValue(); }/*from www . j a v a 2 s. c o m*/ if (!myDragSubject.isEmpty()) myDragSubject.setProposedValues(domainX, domainY); myChartPanel.redrawCanvas(); } }