List of usage examples for org.jfree.data Range getLength
public double getLength()
From source file:apidemo.PanScrollZoomDemo.java
/** * Recalculates the scrollbar settings.//w ww . j a va 2 s . c om * * @param plot the plot. */ private void recalcScrollBar(final Plot plot) { if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis axis = hvp.getDomainAxis(); axis.setLowerMargin(0); axis.setUpperMargin(0); final Range rng = axis.getRange(); final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); final int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum(); if (rng.getLength() > 0) { this.scrollFactor = len / rng.getLength(); } final double dblow = rng.getLowerBound(); final int ilow = (int) (dblow * this.scrollFactor); scrollBarModel.setMinimum(ilow); final int val = ilow; scrollBarModel.setValue(val); final double dbup = rng.getUpperBound(); final int iup = (int) (dbup * this.scrollFactor); scrollBarModel.setMaximum(iup); final int ext = iup - ilow; scrollBarModel.setExtent(ext); scrollBarModel.addChangeListener(this); } }
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. ja va2 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:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Update the Domain Slider Crosshair./*from w ww .j a v a 2 s . c om*/ * * @param chartui * @param movingindex * @param domainstart * @param domainend * @param movingslidervalue * @param sliderminimum * @param slidermaximum * * @param debug * * @return double */ public static double updateDomainCrosshairForDomainSlider(final ChartUIComponentPlugin chartui, final int movingindex, final int domainstart, final int domainend, final int movingslidervalue, final int sliderminimum, final int slidermaximum, final boolean debug) { final String SOURCE = "ChartHelper.updateDomainCrosshairForDomainSlider() "; final double dblDomainCrosshairXYPlot; if ((chartui.getChartPanel() != null) && (chartui.getChartPanel().getChart() != null) && (chartui.getChartPanel().getChart().getPlot() != null)) { final double dblDomainCrosshair; final double dblPositionFraction; final XYPlot plot; final ValueAxis domainAxis; final Range range; plot = (XYPlot) chartui.getChartPanel().getChart().getPlot(); domainAxis = plot.getDomainAxis(); range = domainAxis.getRange(); if (movingindex == INDEX_LEFT) { // Trying to Move Left, but are we already at the Left Extent? if (movingslidervalue <= sliderminimum) { dblDomainCrosshair = sliderminimum; dblDomainCrosshairXYPlot = domainAxis.getLowerBound(); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "At Left Extent, cannot move Left Thumb to the Left" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } // It is Ok to move further Left than the current setting of domainstart, // but we musn't draw a crosshair else if (movingslidervalue < domainstart) { // Do not draw a crosshair, set to lower bound? dblDomainCrosshair = sliderminimum; dblDomainCrosshairXYPlot = domainAxis.getLowerBound(); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Moving Left Thumb to the Left beyond current DomainStart" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } else { // Try to Move Right, the slider won't be able to move past the Right Thumb dblDomainCrosshair = movingslidervalue; dblPositionFraction = (double) (movingslidervalue - domainstart) / (double) (domainend - domainstart); dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength()); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Moving Left Thumb to the Right" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } } else if (movingindex == INDEX_RIGHT) { // Trying to Move Right, but are we already at the Right Extent? if (movingslidervalue >= slidermaximum) { dblDomainCrosshair = slidermaximum; dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + range.getLength(); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "At Right Extent, cannot move Right Thumb to the Right" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } // It is Ok to move further Right than the current setting of domainend // but we musn't draw a crosshair else if (movingslidervalue > domainend) { // Do not draw a crosshair, set to upper bound? dblDomainCrosshair = slidermaximum; dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + range.getLength(); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Moving Right Thumb to the Right beyond current DomainEnd" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } else { // Try to Move Left, the slider won't be able to move past the Left Thumb dblDomainCrosshair = movingslidervalue; dblPositionFraction = (double) (movingslidervalue - domainstart) / (double) (domainend - domainstart); dblDomainCrosshairXYPlot = domainAxis.getLowerBound() + (dblPositionFraction * range.getLength()); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Moving Right Thumb to the Left" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } } else { // Do nothing, an Error dblDomainCrosshair = sliderminimum; dblDomainCrosshairXYPlot = domainAxis.getLowerBound(); FrameworkSingletons.LOGGER.debug(debug, SOURCE + "Invalid Thumb index" + " [crosshair.domain=" + dblDomainCrosshair + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } chartui.setDomainCrosshair(dblDomainCrosshair); plot.setDomainCrosshairValue(dblDomainCrosshairXYPlot); } else { chartui.setDomainCrosshair(sliderminimum); dblDomainCrosshairXYPlot = Double.MIN_VALUE; FrameworkSingletons.LOGGER.debug(debug, SOURCE + "There is no Chart, so cannot update Domain Slider Crosshair" + " [crosshair.domain=" + sliderminimum + "] [crosshair.xyplot" + dblDomainCrosshairXYPlot + "]"); } return (dblDomainCrosshairXYPlot); }
From source file:ru.spbspu.viewer.DataView.java
/** * ? ? //from w w w . j a va 2 s . co m */ public void buildOscillogram() { CategoryTableXYDataset serie = new CategoryTableXYDataset(); serie.setNotify(false); double step = 1.0 / getDiscretization(); double startPosition = step * getFramePosition(); double[] data = null; if (LPF.isSelected()) { data = _presenter.lpFilter(_presenter.getFrameData(getFramePosition(), getFrameWidth()), Double.parseDouble(spinnerLimitFreq.getValue().toString())); } else { data = _presenter.getFrameData(getFramePosition(), getFrameWidth()); } for (int i = 0; i < data.length; i++) { serie.add(startPosition, data[i], ""); startPosition += step; } JFreeChart chart = ChartFactory.createXYLineChart("", "t,c", "g, /c^2", serie); chart.removeLegend(); chart.setAntiAlias(false); XYPlot plot = chart.getXYPlot(); plot.setFixedRangeAxisSpace(GRAPHIC_SPACE); //plot.setRangeGridlinePaint(Color.BLACK); org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis(); Range range = _presenter.getMinMaxRange(); if (range.getLength() > 0) { yAxis.setRange(range); } org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis(); double start = getFramePosition() * 1.0 / getDiscretization(); double max = start + getFrameWidth() * 1.0 / getDiscretization(); xAxis.setRange(start, max); ChartPanel chartPanel = new ChartPanel(chart); drawGraphOfSignal(chartPanel); }
From source file:org.fhcrc.cpl.viewer.gui.MRMDialog.java
protected void createChartInPanelDaughterTasksOnly(XYPlot xyp) { XYSeries coloredDataset = transitionOnPlot.getCurrentDaughter().getGraphData(); Paint daughterColor = Utils.paleColor((Color) transitionOnPlot.getCurrentDaughter().getGraphColor()); ArrayList<XYLineAnnotation> coloredDaughters = new ArrayList<XYLineAnnotation>(); //Trace calculated elution curves over data spikes if (transitionOnPlot.getElutionCurves() != null && !transitionOnPlot.getElutionCurves().isEmpty()) { MRMDaughter curDaughter = transitionOnPlot.getCurrentDaughter(); ElutionCurveStrategy ecs = transitionOnPlot.getElutionCurves().get(curDaughter); //Is current daughter rejected? Boolean accepted = (Boolean) ((PeaksTableModel) peaksTable.getModel()).data[curDaughter .getElutionDataTableRow()][peaksData.Accept.colno]; if (accepted == null || !accepted) { xyp.setBackgroundPaint(new Color(255, 230, 230)); }/*from w ww. j a va 2 s. c o m*/ List<ElutionCurve> ecl = ecs.getDaughterCurves(); if (ecl != null) { for (ElutionCurve e : ecl) { List<Line2D.Double> ll2dd = e.getSegments(); for (Line2D.Double l2dd : ll2dd) { xyp.addAnnotation(Utils.line2Annotation(l2dd, new BasicStroke(2.0f), ecs.isBestDaughterCurve(e) ? Color.BLACK : Color.LIGHT_GRAY)); } } } } // If there is a valid "current" daughter draw the spikes in the daughter's color // as annotations (sensu JFree) if (coloredDataset != null) { int nOfPoints = coloredDataset.getItemCount(); for (int i = 0; i < (nOfPoints - 1); i++) { XYDataItem p1 = coloredDataset.getDataItem(i); XYDataItem p2 = coloredDataset.getDataItem(i + 1); coloredDaughters.add(new XYLineAnnotation(p1.getX().doubleValue(), p1.getY().doubleValue(), p2.getX().doubleValue(), p2.getY().doubleValue(), new BasicStroke(1.5f), transitionOnPlot.getCurrentDaughter().getGraphColor()) // new XYLineAnnotation(p1.getX().doubleValue(),p1.getY().doubleValue(),p2.getX().doubleValue(),p2.getY().doubleValue(),new BasicStroke(1.5f),daughterColor) ); } } if (_traceAllFragments) { for (MRMDaughter d : transitionOnPlot.getDaughters().values()) { if (d == transitionOnPlot.getCurrentDaughter()) continue; XYSeries curXYSeries = d.getContinDaughterData(); if (curXYSeries == null || curXYSeries.getItemCount() == 0) continue; if (d.getBestElutionCurve() == null) continue; int nOfPoints = curXYSeries.getItemCount(); for (int i = 0; i < (nOfPoints - 1); i++) { XYDataItem p1 = curXYSeries.getDataItem(i); XYDataItem p2 = curXYSeries.getDataItem(i + 1); coloredDaughters.add( // new XYLineAnnotation(p1.getX().doubleValue(),p1.getY().doubleValue(),p2.getX().doubleValue(),p2.getY().doubleValue(),new BasicStroke(1f),Utils.paleColor((Color)d.getGraphColor())) new XYLineAnnotation(p1.getX().doubleValue(), p1.getY().doubleValue(), p2.getX().doubleValue(), p2.getY().doubleValue(), new BasicStroke(1f), d.getGraphColor())); } } } if (coloredDaughters != null) { for (XYLineAnnotation xyla : coloredDaughters) { xyp.addAnnotation(xyla); } } coloredDaughters.clear(); //Display L or H label in upper left hand corner Range xRange = xyp.getDomainAxis().getRange(); Range yRange = xyp.getRangeAxis().getRange(); XYTextAnnotation lab = new XYTextAnnotation( (String) ((PeaksTableModel) peaksTable.getModel()).data[transitionOnPlot.getCurrentDaughter() .getElutionDataTableRow()][peaksData.Label.colno], xRange.getUpperBound() - (0.05 * xRange.getLength()), yRange.getUpperBound() - (0.05 * yRange.getLength())); lab.setFont(lab.getFont().deriveFont(Font.BOLD, 40.0F)); xyp.addAnnotation(lab); XYTextAnnotation midMarker = new XYTextAnnotation("\u25BC", ((MRMTransition) transitionOnPlot).getCalcXatMaxYAllDaughters(), ((MRMTransition) transitionOnPlot).getCalcMaxYAllDaughters()); midMarker.setPaint(Color.RED); midMarker.setFont(midMarker.getFont().deriveFont(Font.BOLD, 20F)); XYTextAnnotation midMarkerOutline = new XYTextAnnotation("\u25BC", ((MRMTransition) transitionOnPlot).getCalcXatMaxYAllDaughters(), ((MRMTransition) transitionOnPlot).getCalcMaxYAllDaughters()); midMarkerOutline.setPaint(Color.BLACK); midMarkerOutline.setFont(midMarker.getFont().deriveFont(Font.BOLD, 23F)); xyp.addAnnotation(midMarkerOutline); xyp.addAnnotation(midMarker); }