List of usage examples for org.jfree.chart.plot XYPlot getDomainAxisEdge
public RectangleEdge getDomainAxisEdge()
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void mouseDragged(MouseEvent event) { try {/* w ww .j a v a2s.c o m*/ if (this.panStartPoint != null) { Rectangle2D scaledDataArea = this.chartPanel.getScaledDataArea(); this.panStartPoint = RefineryUtilities.getPointInRectangle(this.panStartPoint.getX(), this.panStartPoint.getY(), scaledDataArea); Point2D panEndPoint = RefineryUtilities.getPointInRectangle(event.getX(), event.getY(), scaledDataArea); // horizontal pan Plot plot = this.chartPanel.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot; ValueAxis xAxis = hvp.getDomainAxis(); if (xAxis != null) { double translatedStartPoint = xAxis.java2DToValue((float) panStartPoint.getX(), scaledDataArea, hvp.getDomainAxisEdge()); double translatedEndPoint = xAxis.java2DToValue((float) panEndPoint.getX(), scaledDataArea, hvp.getDomainAxisEdge()); double dX = translatedStartPoint - translatedEndPoint; double oldMin = xAxis.getLowerBound(); double newMin = oldMin + dX; double oldMax = xAxis.getUpperBound(); double newMax = oldMax + dX; // do not pan out of range if (newMin >= hvp.getDataRange(xAxis).getLowerBound() && newMax <= hvp.getDataRange(xAxis).getUpperBound()) { xAxis.setLowerBound(newMin); xAxis.setUpperBound(newMax); } } } // vertical pan (1. Y-Axis) if (plot instanceof XYPlot) { XYPlot vvp = (XYPlot) plot; ValueAxis yAxis = vvp.getRangeAxis(); if (yAxis != null) { double translatedStartPoint = yAxis.java2DToValue((float) panStartPoint.getY(), scaledDataArea, vvp.getRangeAxisEdge()); double translatedEndPoint = yAxis.java2DToValue((float) panEndPoint.getY(), scaledDataArea, vvp.getRangeAxisEdge()); double dY = translatedStartPoint - translatedEndPoint; double oldMin = yAxis.getLowerBound(); double newMin = oldMin + dY; double oldMax = yAxis.getUpperBound(); double newMax = oldMax + dY; // do not pan out of range if (newMin >= yMin && newMax <= yMax) { yAxis.setLowerBound(newMin); yAxis.setUpperBound(newMax); } } } // for the next time this.panStartPoint = panEndPoint; } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:nl.vu.nat.jfreechartcustom.XYBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device.//from ww w. j a va 2s. c o m * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { boolean bAddEntity = false; double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { z = ((XYZDataset) dataset).getZValue(series, item); } Paint p = this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { // Detect if Rectangle is smaller than 2 by 2 pixels block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setPaint(p); g2.fill(block); g2.setStroke(new BasicStroke(1.0f)); // g2.draw(block); EntityCollection entities = state.getEntityCollection(); if (entities != null && bAddEntity) { addEntity(entities, block, dataset, series, item, 0.0, 0.0); } }
From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java
/** * @see drawSecondaryPass// ww w . j a va2 s. c om */ private void drawFeedBackNode(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, // final int series, final int item, final ValueAxis domainAxis, final Rectangle2D dataArea, final ValueAxis rangeAxis, // final CrosshairState crosshairState, final EntityCollection entities) { // get the data point... final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item); final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); 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)) { g2.setPaint(getFeedbackNodePaint()); g2.fill(shape); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } drawFeedbackItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawYIntervalPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); }// ww w . j ava 2 s .co m IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null && line != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of an {@link XYPlot}, with a {@link NumberAxis} for the * domain axis, a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} to draw the data items. * // ww w . j ava2s . c o m * This method is copied from * {@link org.jfree.chart.ChartFactory#createBubbleChart(String, String, String, XYZDataset, PlotOrientation, boolean, boolean, boolean)} * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException(Messages.getString("TopChartFactory.argument")); //$NON-NLS-1$ } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS) { @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double transDomain = 0.0; double transRange = 0.0; double zero; // MOD scorreia +2L avoid points: minimal size of circle must be 1 // z = z * transX + 1; // ADD xqliu 2009-07-06 bug 8035 double zSize = getBubbleSize(z); // calculate the multiple of bubble's default size z = 0; // use bubble's default size // ~ switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero; transRange = transDomain; break; case SCALE_ON_RANGE_AXIS: zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); transDomain = transRange; break; default: double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1; transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); } transDomain = Math.abs(transDomain); transRange = Math.abs(transRange); // MODSCA 2008-11-27 enlarge ellipse by diag% of the total diagonal double diag = Math.sqrt(dataArea.getHeight() * dataArea.getHeight() + dataArea.getWidth() * dataArea.getWidth()); transDomain += diag / 100; transRange += diag / 100; Ellipse2D circle = null; // ADD xqliu 2009-07-06 bug 8035 transDomain *= zSize; transRange *= zSize; // ~ if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // add an entity if this info is being collected EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } } /** * DOC xqliu : calculate the size of bubble. for bug 8035 2009-07-06. * * @param z multiple of bubble's default size * @return */ private double getBubbleSize(double z) { if (z > 0 && z <= 10) { return 2; } else if (z > 10 && z <= 100) { return 3; } else if (z > 100) { return 4; } return 1; } }; if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java
public void handleContextMenuShowing(ContextMenuEvent event) { // Calculate the m/z value of the clicked point final double clickedX = event.getX(); XYPlot plot = chartNode.getChart().getXYPlot(); Rectangle2D chartArea = chartNode.getRenderingInfo().getPlotInfo().getDataArea(); RectangleEdge axisEdge = plot.getDomainAxisEdge(); ValueAxis domainAxis = plot.getDomainAxis(); final double clickedMz = domainAxis.java2DToValue(clickedX, chartArea, axisEdge); final double clickedMzWithShift = Math.abs(clickedMz - mzShift.get()); // Update the m/z shift menu item DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); setToMenuItem.setText("Set to " + mzFormat.format(clickedMz) + " m/z"); setToMenuItem.setUserData(clickedMz); // Update the Show XIC menu item showXICMenuItem.setText("Show XIC of " + mzFormat.format(clickedMzWithShift) + " m/z"); showXICMenuItem.setUserData(clickedMzWithShift); // Update the MS/MS menu findMSMSMenu.setText("Find MS/MS of " + mzFormat.format(clickedMzWithShift) + " m/z"); final ObservableList<MenuItem> msmsItems = findMSMSMenu.getItems(); msmsItems.clear();// www.j av a 2s. c o m MZmineProject project = MZmineCore.getCurrentProject(); for (RawDataFile file : project.getRawDataFiles()) { scans: for (MsScan scan : file.getScans()) { if (scan.getMsFunction().getMsLevel() == 1) continue; for (IsolationInfo isolation : scan.getIsolations()) { if (!isolation.getIsolationMzRange().contains(clickedMzWithShift)) continue; String menuLabel = MsScanUtils.createSingleLineMsScanDescription(scan, isolation); MenuItem msmsItem = new MenuItem(menuLabel); msmsItem.setOnAction(e -> MsSpectrumPlotModule.showNewSpectrumWindow(scan)); msmsItems.add(msmsItem); continue scans; } } } if (msmsItems.isEmpty()) { MenuItem noneItem = new MenuItem("None"); noneItem.setDisable(true); msmsItems.add(noneItem); } // Update the Remove... menu final ObservableList<MenuItem> rmItems = removeDatasetMenu.getItems(); rmItems.clear(); for (MsSpectrumDataSet dataset : datasets) { MenuItem msmsItem = new MenuItem(dataset.getName()); msmsItem.setOnAction(e -> datasets.remove(dataset)); rmItems.add(msmsItem); } removeDatasetMenu.setDisable(rmItems.isEmpty()); }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private Point2D.Double _getPointForCandlestick(int plotIndex, int seriesIndex, int dataIndex) { final ChartPanel chartPanel = this.chartJDialog.getChartPanel(); final XYPlot plot = this.chartJDialog.getPlot(plotIndex); final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final org.jfree.data.xy.DefaultHighLowDataset defaultHighLowDataset = (org.jfree.data.xy.DefaultHighLowDataset) plot .getDataset(seriesIndex);// w w w .j a v a2 s . c om if (dataIndex >= defaultHighLowDataset.getItemCount(0)) { /* Not ready yet. */ return null; } final double xValue = defaultHighLowDataset.getXDate(0, dataIndex).getTime(); final double yValue = defaultHighLowDataset.getCloseValue(0, dataIndex); final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(plotIndex) .getDataArea(); final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge); // Use Double version, to avoid from losing precision. return new Point2D.Double(xJava2D, yJava2D); }
From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java
public void initChart(boolean usePhysicalPosition) { //<editor-fold defaultstate="expanded" desc="PLOT DEFAULTS"> this.threshold = Config.getSingleton().getDouble(GenericReportGenerator.PLOT_MANHATTAN_THRESHOLD_CONFIG, GenericReportGenerator.PLOT_MANHATTAN_THRESHOLD_DEFAULT); this.manhattan_back = Config.getSingleton().getColor( GenericReportGenerator.PLOT_MANHATTAN_BACKGROUND_CONFIG, GenericReportGenerator.PLOT_MANHATTAN_BACKGROUND_DEFAULT); this.manhattan_dot = Config.getSingleton().getColor(GenericReportGenerator.PLOT_MANHATTAN_MAIN_CONFIG, GenericReportGenerator.PLOT_MANHATTAN_MAIN_DEFAULT); //</editor-fold> final MarkerKey toUseMarkerKey; final long toUseRequestedPosWindow; if (usePhysicalPosition) { toUseMarkerKey = null;/*from w w w. ja va2 s . co m*/ toUseRequestedPosWindow = requestedPosWindow; } else { toUseMarkerKey = origMarkerKey; toUseRequestedPosWindow = requestedSetSize; // XXX should this be requestedPosWindow instead? } initXYDataset = GenericReportGenerator.getManhattanZoomByChrAndPos(this, testOpKey, origChr, toUseMarkerKey, startPhysPos, toUseRequestedPosWindow); zoomChart = createChart(initXYDataset, currentChr); zoomPanel = new ChartPanel(zoomChart); zoomPanel.setInitialDelay(10); zoomPanel.setDismissDelay(5000); zoomPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { int mouseX = event.getTrigger().getX(); int mouseY = event.getTrigger().getY(); final Point2D point = zoomPanel.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) zoomChart.getPlot(); ChartRenderingInfo info = zoomPanel.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); long chartX = (long) domainAxis.java2DToValue(point.getX(), dataArea, domainAxisEdge); // ValueAxis rangeAxis = plot.getRangeAxis(); // RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // double chartY = rangeAxis.java2DToValue(p.getY(), dataArea, // rangeAxisEdge); try { if (LinksExternalResouces.checkIfRsNecessary(cmb_SearchDB.getSelectedIndex())) { // THE SELECTED EXTERNAL RESOURCE NEEDS RSID INFO String tooltip = zoomPanel.getToolTipText(event.getTrigger()); if (tooltip == null || tooltip.isEmpty()) { // CHECK IF THERE IS AN RSID Dialogs.showWarningDialogue(Text.Reports.warnExternalResource); } else { String rsId = tooltip.substring(6, tooltip.indexOf('<', 6)); URLInDefaultBrowser.browseGenericURL(LinksExternalResouces.getResourceLink( cmb_SearchDB.getSelectedIndex(), currentChr, // chr rsId, // rsId chartX) // pos ); } } else { // THE SELECTED EXTERNAL RESOURCE ONLY NEEDS CHR+POS INFO URLInDefaultBrowser.browseGenericURL( LinksExternalResouces.getResourceLink(cmb_SearchDB.getSelectedIndex(), currentChr, // chr "", // rsId chartX) // pos ); } // URLInDefaultBrowser.browseGenericURL(LinkEnsemblUrl.getHomoSapiensLink(currentChr, (int) chartX)); } catch (IOException ex) { log.error(Text.Reports.cannotOpenEnsembl, ex); } } /** * Receives chart mouse moved events. * * @param event the event. */ @Override public void chartMouseMoved(ChartMouseEvent event) { // ignore } }); initGUI(); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java
/** * Translates the shape so that it displays correctly given the plot and dataArea. * * @param shape the shape to translate * @param plot the plot that will be used to translate the shape * @param dataArea the dataArea that the shape will be translated to * @return The translated shape *//*from www . jav a2 s .c o m*/ @SuppressWarnings({ "SuspiciousNameCombination" }) protected Ellipse2D.Double translateShape(Ellipse2D.Double shape, XYPlot plot, Rectangle2D dataArea) { Ellipse2D.Double circle = null; //double x = shape.getCenterX(); //double y = shape.getCenterY(); double z = shape.getWidth(); PlotOrientation orientation = plot.getOrientation(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(shape.getX(), dataArea, domainAxisLocation); double transX2 = domainAxis.valueToJava2D(shape.getX() + shape.getWidth(), dataArea, domainAxisLocation); //The upper-left corner is the lower-left on the graph (screen origin vs. graph origin) double transY1 = rangeAxis.valueToJava2D(shape.getY() + shape.getHeight(), dataArea, rangeAxisLocation); double transY2 = rangeAxis.valueToJava2D(shape.getY(), dataArea, rangeAxisLocation); double width = z * domainAxis.getRange().getLength() * domainZoomMultiplier * SIZE_MULTIPLIER; double height = z * rangeAxis.getRange().getLength() * rangeZoomMultiplier * SIZE_MULTIPLIER; double transWidth = domainAxis.lengthToJava2D(width, dataArea, domainAxisLocation);//transX2 - transX1; double transHeight = rangeAxis.lengthToJava2D(height, dataArea, rangeAxisLocation);//transY2 - transY1; double transX = (transX1 + transX2) / 2.0; double transY = (transY1 + transY2) / 2.0; switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: transHeight = transWidth; break; case SCALE_ON_RANGE_AXIS: transWidth = transHeight; break; default: break; } transWidth = Math.abs(transWidth); transHeight = Math.abs(transHeight); if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - transWidth / 2.0, transY - transHeight / 2.0, transWidth, transHeight); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - transHeight / 2.0, transX - transWidth / 2.0, transHeight, transWidth); } return circle; }
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 ww w . j av a2 s .co m*/ if (!myDragSubject.isEmpty()) myDragSubject.setProposedValues(domainX, domainY); myChartPanel.redrawCanvas(); } }