List of usage examples for org.jfree.chart.axis ValueAxis java2DToValue
public abstract double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge);
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 w w w . j a v a 2 s . c o m if (!myDragSubject.isEmpty()) myDragSubject.setProposedValues(domainX, domainY); myChartPanel.redrawCanvas(); } }
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * Translates mouse coordinates to chart coordinates (xy-axis) * //from ww w. j a v a 2 s .c o m * @param myChart * @param mouseX * @param mouseY * @return Range as chart coordinates (never null) */ public static Point2D mouseXYToPlotXY(ChartViewer myChart, int mouseX, int mouseY) { XYPlot plot = null; // find plot as parent of axis ChartEntity entity = findChartEntity(myChart.getCanvas(), mouseX, mouseY); if (entity instanceof AxisEntity) { Axis a = ((AxisEntity) entity).getAxis(); if (a.getPlot() instanceof XYPlot) plot = (XYPlot) a.getPlot(); } ChartRenderingInfo info = myChart.getRenderingInfo(); int subplot = info.getPlotInfo().getSubplotIndex(new Point2D.Double(mouseX, mouseY)); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); if (subplot != -1) dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea(); // find subplot or plot if (plot == null) plot = findXYSubplot(myChart.getChart(), info, mouseX, mouseY); // coordinates double cx = 0; double cy = 0; if (plot != null) { // find axis ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // parent? if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); domainAxis = pp.getDomainAxis(); domainAxisEdge = pp.getDomainAxisEdge(); } if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); rangeAxis = pp.getRangeAxis(); rangeAxisEdge = pp.getRangeAxisEdge(); } if (domainAxis != null) cx = domainAxis.java2DToValue(mouseX, dataArea, domainAxisEdge); if (rangeAxis != null) cy = rangeAxis.java2DToValue(mouseY, dataArea, rangeAxisEdge); } return new Point2D.Double(cx, cy); }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Translates mouse coordinates to chart coordinates (xy-axis) * //from w w w . j av a 2s. c om * @param myChart * @param mouseX * @param mouseY * @return Range as chart coordinates * @throws Exception */ public static Point2D mouseXYToPlotXY(ChartPanel myChart, int mouseX, int mouseY) throws Exception { Point2D p = myChart.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = null; // find plot as parent of axis ChartEntity entity = findChartEntity(myChart, mouseX, mouseY); if (entity instanceof AxisEntity) { Axis a = ((AxisEntity) entity).getAxis(); if (a.getPlot() instanceof XYPlot) plot = (XYPlot) a.getPlot(); } ChartRenderingInfo info = myChart.getChartRenderingInfo(); int subplot = info.getPlotInfo().getSubplotIndex(p); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); if (subplot != -1) dataArea = info.getPlotInfo().getSubplotInfo(subplot).getDataArea(); if (plot == null) plot = findXYSubplot(myChart.getChart(), info, p.getX(), p.getY()); // coordinates double cx = 0; double cy = 0; if (plot != null) { // find axis ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // parent? if (domainAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); domainAxis = pp.getDomainAxis(); domainAxisEdge = pp.getDomainAxisEdge(); } if (rangeAxis == null && plot.getParent() != null && plot.getParent() instanceof XYPlot) { XYPlot pp = ((XYPlot) plot.getParent()); rangeAxis = pp.getRangeAxis(); rangeAxisEdge = pp.getRangeAxisEdge(); } if (domainAxis != null) cx = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge); if (rangeAxis != null) cy = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge); } else { throw new Exception("no xyplot found"); } return new Point2D.Double(cx, cy); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
/** * Decreases the range on the horizontal axis, centered about a Java2D x coordinate. * <P>//from w ww.j a v a2s . c o m * The range on the x axis is multiplied by zoomFactor * * @param x the x coordinate in Java2D space. * @param zoomFactor the zoomFactor < 1 == zoom in; else out. */ private void zoomHorizontal(double x, double zoomFactor) { JFreeChart chart = this.chartPanel.getChart(); ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); if (chart.getPlot() instanceof XYPlot) { XYPlot hvp = (XYPlot) chart.getPlot(); ValueAxis axis = hvp.getDomainAxis(); if (axis != null) { double anchorValue = axis.java2DToValue((float) x, info.getPlotInfo().getDataArea(), hvp.getDomainAxisEdge()); if (zoomFactor < 1.0) { axis.resizeRange(zoomFactor, anchorValue); } else if (zoomFactor > 1.0) { Range range = hvp.getDataRange(axis); adjustRange(axis, range, zoomFactor, anchorValue); } } } }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
/** * Decreases the range on the vertical axis, centered about a Java2D y coordinate. * <P>/*from ww w. ja va2s. c om*/ * The range on the y axis is multiplied by zoomFactor * * @param y the y coordinate in Java2D space. * @param zoomFactor the zoomFactor < 1 == zoom in; else out. */ private void zoomVertical(double y, double zoomFactor) { JFreeChart chart = this.chartPanel.getChart(); ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); if (chart.getPlot() instanceof XYPlot) { XYPlot vvp = (XYPlot) chart.getPlot(); ValueAxis primYAxis = vvp.getRangeAxis(); if (primYAxis != null) { double anchorValue = primYAxis.java2DToValue((float) y, info.getPlotInfo().getDataArea(), vvp.getRangeAxisEdge()); if (zoomFactor < 1.0) { // zoom in primYAxis.resizeRange(zoomFactor, anchorValue); } else if (zoomFactor > 1.0) { // zoom out Range range = new Range(yMin, yMax); adjustRange(primYAxis, range, zoomFactor, anchorValue); } } } }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void mouseDragged(MouseEvent event) { try {/*from www . 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:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Updates the preselected y-value./* ww w .j av a 2 s . c o m*/ */ private void updateYFieldValue() { // update preselected y value because range axis has been changed if (mousePosition != null) { Rectangle2D plotArea = engine.getChartPanel().getScreenDataArea(); if (engine.getChartPanel().getChart().getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) engine.getChartPanel().getChart().getPlot(); // calculate y value for (int i = 0; i < plot.getRangeAxisCount(); i++) { ValueAxis config = plot.getRangeAxis(i); if (config != null && config.getLabel() != null) { if (config.getLabel() .equals(String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()))) { double chartY = config.java2DToValue(mousePosition.getY(), plotArea, plot.getRangeAxisEdge()); yField.setText(String.valueOf(chartY)); } } } } } }
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 ww w . ja v a 2 s. c o 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:pipeline.parameter_cell_views.FloatRangeSlider.java
/** * Translates MouseEvent screen coordinates to coordinates in chart units * /*from w w w .j a va 2 s .com*/ * @param e * MouseEvent containing coordinates of interest * @return Chart coordinates (evaluated as double) */ private @Nullable Point2D getChartCoordinates(MouseEvent e) { if (chartPanel.getChartRenderingInfo().getChartArea().getHeight() == 0) { Utils.log("Cannot translate to chart coordinates", LogLevel.DEBUG); return null; } int mouseX = e.getX(); int mouseY = e.getY(); Utils.log("x = " + mouseX + ", y = " + mouseY, LogLevel.DEBUG); Point2D p = chartPanel.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) chart.getPlot(); Rectangle2D plotArea = this.chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); double chartX = domainAxis.java2DToValue(p.getX(), plotArea, domainAxisEdge); double chartY = rangeAxis.java2DToValue(p.getY(), plotArea, rangeAxisEdge); return new Point2D.Double(chartX, chartY); }
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();/* w ww . jav a2 s .co 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()); }