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