List of usage examples for org.jfree.data Range Range
public Range(double lower, double upper)
From source file:org.jfree.data.xy.IntervalXYDelegate.java
/** * Returns the range of the values in the dataset's domain, including * or excluding the interval around each x-value as specified. * * @param includeInterval a flag that determines whether or not the * x-interval should be taken into account. * * @return The range.// ww w. j ava 2s .c o m */ @Override public Range getDomainBounds(boolean includeInterval) { // first get the range without the interval, then expand it for the // interval width Range range = DatasetUtilities.findDomainBounds(this.dataset, false); if (includeInterval && range != null) { double lowerAdj = getIntervalWidth() * getIntervalPositionFactor(); double upperAdj = getIntervalWidth() - lowerAdj; range = new Range(range.getLowerBound() - lowerAdj, range.getUpperBound() + upperAdj); } return range; }
From source file:org.jfree.experimental.chart.axis.LogAxis.java
/** * Adjusts the axis range to match the data range that the axis is * required to display.//from w w w . j av a 2 s . c om */ 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
/** * Updates the axis-related properties of a chart. * //from w w w . j av a 2s. c o m * @param aControl * Chart control to be updated. * @param aAxes * Axis-related visual settings to be applied. * @param aGrid * Grid-related visual settings to be applied. */ public static void updateAxes(JFreeChart aControl, AxesSettings aAxes, GridSettings aGrid) { XYPlot plot = aControl.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()); updateAxes(plot, aAxes, aGrid, domainDataRange, rangeDataRange); }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
public JFreeChart getChart(List<String> idsToPaint) { if (paramX == null || paramY == null) { return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend); }/*from ww w . j a v a 2 s . c o m*/ NumberAxis xAxis = new NumberAxis(AttributeUtilities.getNameWithUnit(paramX, unitX, transformX)); NumberAxis yAxis = new NumberAxis(AttributeUtilities.getNameWithUnit(paramY, unitY, transformY)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); double usedMinX = Double.POSITIVE_INFINITY; double usedMaxX = Double.NEGATIVE_INFINITY; int index = 0; ColorAndShapeCreator colorAndShapeCreator = new ColorAndShapeCreator(idsToPaint.size()); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); try { if (plotable != null) { if (plotable.getType() == Plotable.BOTH || plotable.getType() == Plotable.BOTH_STRICT) { Double minArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX), transformX); Double maxArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX), transformX); if (isValid(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (isValid(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } for (Map<String, Integer> choice : plotable.getAllChoices()) { double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY, choice); if (points != null) { for (int i = 0; i < points[0].length; i++) { if (isValid(points[0][i])) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } } else if (plotable.getType() == Plotable.DATASET || plotable.getType() == Plotable.DATASET_STRICT) { double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY); if (points != null) { for (int i = 0; i < points[0].length; i++) { if (isValid(points[0][i])) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } else if (plotable.getType() == Plotable.FUNCTION) { Double minArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX), transformX); Double maxArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX), transformX); if (isValid(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (isValid(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } } else if (plotable.getType() == Plotable.FUNCTION_SAMPLE) { Double minArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMinArguments().get(paramX), unitX), transformX); Double maxArg = Plotable.transform( plotable.convertToUnit(paramX, plotable.getMaxArguments().get(paramX), unitX), transformX); if (isValid(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (isValid(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } for (Double x : plotable.getSamples()) { Double xx = Plotable.transform(plotable.convertToUnit(paramX, x, unitX), transformX); if (isValid(xx)) { usedMinX = Math.min(usedMinX, xx); usedMaxX = Math.max(usedMaxX, xx); } } } } } catch (ConvertException e) { } } if (Double.isInfinite(usedMinX)) { usedMinX = 0.0; } if (Double.isInfinite(usedMaxX)) { usedMaxX = 100.0; } if (paramX.equals(AttributeUtilities.TIME) || paramX.equals(AttributeUtilities.CONCENTRATION)) { usedMinX = Math.min(usedMinX, 0.0); xAxis.setAutoRangeIncludesZero(true); } else { xAxis.setAutoRangeIncludesZero(false); } if (paramY.equals(AttributeUtilities.TIME) || paramY.equals(AttributeUtilities.CONCENTRATION)) { yAxis.setAutoRangeIncludesZero(true); } else { yAxis.setAutoRangeIncludesZero(false); } if (usedMinX == usedMaxX) { usedMinX -= 1.0; usedMaxX += 1.0; } if (useManualRange && minX < maxX && minY < maxY) { usedMinX = minX; usedMaxX = maxX; xAxis.setRange(new Range(minX, maxX)); yAxis.setRange(new Range(minY, maxY)); } Set<ConvertException> convertExceptions = new LinkedHashSet<>(); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.DATASET) { try { plotDataSet(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index)); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.DATASET_STRICT) { try { plotDataSetStrict(plot, plotable, id); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.FUNCTION) { try { plotFunction(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } warnings = new ArrayList<>(); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.FUNCTION_SAMPLE) { try { plotFunctionSample(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX, warnings); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.BOTH) { try { plotBoth(plot, plotable, id, colorAndShapeCreator.getColorList().get(index), colorAndShapeCreator.getShapeList().get(index), usedMinX, usedMaxX); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable != null && plotable.getType() == Plotable.BOTH_STRICT) { try { plotBothStrict(plot, plotable, id, usedMinX, usedMaxX); index++; } catch (ConvertException e) { convertExceptions.add(e); } } } if (!convertExceptions.isEmpty()) { String warning = "Some datasets/functions cannot be converted to the desired unit\n"; warning += "Uncovertable units: "; for (ConvertException e : convertExceptions) { warning += e.getFromUnit() + "->" + e.getToUnit() + ", "; } warning = warning.substring(0, warning.length() - 2); JOptionPane.showMessageDialog(this, warning, "Warning", JOptionPane.WARNING_MESSAGE); } return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); }
From source file:org.tsho.dmc2.ui.bifurcation.BifurcationControlForm2.java
public Range getSecondParameterRange() throws InvalidData { if (box1.getSelectedItem() == box2.getSelectedItem()) { throw new InvalidData("Must select different parameters"); }/* www .j ava2s . c o m*/ if (lSecondParRange.getValue() >= uSecondParRange.getValue()) { throw new InvalidData("Invalid \"" + box2.getSelectedItem() + "\" parameter range"); } return new Range(lSecondParRange.getValue(), uSecondParRange.getValue()); }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java
public JPanel calcEthanolWater() throws Exception { double T = 343.15; setLayout(new BorderLayout()); COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound c1 = db.getComp("ethanol"); COSMOSACCompound c2 = db.getComp("water"); double[] cavityVolume = new double[2]; cavityVolume[0] = c1.Vcosmo;// w w w . j av a 2 s. com cavityVolume[1] = c2.Vcosmo; double[][] sigma = new double[2][]; sigma[0] = c1.sigma; sigma[1] = c2.sigma; SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c1.name.toLowerCase() + ".log"); SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c2.name.toLowerCase() + ".log"); sigma[0] = c1Sigma.getSigmaProfile(); sigma[1] = c2Sigma.getSigmaProfile(); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setParameters(cavityVolume, c1.charge, sigma); cosmosac.setIgnoreSG(true); cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2); cosmosac.setTemperature(T); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[] Psat = new double[2]; Psat[0] = 72388; Psat[1] = 32760; double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot1; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot1 = (XYPlot) chart.getPlot(); plot1.getDomainAxis().setRange(new Range(0.0, 1.0)); plot1.setDataset(dataset); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp1 = new JPanel(new BorderLayout()); jp1.add(chartPanel); add(jp1, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp1; }
From source file:org.jfree.data.time.TimeSeries.java
/** * Returns the range of y-values in the time series. Any <code>null</code> * data values in the series will be ignored (except for the special case * where all data values are <code>null</code>, in which case the return * value is <code>Range(Double.NaN, Double.NaN)</code>). If the time * series contains no items, this method will return <code>null</code>. * /*from w ww . j av a 2s.com*/ * @return The range of y-values in the time series (possibly * <code>null</code>). * * @since 1.0.18 */ public Range findValueRange() { if (this.data.isEmpty()) { return null; } return new Range(this.minY, this.maxY); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Some checks for the getRangeBounds() method. *///ww w .j a v a 2s . c o m @Test public void testGetRangeBounds() { TimeSeriesCollection dataset = new TimeSeriesCollection(); // when the dataset contains no series, we expect the range to be null assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // when the dataset contains one or more series, but those series // contain no items, we still expect the range to be null TimeSeries s1 = new TimeSeries("S1"); dataset.addSeries(s1); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // tests with values s1.add(new Year(2012), 1.0); assertEquals(new Range(1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(1.0, 1.0), dataset.getRangeBounds(true)); s1.add(new Year(2013), -1.0); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); s1.add(new Year(2014), null); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); // adding a second series TimeSeries s2 = new TimeSeries("S2"); dataset.addSeries(s2); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); s2.add(new Year(2014), 5.0); assertEquals(new Range(-1.0, 5.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 5.0), dataset.getRangeBounds(true)); dataset.removeAllSeries(); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); s1 = new TimeSeries("s1"); s2 = new TimeSeries("s2"); dataset.addSeries(s1); dataset.addSeries(s2); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); s2.add(new Year(2014), 100.0); assertEquals(new Range(100.0, 100.0), dataset.getRangeBounds(false)); assertEquals(new Range(100.0, 100.0), dataset.getRangeBounds(true)); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapPlotPanel.java
/** * See if the axis ranges have changed in the main chart and, if so, update * the subcharts.//from w w w. j a va 2 s . c om * * @param event */ public void chartChanged(ChartChangeEvent event) { // this happens when zooming, or resetting the axis scales logger.info("The port heat map chart changed"); XYPlot plot2 = (XYPlot) SinglePortChart.getPlot(); XYPlot plot1 = (XYPlot) SingleTimeChart.getPlot(); XYPlot plot = (XYPlot) heatChart.getPlot(); if (pHeatMap != null) { // X - Domain - time // Y - Range - port // Z - - % Util Range fixedXRange = new Range(0, pHeatMap.getMaximumXValue()); Range fixedYRange = new Range(0, pHeatMap.getMaximumYValue()); Range fixedZRange = new Range(0, pHeatMap.getMaximumZValue()); // vertical, all ports, single time plot1.getRangeAxis().setRange(fixedZRange); plot1.getDomainAxis().setRange(fixedYRange); // horizontal, single port, all times plot2.getRangeAxis().setRange(fixedZRange); plot2.getDomainAxis().setRange(fixedXRange); // main chart if (initial) { initial = false; // only necessary the first time plot.getRangeAxis().setRange(fixedYRange); plot.getDomainAxis().setRange(fixedXRange); } // the main chart has to be handled different, cause its zoomable if (!plot.getDomainAxis().getRange().equals(fixedXRange)) { fixedXRange = plot.getDomainAxis().getRange(); // single port over time, lower horizontal plot plot2.getDomainAxis().setRange(fixedXRange); // plot2.getRangeAxis().setRange(fixedZRange); } if (!plot.getRangeAxis().getRange().equals(fixedYRange)) { fixedYRange = plot.getRangeAxis().getRange(); // all ports over single time, right vertical plot plot1.getDomainAxis().setRange(fixedYRange); // plot1.getRangeAxis().setRange(fixedZRange); } } }
From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java
private Range getRange(final XYSeriesCollection seriesCol) { if (this.boundingBox == null) return seriesCol.getRangeBounds(false); else// w ww . ja v a 2 s.com return new Range(boundingBox.minY, boundingBox.maxY); }