use of org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramDataModel in project knime-core by knime.
the class HistogramNodeModel method createHistogramModel.
/**
* {@inheritDoc}
*/
@Override
protected void createHistogramModel(final ExecutionContext exec, final int noOfRows, final BufferedDataTable data) throws CanceledExecutionException {
LOGGER.debug("Entering createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
if (noOfRows == 0) {
m_model = null;
return;
}
if (exec == null) {
throw new NullPointerException("exec must not be null");
}
if (data == null) {
throw new IllegalArgumentException("Table shouldn't be null");
}
ExecutionMonitor subExec = exec.createSubProgress(0.5);
exec.setMessage("Adding rows to histogram model...");
final DataArray dataArray = new DefaultDataArray(data, 1, noOfRows, subExec);
exec.setMessage("Adding row color to histogram...");
final SortedSet<Color> colorSet = new TreeSet<Color>(HSBColorComparator.getInstance());
subExec = exec.createSubProgress(0.5);
final double progressPerRow = 1.0 / noOfRows;
double progress = 0.0;
final CloseableRowIterator rowIterator = data.iterator();
try {
for (int i = 0; i < noOfRows && rowIterator.hasNext(); i++) {
final DataRow row = rowIterator.next();
final Color color = data.getDataTableSpec().getRowColor(row).getColor(false, false);
if (!colorSet.contains(color)) {
colorSet.add(color);
}
progress += progressPerRow;
subExec.setProgress(progress, "Adding data rows to histogram...");
subExec.checkCanceled();
}
} finally {
if (rowIterator != null) {
rowIterator.close();
}
}
exec.setProgress(1.0, "Histogram finished.");
m_model = new InteractiveHistogramDataModel(dataArray, new ArrayList<Color>(colorSet));
LOGGER.debug("Exiting createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
}
Aggregations