Search in sources :

Example 1 with FixedHistogramDataModel

use of org.knime.base.node.viz.histogram.datamodel.FixedHistogramDataModel in project knime-core by knime.

the class FixedColumnHistogramNodeModel method createHistogramModel.

/**
 * {@inheritDoc}
 */
@Override
protected void createHistogramModel(final ExecutionContext exec, final int noOfRows, final BufferedDataTable table) throws CanceledExecutionException {
    LOGGER.debug("Entering createHistogramModel(exec, table) " + "of class FixedColumnHistogramNodeModel.");
    final Collection<ColorColumn> aggrColumns = getAggrColumns();
    final int noOfBins = BinningUtil.calculateIntegerMaxNoOfBins(m_noOfBins.getIntValue(), getXColSpec());
    m_model = new FixedHistogramDataModel(getXColSpec(), AggregationMethod.getDefaultMethod(), aggrColumns, noOfBins);
    if (noOfRows < 1) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("No rows available");
        }
        return;
    }
    exec.setMessage("Adding data rows to histogram...");
    final double progressPerRow = 1.0 / noOfRows;
    double progress = 0.0;
    int aggrColSize = 0;
    if (aggrColumns != null) {
        aggrColSize = aggrColumns.size();
    }
    final DataTableSpec tableSpec = getTableSpec();
    final int xColIdx = getXColIdx();
    // save the aggregation column indices
    final int[] aggrColIdxs = new int[aggrColSize];
    if (aggrColumns != null) {
        int idx = 0;
        for (final ColorColumn aggrCol : aggrColumns) {
            aggrColIdxs[idx++] = tableSpec.findColumnIndex(aggrCol.getColumnName());
        }
    }
    final CloseableRowIterator rowIterator = table.iterator();
    try {
        for (int rowCounter = 0; rowCounter < noOfRows && rowIterator.hasNext(); rowCounter++) {
            final DataRow row = rowIterator.next();
            final Color color = tableSpec.getRowColor(row).getColor(false, false);
            if (aggrColSize < 1) {
                m_model.addDataRow(row.getKey(), color, row.getCell(xColIdx), DataType.getMissingCell());
            } else {
                final DataCell[] aggrCells = new DataCell[aggrColSize];
                for (int i = 0, length = aggrColIdxs.length; i < length; i++) {
                    aggrCells[i] = row.getCell(aggrColIdxs[i]);
                }
                m_model.addDataRow(row.getKey(), color, row.getCell(xColIdx), aggrCells);
            }
            progress += progressPerRow;
            exec.setProgress(progress, "Adding data rows to histogram...");
            exec.checkCanceled();
        }
    } finally {
        if (rowIterator != null) {
            rowIterator.close();
        }
    }
    exec.setMessage("Sorting rows...");
    exec.setProgress(1.0, "Histogram finished.");
    LOGGER.debug("Exiting createHistogramModel(exec, table) " + "of class FixedColumnHistogramNodeModel.");
}
Also used : FixedHistogramDataModel(org.knime.base.node.viz.histogram.datamodel.FixedHistogramDataModel) DataTableSpec(org.knime.core.data.DataTableSpec) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Color(java.awt.Color) CloseableRowIterator(org.knime.core.data.container.CloseableRowIterator) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Aggregations

Color (java.awt.Color)1 FixedHistogramDataModel (org.knime.base.node.viz.histogram.datamodel.FixedHistogramDataModel)1 ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)1 DataCell (org.knime.core.data.DataCell)1 DataRow (org.knime.core.data.DataRow)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 CloseableRowIterator (org.knime.core.data.container.CloseableRowIterator)1