List of usage examples for org.jfree.data.general DatasetUtilities findDomainBounds
public static Range findDomainBounds(XYDataset dataset)
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
/** * Creates new form Chromatogram2DViewerPanel *//*from w w w . ja v a2 s. c om*/ public Chromatogram1DHeatmapViewerPanel(InstanceContent topComponentInstanceContent, Lookup tcLookup, ADataset2D<IChromatogram1D, IScan> ds) { initComponents(); this.content = topComponentInstanceContent; this.lookup = tcLookup; chart = new JFreeChart(new XYPlot()); chartPanel = new ContextAwareChartPanel(chart, true, true, true, true, true); Cursor crosshairCursor = new Cursor(Cursor.CROSSHAIR_CURSOR); chartPanel.setCursor(crosshairCursor); // chart.addProgressListener(cdxpanel); chartPanel.setInitialDelay(100); chartPanel.setDismissDelay(30000); chartPanel.setReshowDelay(0); chartPanel.setFocusable(true); jPanel2.add(chartPanel, BorderLayout.CENTER); content.add(chartPanel); addKeyListener(this); dataRange = DatasetUtilities.findDomainBounds(ds); }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DViewPanel.java
public void setPlot(final XYPlot plot) { removeAxisListener();/*from w w w.j a v a2s.c o m*/ ADataset1D<?, IScan> dataset = null; if (plot.getDataset() instanceof ADataset1D) { dataset = (ADataset1D<?, IScan>) plot.getDataset(); } else { throw new IllegalArgumentException("Requires a plot with ADataset1D!"); } this.plot = plot; if (selectionOverlay != null) { content.remove(selectionOverlay); selectionOverlay = null; } if (selectionOverlay == null) { selectionOverlay = new SelectionOverlay(Color.BLUE, Color.RED, 1.75f, 1.75f, 0.66f); chartPanel.addOverlay(selectionOverlay); selectionOverlay.addChangeListener(chartPanel); content.add(selectionOverlay); } else { for (ISelection selection : selectionOverlay.getMouseClickSelection()) { selection.setDataset(dataset); } ISelection selection = selectionOverlay.getMouseHoverSelection(); if (selection != null) { selection.setDataset(dataset); } } if (selectionHandler == null) { selectionHandler = new InstanceContentSelectionHandler(this.content, selectionOverlay, InstanceContentSelectionHandler.Mode.ON_CLICK, dataset, 1); } else { selectionHandler.setDataset(dataset); } if (mouseSelectionHandler == null) { mouseSelectionHandler = new XYMouseSelectionHandler<>(dataset); mouseSelectionHandler.addSelectionChangeListener(selectionOverlay); mouseSelectionHandler.addSelectionChangeListener(selectionHandler); chartPanel.addChartMouseListener(mouseSelectionHandler); } else { mouseSelectionHandler.setDataset(dataset); } AxisChangeListener listener = selectionOverlay; ValueAxis domain = this.plot.getDomainAxis(); ValueAxis range = this.plot.getRangeAxis(); if (domain != null) { domain.addChangeListener(listener); } if (range != null) { range.addChangeListener(listener); } this.plot.setNoDataMessage("Loading Data..."); this.plot.setDomainPannable(true); this.plot.setRangePannable(true); chart = new JFreeChart(this.plot); chartPanel.setChart(chart); XYItemRenderer r = this.plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { ((XYLineAndShapeRenderer) r).setDrawSeriesLineAsPath(true); ((XYLineAndShapeRenderer) r).setBaseShapesVisible(false); ((XYLineAndShapeRenderer) r).setBaseShapesFilled(true); } else if (r instanceof XYAreaRenderer) { ((XYAreaRenderer) r).setOutline(true); ((XYAreaRenderer) r).setBaseCreateEntities(true, false); } else if (r instanceof EntityAwareSamplingXYLineRenderer) { ((EntityAwareSamplingXYLineRenderer) r).setBaseCreateEntities(true, false); } ChartCustomizer.setSeriesColors(this.plot, 0.8f); ChartCustomizer.setSeriesStrokes(this.plot, 2.0f); dmkl = new DomainMarkerKeyListener(this.plot); dmkl.setPlot(this.plot); chartPanel.addKeyListener(dmkl); addAxisListener(); //add available chart overlays ArrayList<? extends Overlay> overlays = new ArrayList<>(getLookup().lookupAll(Overlay.class)); Collections.sort(overlays, new Comparator<Overlay>() { @Override public int compare(Overlay o1, Overlay o2) { if (o1 instanceof ChartOverlay && o2 instanceof ChartOverlay) { ChartOverlay co1 = (ChartOverlay) o1; ChartOverlay co2 = (ChartOverlay) o2; return Integer.compare(co1.getLayerPosition(), co2.getLayerPosition()); } else { return 0; } } }); for (Overlay overlay : overlays) { if (!(overlay instanceof SelectionOverlay)) { chartPanel.removeOverlay(overlay); if (overlay instanceof AxisChangeListener) { AxisChangeListener axisChangeListener = (AxisChangeListener) overlay; if (domain != null) { domain.addChangeListener(axisChangeListener); } if (range != null) { range.addChangeListener(axisChangeListener); } } if (overlay instanceof ISelectionChangeListener) { ISelectionChangeListener isl = (ISelectionChangeListener) overlay; mouseSelectionHandler.addSelectionChangeListener(isl); mouseSelectionHandler.addSelectionChangeListener(selectionHandler); selectionOverlay.addChangeListener(chartPanel); } chartPanel.addOverlay(overlay); overlay.addChangeListener(chartPanel); } } //add selection overlay last chartPanel.removeOverlay(selectionOverlay); chartPanel.addOverlay(selectionOverlay); if (range != null) { range.setAutoRange(true); range.setDefaultAutoRange(DatasetUtilities.findRangeBounds(dataset)); } if (domain != null) { domain.setAutoRange(true); domain.setDefaultAutoRange(DatasetUtilities.findDomainBounds(dataset)); } }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
private void setViewPortAround(final double value) { Runnable r = new Runnable() { @Override/*w w w .j a v a2 s .c o m*/ public void run() { double value2 = value / 100.0d; System.out.println("ViewPort around " + value2); Range dataDomainBounds = DatasetUtilities .findDomainBounds(chartPanel.getChart().getXYPlot().getDataset()); ValueAxis domainAxis = chartPanel.getChart().getXYPlot().getDomainAxis(); double lowerBound = Math.max(dataDomainBounds.getLowerBound(), dataDomainBounds.getLowerBound() + (value / 99.0d * dataDomainBounds.getLength())); double upperBound = Math.min(dataDomainBounds.getUpperBound(), dataDomainBounds.getLowerBound() + ((value + 10.0d) / 99.0d * dataDomainBounds.getLength())); domainAxis.setRange(lowerBound, upperBound); } }; SwingUtilities.invokeLater(r); }
From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java
public void setPlot(final XYPlot plot) { removeAxisListener();/* w w w .j a v a 2s .com*/ ADataset2D dataset = null; if (plot.getDataset() instanceof ADataset2D) { dataset = (ADataset2D) plot.getDataset(); } else { throw new IllegalArgumentException("Requires a plot with ADataset2D!"); } this.plot = plot; if (this.selectionOverlay != null) { this.content.remove(selectionOverlay); this.selectionOverlay = null; } if (selectionOverlay == null) { selectionOverlay = new SelectionOverlay(Color.BLUE, Color.RED, 1.75f, 1.75f, 0.66f); chartPanel.addOverlay(selectionOverlay); selectionOverlay.addChangeListener(chartPanel); this.content.add(selectionOverlay); } else { for (ISelection selection : selectionOverlay.getMouseClickSelection()) { selection.setDataset(dataset); } ISelection selection = selectionOverlay.getMouseHoverSelection(); if (selection != null) { selection.setDataset(dataset); } } if (selectionHandler == null) { selectionHandler = new InstanceContentSelectionHandler(this.content, selectionOverlay, InstanceContentSelectionHandler.Mode.valueOf((String) modeSpinner.getValue()), dataset, 1); } else { selectionHandler.setDataset(dataset); } if (mouseSelectionHandler == null) { mouseSelectionHandler = new XYMouseSelectionHandler<>(dataset); mouseSelectionHandler.addSelectionChangeListener(selectionOverlay); mouseSelectionHandler.addSelectionChangeListener(selectionHandler); chartPanel.addChartMouseListener(mouseSelectionHandler); } else { mouseSelectionHandler.setDataset(dataset); } XYItemRenderer xyir = plot.getRenderer(); if (xyir instanceof XYBlockRenderer) { XYBlockRenderer xybr = (XYBlockRenderer) xyir; boxWidthSpinner.setValue(xybr.getBlockWidth()); boxHeightSpinner.setValue(xybr.getBlockHeight()); } AxisChangeListener listener = selectionOverlay; ValueAxis domain = this.plot.getDomainAxis(); ValueAxis range = this.plot.getRangeAxis(); if (domain != null) { domain.addChangeListener(listener); } if (range != null) { range.addChangeListener(listener); } this.plot.setNoDataMessage("Loading Data..."); chart = new JFreeChart(this.plot); chartPanel.setChart(chart); // dmkl = new DomainMarkerKeyListener( // this.plot); // dmkl.setPlot(this.plot); // chartPanel.addKeyListener(dmkl); addAxisListener(); //add available chart overlays ArrayList<? extends Overlay> overlays = new ArrayList<>(getLookup().lookupAll(Overlay.class)); Collections.sort(overlays, new Comparator<Overlay>() { @Override public int compare(Overlay o1, Overlay o2) { if (o1 instanceof ChartOverlay && o2 instanceof ChartOverlay) { ChartOverlay co1 = (ChartOverlay) o1; ChartOverlay co2 = (ChartOverlay) o2; return Integer.compare(co1.getLayerPosition(), co2.getLayerPosition()); } else { return 0; } } }); for (Overlay overlay : overlays) { if (!(overlay instanceof SelectionOverlay)) { chartPanel.removeOverlay(overlay); if (overlay instanceof AxisChangeListener) { AxisChangeListener axisChangeListener = (AxisChangeListener) overlay; if (domain != null) { domain.addChangeListener(axisChangeListener); } if (range != null) { range.addChangeListener(axisChangeListener); } } if (overlay instanceof ISelectionChangeListener) { ISelectionChangeListener isl = (ISelectionChangeListener) overlay; mouseSelectionHandler.addSelectionChangeListener(isl); mouseSelectionHandler.addSelectionChangeListener(selectionHandler); selectionOverlay.addChangeListener(chartPanel); } chartPanel.addOverlay(overlay); overlay.addChangeListener(chartPanel); } } //add selection overlay last chartPanel.removeOverlay(selectionOverlay); chartPanel.addOverlay(selectionOverlay); if (range != null) { range.setAutoRange(true); range.setDefaultAutoRange(DatasetUtilities.findRangeBounds(dataset)); } if (domain != null) { domain.setAutoRange(true); domain.setDefaultAutoRange(DatasetUtilities.findDomainBounds(dataset)); } }
From source file:ucar.unidata.idv.control.chart.MyXYPlot.java
/** * Returns the range for the specified axis. * * @param axis the axis./* w ww . ja v a 2s .c om*/ * * @return The range. */ public Range getDataRange(ValueAxis axis) { Range result = null; List mappedDatasets = new ArrayList(); boolean isDomainAxis = true; // is it a domain axis? int domainIndex = getDomainAxisIndex(axis); if (domainIndex >= 0) { isDomainAxis = true; mappedDatasets.addAll(getDatasetsMappedToDomainAxis(new Integer(domainIndex))); } // or is it a range axis? int rangeIndex = getRangeAxisIndex(axis); if (rangeIndex >= 0) { isDomainAxis = false; mappedDatasets.addAll(getDatasetsMappedToRangeAxis(new Integer(rangeIndex))); } // iterate through the datasets that map to the axis and get the union // of the ranges. Iterator iterator = mappedDatasets.iterator(); while (iterator.hasNext()) { XYDataset d = (XYDataset) iterator.next(); if (d != null) { XYItemRenderer r = getRendererForDataset(d); if (isDomainAxis) { if (r != null) { result = Range.combine(result, r.findDomainBounds(d)); } else { result = Range.combine(result, DatasetUtilities.findDomainBounds(d)); } } else { if (r != null) { result = Range.combine(result, r.findRangeBounds(d)); } else { result = Range.combine(result, DatasetUtilities.findRangeBounds(d)); } } } } return result; }