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 };
}
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) };
}
Aggregations