List of usage examples for org.jfree.chart.util Args nullNotPermitted
public static void nullNotPermitted(Object param, String name)
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
/** * Paints a chart with scaling options/*from ww w . ja va 2 s . com*/ * * @param chart * @param info * @param out * @param width * @param height * @param resolution * @return BufferedImage of a given chart with scaling to resolution * @throws IOException */ private static BufferedImage paintScaledChartToBufferedImage(JFreeChart chart, ChartRenderingInfo info, OutputStream out, int width, int height, int resolution, int bufferedIType) throws IOException { Args.nullNotPermitted(out, "out"); Args.nullNotPermitted(chart, "chart"); double scaleX = resolution / 72.0; double scaleY = resolution / 72.0; double desiredWidth = width * scaleX; double desiredHeight = height * scaleY; double defaultWidth = width; double defaultHeight = height; boolean scale = false; // get desired width and height from somewhere then... if ((scaleX != 1) || (scaleY != 1)) { scale = true; } BufferedImage image = new BufferedImage((int) desiredWidth, (int) desiredHeight, bufferedIType); Graphics2D g2 = image.createGraphics(); if (scale) { AffineTransform saved = g2.getTransform(); g2.transform(AffineTransform.getScaleInstance(scaleX, scaleY)); chart.draw(g2, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight), info); g2.setTransform(saved); g2.dispose(); } else { chart.draw(g2, new Rectangle2D.Double(0, 0, defaultWidth, defaultHeight), info); } return image; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Creates a {@link CategoryDataset} that contains a copy of the data in * an array (instances of {@code double} are created to represent the * data items).// www. j av a2 s . c o m * <p> * Row and column keys are taken from the supplied arrays. * * @param rowKeys the row keys ({@code null} not permitted). * @param columnKeys the column keys ({@code null} not permitted). * @param data the data. * * @return The dataset. */ public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, Comparable[] columnKeys, double[][] data) { Args.nullNotPermitted(rowKeys, "rowKeys"); Args.nullNotPermitted(columnKeys, "columnKeys"); if (ArrayUtils.hasDuplicateItems(rowKeys)) { throw new IllegalArgumentException("Duplicate items in 'rowKeys'."); } if (ArrayUtils.hasDuplicateItems(columnKeys)) { throw new IllegalArgumentException("Duplicate items in 'columnKeys'."); } if (rowKeys.length != data.length) { throw new IllegalArgumentException( "The number of row keys does not match the number of rows in " + "the data array."); } int columnCount = 0; for (int r = 0; r < data.length; r++) { columnCount = Math.max(columnCount, data[r].length); } if (columnKeys.length != columnCount) { throw new IllegalArgumentException( "The number of column keys does not match the number of " + "columns in the data array."); } // now do the work... DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int r = 0; r < data.length; r++) { Comparable rowKey = rowKeys[r]; for (int c = 0; c < data[r].length; c++) { Comparable columnKey = columnKeys[c]; result.addValue(new Double(data[r][c]), rowKey, columnKey); } } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Creates a {@link CategoryDataset} by copying the data from the supplied * {@link KeyedValues} instance./* w ww . j a v a2s .c o m*/ * * @param rowKey the row key ({@code null} not permitted). * @param rowData the row data ({@code null} not permitted). * * @return A dataset. */ public static CategoryDataset createCategoryDataset(Comparable rowKey, KeyedValues rowData) { Args.nullNotPermitted(rowKey, "rowKey"); Args.nullNotPermitted(rowData, "rowData"); DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int i = 0; i < rowData.getItemCount(); i++) { result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i)); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Creates an {@link XYSeries} by sampling the specified function over a * fixed range.//ww w. ja v a 2 s.co m * * @param f the function ({@code null} not permitted). * @param start the start value for the range. * @param end the end value for the range. * @param samples the number of sample points (must be > 1). * @param seriesKey the key to give the resulting series * ({@code null} not permitted). * * @return A series. * * @since 1.0.13 */ public static XYSeries sampleFunction2DToSeries(Function2D f, double start, double end, int samples, Comparable seriesKey) { Args.nullNotPermitted(f, "f"); Args.nullNotPermitted(seriesKey, "seriesKey"); if (start >= end) { throw new IllegalArgumentException("Requires 'start' < 'end'."); } if (samples < 2) { throw new IllegalArgumentException("Requires 'samples' > 1"); } XYSeries series = new XYSeries(seriesKey); double step = (end - start) / (samples - 1); for (int i = 0; i < samples; i++) { double x = start + (step * i); series.add(x, f.getValue(x)); } return series; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of values in the domain (x-values) of a dataset. * * @param dataset the dataset ({@code null} not permitted). * @param includeInterval determines whether or not the x-interval is taken * into account (only applies if the dataset is an * {@link IntervalXYDataset}). * * @return The range of values (possibly {@code null}). *///from www . ja va2 s .co m public static Range findDomainBounds(XYDataset dataset, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Range result; // if the dataset implements DomainInfo, life is easier if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; result = info.getDomainBounds(includeInterval); } else { result = iterateDomainBounds(dataset, includeInterval); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the bounds of the x-values in the specified {@code dataset} * taking into account only the visible series and including any x-interval * if requested.// w ww. j a v a2 s .c o m * * @param dataset the dataset ({@code null} not permitted). * @param visibleSeriesKeys the visible series keys ({@code null} * not permitted). * @param includeInterval include the x-interval (if any)? * * @return The bounds (or {@code null} if the dataset contains no * values. * * @since 1.0.13 */ public static Range findDomainBounds(XYDataset dataset, List visibleSeriesKeys, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof XYDomainInfo) { XYDomainInfo info = (XYDomainInfo) dataset; result = info.getDomainBounds(visibleSeriesKeys, includeInterval); } else { result = iterateToFindDomainBounds(dataset, visibleSeriesKeys, includeInterval); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Iterates over the items in an {@link XYDataset} to find * the range of x-values./*from w ww . j a va 2 s .c o m*/ * * @param dataset the dataset ({@code null} not permitted). * @param includeInterval a flag that determines, for an * {@link IntervalXYDataset}, whether the x-interval or just the * x-value is used to determine the overall range. * * @return The range (possibly {@code null}). */ public static Range iterateDomainBounds(XYDataset dataset, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); double lvalue, uvalue; if (includeInterval && dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = intervalXYData.getXValue(series, item); lvalue = intervalXYData.getStartXValue(series, item); uvalue = intervalXYData.getEndXValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, lvalue); } if (!Double.isNaN(uvalue)) { minimum = Math.min(minimum, uvalue); maximum = Math.max(maximum, uvalue); } } } } else { for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { lvalue = dataset.getXValue(series, item); uvalue = lvalue; if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, uvalue); } } } } if (minimum > maximum) { return null; } else { return new Range(minimum, maximum); } }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of values in the range for the dataset. * * @param dataset the dataset ({@code null} not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (possibly {@code null}). *///w w w .j av a 2 s . co m public static Range findRangeBounds(CategoryDataset dataset, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; result = info.getRangeBounds(includeInterval); } else { result = iterateRangeBounds(dataset, includeInterval); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Finds the bounds of the y-values in the specified dataset, including * only those series that are listed in visibleSeriesKeys. * * @param dataset the dataset ({@code null} not permitted). * @param visibleSeriesKeys the keys for the visible series * ({@code null} not permitted)./*from w w w .j a v a 2 s. com*/ * @param includeInterval include the y-interval (if the dataset has a * y-interval). * * @return The data bounds. * * @since 1.0.13 */ public static Range findRangeBounds(CategoryDataset dataset, List visibleSeriesKeys, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof CategoryRangeInfo) { CategoryRangeInfo info = (CategoryRangeInfo) dataset; result = info.getRangeBounds(visibleSeriesKeys, includeInterval); } else { result = iterateToFindRangeBounds(dataset, visibleSeriesKeys, includeInterval); } return result; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of values in the range for the dataset. This method * is the partner for the {@link #findDomainBounds(XYDataset, boolean)} * method./*from w w w. java 2 s . com*/ * * @param dataset the dataset ({@code null} not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (possibly {@code null}). */ public static Range findRangeBounds(XYDataset dataset, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; result = info.getRangeBounds(includeInterval); } else { result = iterateRangeBounds(dataset, includeInterval); } return result; }