List of usage examples for org.jfree.data Range expand
public static Range expand(Range range, double lowerMargin, double upperMargin)
From source file:sim.util.media.chart.BoxPlotGenerator.java
protected void buildChart() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); // we build the chart manually rather than using ChartFactory // because we need to customize the getDataRange method below CategoryAxis categoryAxis = new CategoryAxis(""); NumberAxis valueAxis = new NumberAxis("Untitled Y Axis"); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) { // Customizing this method in order to provide a bit of // vertical buffer. Otherwise the bar chart box gets drawn // slightly off-chart, which looks really bad. public Range getDataRange(ValueAxis axis) { Range range = super.getDataRange(axis); if (range == null) return null; final double EXTRA_PERCENTAGE = 0.02; return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE); }//ww w .j a v a2 s.c o m }; chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); ChartFactory.getChartTheme().apply(chart); chart.setAntiAlias(true); chartPanel = buildChartPanel(chart); setChartPanel(chartPanel); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
From source file:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java
protected void buildChart() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); // we build the chart manually rather than using ChartFactory // because we need to customize the getDataRange method below CategoryAxis categoryAxis = new CategoryAxis(""); NumberAxis valueAxis = new NumberAxis("Untitled Y Axis"); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) { // Customizing this method in order to provide a bit of // vertical buffer. Otherwise the bar chart box gets drawn // slightly off-chart, which looks really bad. public Range getDataRange(ValueAxis axis) { Range range = super.getDataRange(axis); if (range == null) { return null; }/* ww w .j a v a 2 s.c om*/ final double EXTRA_PERCENTAGE = 0.02; return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE); } }; chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false); ChartFactory.getChartTheme().apply(chart); chart.setAntiAlias(true); chartPanel = buildChartPanel(chart); setChartPanel(chartPanel); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }
From source file:org.jfree.data.RangeTest.java
/** * A simple test for the expand() method. *//*from w ww.j a v a2s .c om*/ @Test public void testExpand() { Range r1 = new Range(0.0, 100.0); Range r2 = Range.expand(r1, 0.10, 0.10); assertEquals(-10.0, r2.getLowerBound(), 0.001); assertEquals(110.0, r2.getUpperBound(), 0.001); // Expand by 0% does not change the range r2 = Range.expand(r1, 0.0, 0.0); assertEquals(r1, r2); try { Range.expand(null, 0.1, 0.1); fail("Null value is accepted"); } catch (Exception e) { } // Lower > upper: mid point is used r2 = Range.expand(r1, -0.8, -0.5); assertEquals(65.0, r2.getLowerBound(), 0.001); assertEquals(65.0, r2.getUpperBound(), 0.001); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void updateIntensityAxis() { double max_int = 0.; for (int d = 0; d < thePlot.getDatasetCount(); d++) { XYDataset dataset = thePlot.getDataset(d); for (int s = 0; s < dataset.getSeriesCount(); s++) for (int i = 0; i < dataset.getItemCount(s); i++) max_int = Math.max(max_int, dataset.getYValue(s, i)); }//from ww w . ja va 2 s . co m if (max_int == 0.) { // no data return; } 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()); thePlot.getRangeAxis().setRange(new_int_range); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void updateChart() { // auto zoom/* ww w.jav a 2s . com*/ if (theDocument.size() > 0) { Range mz_range = thePlot.getDomainAxis().getRange(); // update data double mz_toll = screenToDataX(1.); double[][] data = theDocument.getData(mz_range.getLowerBound(), mz_range.getUpperBound()); // 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); } else { thePlot.getRangeAxis().setRange(new Range(0., 1.)); theDataset.removeSeries("intensities"); } // restore annotation shapes showSelection(); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void updateChart() { // auto zoom//from w w w . ja v a 2 s.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(); }