Search in sources :

Example 1 with ColorHandlerPortObject

use of org.knime.core.node.port.viewproperty.ColorHandlerPortObject in project knime-core by knime.

the class ColorManager2NodeModel method execute.

/**
 * Is invoked during the node's execution to make the color settings.
 *
 * @param data the input data array
 * @param exec the execution monitor
 * @return the same input data table whereby the RowKeys contain color info
 *         now
 * @throws CanceledExecutionException if user canceled execution
 */
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws CanceledExecutionException {
    assert (data != null && data.length == 1 && data[INPORT] != null);
    BufferedDataTable in = (BufferedDataTable) data[0];
    DataTableSpec inSpec = in.getDataTableSpec();
    ColorHandler colorHandler;
    // if no column has been selected, guess first nominal column
    if (m_column == null) {
        // find first nominal column with possible values
        String column = DataTableSpec.guessNominalClassColumn(inSpec, false);
        m_columnGuess = column;
        m_isNominalGuess = true;
        super.setWarningMessage("Selected column \"" + column + "\" with default nominal color mapping.");
        Set<DataCell> set = inSpec.getColumnSpec(column).getDomain().getValues();
        m_mapGuess.clear();
        m_mapGuess.putAll(ColorManager2DialogNominal.createColorMapping(set));
        colorHandler = createNominalColorHandler(m_mapGuess);
        DataTableSpec newSpec = getOutSpec(inSpec, column, colorHandler);
        BufferedDataTable changedSpecTable = exec.createSpecReplacerTable(in, newSpec);
        DataTableSpec modelSpec = new DataTableSpec(newSpec.getColumnSpec(column));
        ColorHandlerPortObject viewModel = new ColorHandlerPortObject(modelSpec, colorHandler.toString() + " based on column \"" + m_column + "\"");
        return new PortObject[] { changedSpecTable, viewModel };
    }
    // find column index
    int columnIndex = inSpec.findColumnIndex(m_column);
    // create new column spec based on color settings
    DataColumnSpec cspec = inSpec.getColumnSpec(m_column);
    if (m_isNominal) {
        colorHandler = createNominalColorHandler(m_map);
    } else {
        DataColumnDomain dom = cspec.getDomain();
        DataCell lower, upper;
        if (dom.hasBounds()) {
            lower = dom.getLowerBound();
            upper = dom.getUpperBound();
        } else {
            Statistics3Table stat = new Statistics3Table(in, false, 0, Collections.<String>emptyList(), exec);
            lower = stat.getMinCells()[columnIndex];
            upper = stat.getMaxCells()[columnIndex];
        }
        colorHandler = createRangeColorHandler(lower, upper, m_map);
    }
    DataTableSpec newSpec = getOutSpec(inSpec, m_column, colorHandler);
    DataTableSpec modelSpec = new DataTableSpec(newSpec.getColumnSpec(m_column));
    BufferedDataTable changedSpecTable = exec.createSpecReplacerTable(in, newSpec);
    ColorHandlerPortObject viewModel = new ColorHandlerPortObject(modelSpec, "Coloring on \"" + m_column + "\"");
    return new PortObject[] { changedSpecTable, viewModel };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnDomain(org.knime.core.data.DataColumnDomain) BufferedDataTable(org.knime.core.node.BufferedDataTable) Statistics3Table(org.knime.base.data.statistics.Statistics3Table) DataCell(org.knime.core.data.DataCell) ColorHandlerPortObject(org.knime.core.node.port.viewproperty.ColorHandlerPortObject) PortObject(org.knime.core.node.port.PortObject) ColorHandler(org.knime.core.data.property.ColorHandler) ColorHandlerPortObject(org.knime.core.node.port.viewproperty.ColorHandlerPortObject)

Example 2 with ColorHandlerPortObject

use of org.knime.core.node.port.viewproperty.ColorHandlerPortObject in project knime-core by knime.

the class ColorExtractNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    ColorHandlerPortObject colorPO = (ColorHandlerPortObject) inObjects[0];
    DataTableSpec colorSpec = colorPO.getSpec();
    return new BufferedDataTable[] { exec.createBufferedDataTable(extractColorTable(colorSpec), exec) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataTable(org.knime.core.node.BufferedDataTable) ColorHandlerPortObject(org.knime.core.node.port.viewproperty.ColorHandlerPortObject)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 ColorHandlerPortObject (org.knime.core.node.port.viewproperty.ColorHandlerPortObject)2 Statistics3Table (org.knime.base.data.statistics.Statistics3Table)1 DataCell (org.knime.core.data.DataCell)1 DataColumnDomain (org.knime.core.data.DataColumnDomain)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 ColorHandler (org.knime.core.data.property.ColorHandler)1 PortObject (org.knime.core.node.port.PortObject)1