use of org.knime.base.node.viz.pie.datamodel.fixed.FixedPieDataModel in project knime-core by knime.
the class FixedPieNodeModel method createModel.
/**
* {@inheritDoc}
* @throws CanceledExecutionException
* @throws TooManySectionsException
*/
@Override
protected void createModel(final ExecutionContext exec, final DataColumnSpec pieColSpec, final DataColumnSpec aggrColSpec, final BufferedDataTable dataTable, final int noOfRows, final boolean containsColorHandler) throws CanceledExecutionException, TooManySectionsException {
m_model = new FixedPieDataModel(pieColSpec, aggrColSpec, containsColorHandler);
final DataTableSpec spec = dataTable.getSpec();
final int pieColIdx = spec.findColumnIndex(pieColSpec.getName());
final int aggrColIdx;
if (aggrColSpec == null) {
aggrColIdx = -1;
} else {
aggrColIdx = spec.findColumnIndex(aggrColSpec.getName());
}
final double progressPerRow = 1.0 / noOfRows;
double progress = 0.0;
final CloseableRowIterator rowIterator = dataTable.iterator();
try {
for (int rowCounter = 0; rowCounter < noOfRows && rowIterator.hasNext(); rowCounter++) {
final DataRow row = rowIterator.next();
final Color rowColor = spec.getRowColor(row).getColor(false, false);
final DataCell pieCell = row.getCell(pieColIdx);
final DataCell aggrCell;
if (aggrColIdx >= 0) {
aggrCell = row.getCell(aggrColIdx);
} else {
aggrCell = null;
}
m_model.addDataRow(row, rowColor, pieCell, aggrCell);
progress += progressPerRow;
exec.setProgress(progress, "Adding data rows to pie chart...");
exec.checkCanceled();
}
} finally {
if (rowIterator != null) {
rowIterator.close();
}
}
}
Aggregations