org.jfree.data.category.IntervalCategoryDataset Java Examples

The following examples show how to use org.jfree.data.category.IntervalCategoryDataset. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntervalBarRenderer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 dataset, row, column, pass);
     }

 }
 
Example #2
Source File: IntervalBarRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column,
                     int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 dataset, row, column, pass);
     } 
     
 }
 
Example #3
Source File: IntervalBarRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 dataset, row, column, pass);
     }

 }
 
Example #4
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a Gantt chart using the supplied attributes plus default values
 * where required.  The chart object returned by this method uses a
 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
 * for the domain axis, a {@link DateAxis} as the range axis, and a
 * {@link GanttRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param dateAxisLabel  the label for the date axis
 *                       (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A Gantt chart.
 */
public static JFreeChart createGanttChart(String title,
        String categoryAxisLabel, String dateAxisLabel,
        IntervalCategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    DateAxis dateAxis = new DateAxis(dateAxisLabel);
    CategoryItemRenderer renderer = new GanttRenderer();
    renderer.setBaseToolTipGenerator(
                new IntervalCategoryToolTipGenerator(
                "{3} - {4}", DateFormat.getDateInstance()));
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis,
            renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #5
Source File: IntervalBarRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        boolean selected, int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 d, row, column, selected);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 dataset, row, column, selected, pass);
     }

 }
 
Example #6
Source File: IntervalBarRenderer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 dataset, row, column, pass);
     }

 }
 
Example #7
Source File: IntervalBarRenderer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis,
                 dataset, row, column, pass);
     }

 }
 
Example #8
Source File: IntervalBarRenderer.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the bar for a single (series, category) data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column,
                     int pass) {

     if (dataset instanceof IntervalCategoryDataset) {
         IntervalCategoryDataset d = (IntervalCategoryDataset) dataset;
         drawInterval(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 d, row, column);
     }
     else {
         super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, 
                 dataset, row, column, pass);
     } 
     
 }
 
Example #9
Source File: ChartFactory.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Gantt chart using the supplied attributes plus default values
 * where required.  The chart object returned by this method uses a
 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
 * for the domain axis, a {@link DateAxis} as the range axis, and a
 * {@link GanttRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param dateAxisLabel  the label for the date axis
 *                       (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A Gantt chart.
 */
public static JFreeChart createGanttChart(String title,
        String categoryAxisLabel, String dateAxisLabel,
        IntervalCategoryDataset dataset, boolean legend, boolean tooltips,
        boolean urls) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    DateAxis dateAxis = new DateAxis(dateAxisLabel);

    CategoryItemRenderer renderer = new GanttRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(
                new IntervalCategoryToolTipGenerator(
                "{3} - {4}", DateFormat.getDateInstance()));
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(
                new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis,
            renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #10
Source File: DatasetUtilities.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd
                            = (IntervalCategoryDataset) dataset;
                    value = icd.getStartValue(series, item);
                }
                else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    minimum = Math.min(minimum, value.doubleValue());
                }
            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #11
Source File: IntervalCategoryItemLabelGenerator.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }

    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #12
Source File: IntervalCategoryItemLabelGenerator.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }

    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #13
Source File: IntervalCategoryToolTipGenerator.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }

    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #14
Source File: IntervalCategoryToolTipGenerator.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the 
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset, 
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);  
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }
    
    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);  
            result[4] = getNumberFormat().format(end);  
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #15
Source File: IntervalCategoryItemLabelGenerator.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the 
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset, 
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);  
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }
    
    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);  
            result[4] = getNumberFormat().format(end);  
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #16
Source File: DatasetUtilities.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd
                            = (IntervalCategoryDataset) dataset;
                    value = icd.getStartValue(series, item);
                }
                else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    minimum = Math.min(minimum, value.doubleValue());
                }
            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #17
