private int getTotalIssues(TableXYDataset dataset) { int totalIssues = 0; for( int i=0; i<dataset.getSeriesCount(); i++ ) totalIssues+= dataset.getYValue(i,0); return totalIssues; }
/** * Creates a new table model based on the specified dataset. * * @param dataset the dataset. */ public XYDatasetTableModel(TableXYDataset dataset) { this(); this.model = dataset; this.model.addChangeListener(this); }
/** * Returns the number of rows. * * @return The row count. */ @Override public int getRowCount() { if (this.model == null) { return 0; } return this.model.getItemCount(); }
/** * Returns a value of the specified cell. * Column 0 is the X axis, Columns 1 and over are the Y axis * * @param row the row number. * @param column the column number. * * @return The value of the specified cell. */ @Override public Object getValueAt(int row, int column) { if (this.model == null) { return null; } if (column < 1) { return this.model.getX(0, row); } else { return this.model.getY(column - 1, row); } }
for (int itemNo = 0; itemNo < dataset.getItemCount(); itemNo++) { double positive = base; double negative = base; int seriesCount = dataset.getSeriesCount(); for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) { double y = dataset.getYValue(seriesNo, itemNo); if (!Double.isNaN(y)) { if (y > 0.0) {
/** * Calculates the stacked value of the all series up to, but not including * {@code series} for the specified item. It returns 0.0 if * {@code series} is the first series, i.e. 0. * * @param dataset the dataset. * @param series the series. * @param index the index. * * @return The cumulative value for all series' values up to but excluding * {@code series} for {@code index}. */ protected double getPreviousHeight(TableXYDataset dataset, int series, int index) { double result = 0.0; for (int i = 0; i < series; i++) { double value = dataset.getYValue(i, index); if (!Double.isNaN(value)) { result += value; } } return result; }
/** * Returns the range of values the renderer requires to display all the * items from the specified dataset. * * @param dataset the dataset (<code>null</code> permitted). * * @return The range (or <code>null</code> if the dataset is * <code>null</code> or empty). */ public Range findRangeBounds(XYDataset dataset) { if (dataset == null) { return null; } double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; TableXYDataset d = (TableXYDataset) dataset; int itemCount = d.getItemCount(); for (int i = 0; i < itemCount; i++) { double[] stackValues = getStackValues((TableXYDataset) dataset, d.getSeriesCount(), i); min = Math.min(min, stackValues[0]); max = Math.max(max, stackValues[1]); } if (min == Double.POSITIVE_INFINITY) { return null; } return new Range(min, max); }
/** * Gets the number of columns in the model. * * @return The number of columns in the model. */ public int getColumnCount() { if (this.model == null) { return 0; } return this.model.getSeriesCount() + 1; }
/** * Returns the column name. * * @param column the column index. * * @return The column name. */ @Override public String getColumnName(int column) { if (this.model == null) { return super.getColumnName(column); } if (column < 1) { return "X Value"; } else { return this.model.getSeriesKey(column - 1).toString(); } }
double minimum = base; double maximum = base; for (int itemNo = 0; itemNo < dataset.getItemCount(); itemNo++) { double positive = base; double negative = base; int seriesCount = dataset.getSeriesCount(); for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) { double y = dataset.getYValue(seriesNo, itemNo); if (!Double.isNaN(y)) { if (y > 0.0) {
/** * Calculates the stacked values (one positive and one negative) of all * series up to, but not including, <code>series</code> for the specified * item. It returns [0.0, 0.0] if <code>series</code> is the first series. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index. * @param index the item index. * @return An array containing the cumulative negative and positive values * for all series values up to but excluding <code>series</code> * for <code>index</code>. */ private double[] getStackValues(TableXYDataset dataset, int series, int index) { double[] result = new double[2]; for (int i = 0; i < series; i++) { double v = dataset.getYValue(i, index); if (!Double.isNaN(v)) { if (v >= 0.0) { result[1] += v; } else { result[0] += v; } } } return result; }
/** * Returns the range of values the renderer requires to display all the * items from the specified dataset. * * @param dataset the dataset ({@code null} permitted). * * @return The range (or {@code null} if the dataset is {@code null} or * empty). */ @Override public Range findRangeBounds(XYDataset dataset) { if (dataset == null) { return null; } double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; TableXYDataset d = (TableXYDataset) dataset; int itemCount = d.getItemCount(); for (int i = 0; i < itemCount; i++) { double[] stackValues = getStackValues((TableXYDataset) dataset, d.getSeriesCount(), i); min = Math.min(min, stackValues[0]); max = Math.max(max, stackValues[1]); } if (min == Double.POSITIVE_INFINITY) { return null; } return new Range(min, max); }
/** * Returns a value of the specified cell. * Column 0 is the X axis, Columns 1 and over are the Y axis * * @param row the row number. * @param column the column number. * * @return The value of the specified cell. */ public Object getValueAt(int row, int column) { if (this.model == null) { return null; } if (column < 1) { return this.model.getX(0, row); } else { return this.model.getY(column - 1, row); } }
/** * Gets the number of columns in the model. * * @return The number of columns in the model. */ @Override public int getColumnCount() { if (this.model == null) { return 0; } return this.model.getSeriesCount() + 1; }
/** * Returns the column name. * * @param column the column index. * * @return The column name. */ public String getColumnName(int column) { if (this.model == null) { return super.getColumnName(column); } if (column < 1) { return "X Value"; } else { return this.model.getSeriesKey(column - 1).toString(); } }
/** * Calculates the total for the y-values in all series for a given item * index. * * @param dataset the dataset. * @param item the item index. * * @return The total. * * @since 1.0.5 */ public static double calculateStackTotal(TableXYDataset dataset, int item) { double total = 0.0; int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { double value = dataset.getYValue(s, item); if (!Double.isNaN(value)) { total = total + value; } } return total; }
/** * Calculates the stacked value of the all series up to, but not including * <code>series</code> for the specified item. It returns 0.0 if * <code>series</code> is the first series, i.e. 0. * * @param dataset the dataset. * @param series the series. * @param index the index. * * @return The cumulative value for all series' values up to but excluding * <code>series</code> for <code>index</code>. */ protected double getPreviousHeight(TableXYDataset dataset, int series, int index) { double result = 0.0; for (int i = 0; i < series; i++) { double value = dataset.getYValue(i, index); if (!Double.isNaN(value)) { result += value; } } return result; }
/** * Creates a new table model based on the specified dataset. * * @param dataset the dataset. */ public XYDatasetTableModel(TableXYDataset dataset) { this(); this.model = dataset; this.model.addChangeListener(this); }
/** * Returns the number of rows. * * @return The row count. */ public int getRowCount() { if (this.model == null) { return 0; } return this.model.getItemCount(); }
/** * Calculates the total for the y-values in all series for a given item * index. * * @param dataset the dataset. * @param item the item index. * * @return The total. * * @since 1.0.5 */ public static double calculateStackTotal(TableXYDataset dataset, int item) { double total = 0.0; int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { double value = dataset.getYValue(s, item); if (!Double.isNaN(value)) { total = total + value; } } return total; }