List of usage examples for org.jfree.data Range Range
public Range(double lower, double upper)
From source file:org.jfree.data.time.TimeTableXYDataset.java
/** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that controls whether or not the * x-intervals are taken into account. * * @return The range.//from ww w. j a va 2 s . com */ @Override public Range getDomainBounds(boolean includeInterval) { List keys = this.values.getRowKeys(); if (keys.isEmpty()) { return null; } TimePeriod first = (TimePeriod) keys.get(0); TimePeriod last = (TimePeriod) keys.get(keys.size() - 1); if (!includeInterval || this.domainIsPointsInTime) { return new Range(getXValue(first), getXValue(last)); } else { return new Range(first.getStart().getTime(), last.getEnd().getTime()); } }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The range (or <code>null</code> if the dataset contains no * values).//w w w .j a v a 2 s . co m */ @Override public Range getDomainBounds(boolean includeInterval) { if (includeInterval) { return this.intervalDelegate.getDomainBounds(includeInterval); } else { double lower = Double.POSITIVE_INFINITY; double upper = Double.NEGATIVE_INFINITY; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double minX = series.getMinX(); if (!Double.isNaN(minX)) { lower = Math.min(lower, minX); } double maxX = series.getMaxX(); if (!Double.isNaN(maxX)) { upper = Math.max(upper, maxX); } } if (lower > upper) { return null; } else { return new Range(lower, upper); } } }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * /* w w w. ja va 2 s. com*/ * @param myChart * @return Range the domainAxis zoom (X-axis) */ public static Range getZoomDomainAxis(ChartPanel myChart) { XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ValueAxis domainAxis = plot.getDomainAxis(); return new Range(domainAxis.getLowerBound(), domainAxis.getUpperBound()); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void updateChart() { // auto zoom// w ww . j a va2s . com if (theDocument.getNoScans() > 0) { Range mz_range = thePlot.getDomainAxis().getRange(); // update data double mz_toll = screenToDataX(1.); double[][] data = theDocument.getPeakDataAt(current_ind).getData(mz_range, mz_toll); // update visible data and compute intensity range visibleData.clear(); double min_int = (data[0].length > 0) ? data[1][0] : 0.; double max_int = (data[0].length > 0) ? data[1][0] : 0.; for (int i = 0; i < data[0].length; i++) { min_int = Math.min(min_int, data[1][i]); max_int = Math.max(max_int, data[1][i]); visibleData.put(data[0][i], data[1][i]); } //Range new_int_range = new Range(min_int,max_int); Range new_int_range = new Range(0., max_int); // make space for annotations Rectangle2D data_area = theChartPanel.getScreenDataArea(); if (data_area.getHeight() > 0) new_int_range = Range.expand(new_int_range, 0., 12. / data_area.getHeight()); // resize y axis thePlot.getRangeAxis().setRange(new_int_range); // reload dataset //theDataset.removeSeries("intensities"); theDataset.addSeries("intensities", data); /* for( int i=0; i<theDataset.getSeriesCount(); i++ ) { if( theDataset.getSeriesKey(i).equals("intensities") ) thePlot.getRenderer().setSeriesPaint(i,Color.red); else thePlot.getRenderer().setSeriesPaint(i,Color.blue); } */ } else { thePlot.getRangeAxis().setRange(new Range(0., 1.)); for (int i = 0; i < theDataset.getSeriesCount(); i++) theDataset.removeSeries(theDataset.getSeriesKey(i)); } // restore annotation shapes showSelection(); }
From source file:userinterface.graph.PrismLogarithmicAxis.java
/** * Adjusts the axis range to match the data range that the axis is * required to display.//from w w w.j a v a 2 s. c o m */ protected void autoAdjustRange() { Plot plot = getPlot(); if (plot == null) { return; // no plot, no data } if (plot instanceof ValueAxisPlot) { ValueAxisPlot vap = (ValueAxisPlot) plot; Range r = vap.getDataRange(this); if (r == null) { r = getDefaultAutoRange(); } double upper = r.getUpperBound(); double lower = r.getLowerBound(); double range = upper - lower; // if fixed auto range, then derive lower bound... double fixedAutoRange = getFixedAutoRange(); if (fixedAutoRange > 0.0) { lower = Math.max(upper - fixedAutoRange, this.smallestValue); } else { // ensure the autorange is at least <minRange> in size... double minRange = getAutoRangeMinimumSize(); if (range < minRange) { double expand = (minRange - range) / 2; upper = upper + expand; lower = lower - expand; } // apply the margins - these should apply to the exponent range //upper = upper + getUpperMargin() * range; //lower = lower - getLowerMargin() * range; } setRange(new Range(lower, upper), false, false); } }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java
/** * Creates a scatter plot that visualizes the given data collection. * //from www .jav a 2 s . c o m * @param aCollection * Data to be visualized. * @param aGeneral * General visual settings to be applied. * @param aAxes * Axis-related visual settings to be applied. * @param aGrid * Grid-related visual settings to be applied. * @param aScatter * Point-related visual settings to be applied. * @return Newly created chart control. */ private static JFreeChart createScatter(XYSeriesCollection aCollection, GeneralVisSettings aGeneral, AxesSettings aAxes, GridSettings aGrid, ScatterSettings aScatter) { JFreeChart chart = ChartFactory.createScatterPlot(null, // title convertLabel(aAxes.getDomainAxisLabel()), // label of X axis convertLabel(aAxes.getRangeAxisLabel()), // label of Y axis aCollection, // dataset PlotOrientation.VERTICAL, // orientation false, // create legend true, // display tooltips false); // generate urls XYPlot plot = chart.getXYPlot(); Range domainDataRange = aAxes.getLogarithmicDomainAxis() ? new Range(logLowerBound(plot.getDataset(), true), plot.getDataRange(plot.getDomainAxis()).getUpperBound()) : plot.getDataRange(plot.getDomainAxis()); Range rangeDataRange = aAxes.getLogarithmicRangeAxis() ? new Range(logLowerBound(plot.getDataset(), false), plot.getDataRange(plot.getRangeAxis()).getUpperBound()) : plot.getDataRange(plot.getRangeAxis()); updateGeneral(plot, aGeneral); updateAxes(plot, aAxes, aGrid, domainDataRange, rangeDataRange); updateScatter(plot, aScatter); chart.setBackgroundPaint(null); return chart; }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset.java
/** * Returns the range of the values in this dataset's range. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range./* w w w .j a v a 2 s . c o m*/ */ @Override public Range getRangeBounds(boolean includeInterval) { return new Range(this.minimumRangeValue, this.maximumRangeValue); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java
private void onMouseDragged(MouseEvent e) { if (mouse_start_point != null) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); double acc_delta = screenToDataY(e.getPoint().getY() - mouse_start_point.getY()); // update mz if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = old_upper_bound + mz_delta; double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = old_lower_bound + mz_delta; double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }/*from w w w . j a v a 2s . c o m*/ // update acc if (acc_delta > 0.) { double old_upper_bound = thePlot.getRangeAxis().getUpperBound(); double old_lower_bound = thePlot.getRangeAxis().getLowerBound(); double new_upper_bound = old_upper_bound + acc_delta; double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getRangeAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getRangeAxis().getUpperBound(); double old_lower_bound = thePlot.getRangeAxis().getLowerBound(); double new_lower_bound = old_lower_bound + acc_delta; double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getRangeAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } mouse_start_point = e.getPoint(); } } }
From source file:asl.util.PlotMaker.java
public void plotSpecAmp2(double freq[], double[] amp1, double[] phase1, double[] amp2, double[] phase2, String plotTitle, String pngName) { /**//from w w w. jav a 2s . co m final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR) ,station, channel, plotString); final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR) ,station, channel, plotString); **/ File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotSpecAmp: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } // Plot x-axis (frequency) range final double XMIN = .00009; final double XMAX = freq[freq.length - 1]; System.out.format("== plotSpecAmp2: nfreq=%d npts=%d pngName=%s\n", freq.length, amp2.length, pngName); final XYSeries series1 = new XYSeries("Amp_PZ"); final XYSeries series1b = new XYSeries("Amp_Cal"); final XYSeries series2 = new XYSeries("Phase_PZ"); final XYSeries series2b = new XYSeries("Phase_Cal"); double maxdB = 0.; for (int k = 0; k < freq.length; k++) { double dB = amp1[k]; //double dB = 20. * Math.log10( amp1[k] ); //series1.add( freq[k], dB ); //series1.add( freq[k], 20. * Math.log10( amp1[k] ) ); //series1b.add(freq[k], 20. * Math.log10( amp2[k] )); series1.add(freq[k], amp1[k]); series1b.add(freq[k], amp2[k]); series2.add(freq[k], phase1[k]); series2b.add(freq[k], phase2[k]); if (dB > maxdB) { maxdB = dB; } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); //renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); Paint[] paints = new Paint[] { Color.red, Color.blue }; renderer.setSeriesPaint(0, paints[0]); //renderer.setSeriesPaint(1, paints[1]); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesPaint(0, paints[1]); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesLinesVisible(0, true); // Stroke is part of Java Swing ... //renderer2.setBaseStroke( new Stroke( ... ) ); double ymax; if (maxdB < 10) { ymax = 10.; } else { ymax = maxdB + 2; ; } final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)"); verticalAxis.setRange(new Range(-40, ymax)); verticalAxis.setTickUnit(new NumberTickUnit(5)); //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response"); //verticalAxis.setRange( new Range(0.01 , 10) ); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)"); //horizontalAxis.setRange( new Range(0.0001 , 100.5) ); //horizontalAxis.setRange( new Range(0.00009 , 110) ); horizontalAxis.setRange(new Range(XMIN, XMAX)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series1b); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer); //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)"); phaseAxis.setRange(new Range(-180, 180)); phaseAxis.setTickUnit(new NumberTickUnit(30)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series2); seriesCollection2.addSeries(series2b); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot, 1); combinedPlot.add(xyplot2, 1); combinedPlot.setGap(15.); //final JFreeChart chart = new JFreeChart(xyplot); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
/** * Add normal bars in to the chart/*from ww w . j a v a 2 s .co m*/ * * @param dataset * The dataset to visualise * @param title * @param color * @param margin * Define the space between two bars */ public void addBarChart(XYDataset dataset, String title, Color color, double margin, double maxValue) { if (dataset.getItemCount(0) > 0) { XYBarRenderer renderer = new XYBarRenderer(margin); renderer.setSeriesPaint(0, color); renderer.setShadowVisible(false); renderer.setBaseItemLabelsVisible(false); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setSeriesVisibleInLegend(0, false); renderer.setDrawBarOutline(true); plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex); plot.setDataset(plotIndex, dataset); plot.setRenderer(plotIndex, renderer); if (!title.equals("")) { // if title is not null then show the legend and label of the // bar NumberAxis numberAxis = new NumberAxis(title); numberAxis.setLowerMargin(LOWER_PLOT_MARGIN); double maxRange = calculateRangeMax(maxValue); numberAxis.setRangeWithMargins(new Range(0, maxRange), true, true); numberAxis.setLabelPaint(color); numberAxis.setTickLabelPaint(color); plot.setRangeAxis(rangeAxisIndex, numberAxis); } plotIndex++; rangeAxisIndex++; } }