Source File: DatasetUtilities.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #18
Source File: ChartFactory.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Gantt chart using the supplied attributes plus default values
 * where required.  The chart object returned by this method uses a
 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis}
 * for the domain axis, a {@link DateAxis} as the range axis, and a
 * {@link GanttRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param dateAxisLabel  the label for the date axis
 *                       (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A Gantt chart.
 */
public static JFreeChart createGanttChart(String title,
        String categoryAxisLabel, String dateAxisLabel,
        IntervalCategoryDataset dataset, boolean legend, boolean tooltips,
        boolean urls) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    DateAxis dateAxis = new DateAxis(dateAxisLabel);

    CategoryItemRenderer renderer = new GanttRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(
                new IntervalCategoryToolTipGenerator(
                "{3} - {4}", DateFormat.getDateInstance()));
    }
    if (urls) {
        renderer.setBaseItemURLGenerator(
                new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis,
            renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #19
Source File: Cardumen_0079_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #20
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a Gantt chart using the supplied attributes plus default values 
 * where required.  The chart object returned by this method uses a 
 * {@link CategoryPlot} instance as the plot, with a {@link CategoryAxis} 
 * for the domain axis, a {@link DateAxis} as the range axis, and a 
 * {@link GanttRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis 
 *                           (<code>null</code> permitted).
 * @param dateAxisLabel  the label for the date axis 
 *                       (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A Gantt chart.
 */
public static JFreeChart createGanttChart(String title,
                                          String categoryAxisLabel,
                                          String dateAxisLabel,
                                          IntervalCategoryDataset dataset,
                                          boolean legend,
                                          boolean tooltips,
                                          boolean urls) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    DateAxis dateAxis = new DateAxis(dateAxisLabel);

    CategoryItemRenderer renderer = new GanttRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(
                new IntervalCategoryToolTipGenerator(
                "{3} - {4}", DateFormat.getDateInstance()));
    }
    if (urls) {
        renderer.setBaseURLGenerator(new StandardCategoryURLGenerator());
    }

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, dateAxis, 
            renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);

    return chart;

}
 
Example #21
Source File: IntervalCategoryItemLabelGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the 
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset, 
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);  
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }
    
    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);  
            result[4] = getNumberFormat().format(end);  
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #22
Source File: Cardumen_0079_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #23
Source File: IntervalCategoryItemLabelGenerator.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }

    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #24
Source File: DatasetUtilities.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the minimum range value for the specified dataset.  This is
 * easy if the dataset implements the {@link RangeInfo} interface (a good
 * idea if there is an efficient way to determine the minimum value).
 * Otherwise, it involves iterating over the entire data-set.  Returns
 * <code>null</code> if all the data values in the dataset are
 * <code>null</code>.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 *
 * @return The minimum value (possibly <code>null</code>).
 */
public static Number findMinimumRangeValue(CategoryDataset dataset) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    if (dataset instanceof RangeInfo) {
        RangeInfo info = (RangeInfo) dataset;
        return new Double(info.getRangeLowerBound(true));
    }

    // hasn't implemented RangeInfo, so we'll have to iterate...
    else {
        double minimum = Double.POSITIVE_INFINITY;
        int seriesCount = dataset.getRowCount();
        int itemCount = dataset.getColumnCount();
        for (int series = 0; series < seriesCount; series++) {
            for (int item = 0; item < itemCount; item++) {
                Number value;
                if (dataset instanceof IntervalCategoryDataset) {
                    IntervalCategoryDataset icd
                            = (IntervalCategoryDataset) dataset;
                    value = icd.getStartValue(series, item);
                }
                else {
                    value = dataset.getValue(series, item);
                }
                if (value != null) {
                    minimum = Math.min(minimum, value.doubleValue());
                }
            }
        }
        if (minimum == Double.POSITIVE_INFINITY) {
            return null;
        }
        else {
            return new Double(minimum);
        }

    }

}
 
Example #25
Source File: Cardumen_00194_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #26
Source File: IntervalCategoryItemLabelGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }

    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #27
Source File: IntervalCategoryToolTipGenerator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates the array of items that can be passed to the
 * <code>MessageFormat</code> class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 *
 * @return The items (never <code>null</code>).
 */
protected Object[] createItemArray(CategoryDataset dataset,
                                   int row, int column) {
    Object[] result = new Object[5];
    result[0] = dataset.getRowKey(row).toString();
    result[1] = dataset.getColumnKey(column).toString();
    Number value = dataset.getValue(row, column);
    if (getNumberFormat() != null) {
        result[2] = getNumberFormat().format(value);
    }
    else if (getDateFormat() != null) {
        result[2] = getDateFormat().format(value);
    }

    if (dataset instanceof IntervalCategoryDataset) {
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number start = icd.getStartValue(row, column);
        Number end = icd.getEndValue(row, column);
        if (getNumberFormat() != null) {
            result[3] = getNumberFormat().format(start);
            result[4] = getNumberFormat().format(end);
        }
        else if (getDateFormat() != null) {
            result[3] = getDateFormat().format(start);
            result[4] = getDateFormat().format(end);
        }
    }
    return result;
}
 
Example #28
Source File: Cardumen_00194_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #29
Source File: JGenProg2017_0047_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #30
Source File: JGenProg2017_0047_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * 
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateCategoryRangeBounds(CategoryDataset dataset, 
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    boolean interval = includeInterval 
                       && dataset instanceof IntervalCategoryDataset;
    int rowCount = dataset.getRowCount();
    int columnCount = dataset.getColumnCount();
    for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
            Number lvalue;
            Number uvalue;
            if (interval) {
                IntervalCategoryDataset icd 
                    = (IntervalCategoryDataset) dataset;
                lvalue = icd.getStartValue(row, column);
                uvalue = icd.getEndValue(row, column);
            }
            else {
                lvalue = dataset.getValue(row, column);
                uvalue = lvalue;
            }
            if (lvalue != null) {
                minimum = Math.min(minimum, lvalue.doubleValue());
            }
            if (uvalue != null) {
                maximum = Math.max(maximum, uvalue.doubleValue());
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}