Search in sources :

Example 1 with InteractiveHistogramDataModel

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.");
}
Also used : DefaultDataArray(org.knime.base.node.util.DefaultDataArray) InteractiveHistogramDataModel(org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramDataModel) Color(java.awt.Color) ArrayList(java.util.ArrayList) CloseableRowIterator(org.knime.core.data.container.CloseableRowIterator) DataRow(org.knime.core.data.DataRow) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) DataArray(org.knime.base.node.util.DataArray) TreeSet(java.util.TreeSet) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Aggregations

Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 DataArray (org.knime.base.node.util.DataArray)1 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)1 InteractiveHistogramDataModel (org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramDataModel)1 DataRow (org.knime.core.data.DataRow)1 CloseableRowIterator (org.knime.core.data.container.CloseableRowIterator)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1