Search in sources :

Example 1 with FixedPieDataModel

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();
        }
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) FixedPieDataModel(org.knime.base.node.viz.pie.datamodel.fixed.FixedPieDataModel) Color(java.awt.Color) CloseableRowIterator(org.knime.core.data.container.CloseableRowIterator) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Aggregations

Color (java.awt.Color)1 FixedPieDataModel (org.knime.base.node.viz.pie.datamodel.fixed.FixedPieDataModel)1 DataCell (org.knime.core.data.DataCell)1 DataRow (org.knime.core.data.DataRow)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 CloseableRowIterator (org.knime.core.data.container.CloseableRowIterator)1