Search in sources :

Example 16 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn 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)

Example 17 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn in project knime-core by knime.

the class HistogramNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    try {
        return super.configure(inSpecs);
    } catch (final Exception e) {
        final DataTableSpec spec = (DataTableSpec) inSpecs[0];
        if (spec == null) {
            throw new IllegalArgumentException("No table specification found");
        }
        final int numColumns = spec.getNumColumns();
        if (numColumns < 1) {
            throw new InvalidSettingsException("Input table should have at least 1 column.");
        }
        boolean xFound = false;
        boolean aggrFound = false;
        for (int i = 0; i < numColumns; i++) {
            final DataColumnSpec columnSpec = spec.getColumnSpec(i);
            if (!xFound && AbstractHistogramPlotter.X_COLUMN_FILTER.includeColumn(columnSpec)) {
                setSelectedXColumnName(columnSpec.getName());
                xFound = true;
            } else if (!aggrFound && AbstractHistogramPlotter.AGGREGATION_COLUMN_FILTER.includeColumn(columnSpec)) {
                setSelectedAggrColumns(new ColorColumn(Color.lightGray, columnSpec.getName()));
                aggrFound = true;
            }
            if (xFound && aggrFound) {
                break;
            }
        }
        if (!xFound) {
            throw new InvalidSettingsException("No column compatible with this node. Column needs to " + "be nominal or numeric and must contain a valid " + "domain. In order to compute the domain of a column " + "use the DomainCalculator or ColumnFilter node.");
        }
    }
    return new DataTableSpec[0];
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)17 Color (java.awt.Color)7 Point (java.awt.Point)5 DataCell (org.knime.core.data.DataCell)5 DataColumnSpec (org.knime.core.data.DataColumnSpec)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)4 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)4 ArrayList (java.util.ArrayList)3 DoubleCell (org.knime.core.data.def.DoubleCell)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 Dimension (java.awt.Dimension)2 Rectangle (java.awt.Rectangle)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 HistogramLayout (org.knime.base.node.viz.histogram.HistogramLayout)2 HistogramHiliteCalculator (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator)2 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)2 InteractiveHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramVizModel)2 AbstractHistogramProperties (org.knime.base.node.viz.histogram.impl.AbstractHistogramProperties)2