Search in sources :

Example 1 with DataArray

use of org.knime.base.node.util.DataArray 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)

Example 2 with DataArray

use of org.knime.base.node.util.DataArray in project knime-core by knime.

the class ParallelCoordinatesPlotter method calculateLines.

/**
 * Calculates the lines, containing the mapped data points.
 */
private synchronized List<LineInfo> calculateLines() {
    if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null || m_axes == null) {
        return new ArrayList<LineInfo>();
    }
    DataArray array = getDataProvider().getDataArray(getDataArrayIdx());
    // LOGGER.debug("calculate points: " + m_axes);
    List<LineInfo> lines = new ArrayList<LineInfo>(array.size());
    row: for (DataRow row : array) {
        List<Point> points = new ArrayList<Point>();
        List<DataCell> domainValues = new ArrayList<DataCell>();
        for (ParallelAxis axis : m_axes) {
            int colIdx = array.getDataTableSpec().findColumnIndex(axis.getName());
            DataCell value = row.getCell(colIdx);
            if (value.isMissing() && m_skipMissingValues) {
                continue row;
            }
            domainValues.add(value);
            int x = (int) getXAxis().getCoordinate().calculateMappedValue(new StringCell(axis.getName()), getDrawingPaneDimension().width);
            int y = MISSING;
            if (!value.isMissing()) {
                y = getDrawingPaneDimension().height - ParallelCoordinateDrawingPane.BOTTOM_SPACE - (int) axis.getMappedValue(value);
            }
            Point p = new Point(x, y);
            points.add(p);
        }
        boolean isHilite = delegateIsHiLit(row.getKey());
        if (!m_hide || (m_hide && isHilite)) {
            LineInfo line = new LineInfo(points, domainValues, m_selected.contains(row.getKey()), isHilite, array.getDataTableSpec().getRowColor(row), array.getDataTableSpec().getRowSizeFactor(row), row.getKey());
            line.setShape(array.getDataTableSpec().getRowShape(row));
            lines.add(line);
        }
    }
    return lines;
}
Also used : StringCell(org.knime.core.data.def.StringCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Point(java.awt.Point) DataRow(org.knime.core.data.DataRow) DataArray(org.knime.base.node.util.DataArray)

Example 3 with DataArray

use of org.knime.base.node.util.DataArray in project knime-core by knime.

the class ScatterPlotter method updatePaintModel.

/**
 * The data points of the data to visulaize are mapped to screen
 * coordinates, represented by
 * {@link org.knime.base.node.viz.plotter.scatter.DotInfo} and are passed in
 * a {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray} to the
 * {@link org.knime.base.node.viz.plotter.scatter
 * .ScatterPlotterDrawingPane}. Repaint of the drawing pane is triggered.
 * Jittering is also triggered from here.
 *
 * @see org.knime.base.node.viz.plotter.columns.TwoColumnPlotter
 *      #updatePaintModel()
 */
@Override
public void updatePaintModel() {
    if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null) {
        return;
    }
    if (getSelectedXColumnIndex() == -1 || getSelectedYColumnIndex() == -1) {
        return;
    }
    // check if the selected column indices are available
    int xIdx = getSelectedXColumnIndex();
    int yIdx = getSelectedYColumnIndex();
    int numCols = getDataProvider().getDataArray(getDataArrayIdx()).getDataTableSpec().getNumColumns();
    if (xIdx >= numCols || yIdx >= numCols) {
        return;
    }
    // getScatterPlotterDrawingPane().clearSelection();
    // get the rowInfo from the model
    DataArray rowsCont = getDataProvider().getDataArray(getDataArrayIdx());
    if (rowsCont != null) {
        // LOGGER.debug("row container != null");
        // and create a new DotInfo array with the rowKeys in the DotInfos.
        List<DotInfo> dotList = new ArrayList<DotInfo>();
        int rowNr = 0;
        for (DataRow row : rowsCont) {
            double size = rowsCont.getDataTableSpec().getRowSizeFactor(row);
            ColorAttr colorAttr = rowsCont.getDataTableSpec().getRowColor(row);
            boolean isHilite = delegateIsHiLit(row.getKey());
            if ((isHilite && m_hide) || !m_hide) {
                if (m_hide) {
                    isHilite = false;
                }
                DotInfo dot = new DotInfo(0, 0, row.getKey(), isHilite, colorAttr, size, rowNr);
                dot.setShape(rowsCont.getDataTableSpec().getRowShape(row));
                DataCell xDomain = row.getCell(getSelectedXColumnIndex());
                dot.setXDomainValue(xDomain);
                DataCell yDomain = row.getCell(getSelectedYColumnIndex());
                dot.setYDomainValue(yDomain);
                dotList.add(dot);
            }
            rowNr++;
        }
        DotInfo[] dotArray = new DotInfo[dotList.size()];
        dotList.toArray(dotArray);
        // now create a new DotInfoArray
        DotInfoArray newDotArray = new DotInfoArray(dotArray);
        // store it in the drawing pane
        if (isScatterPlotterDrawingPane()) {
            getScatterPlotterDrawingPane().setDotInfoArray(newDotArray);
        }
        // and get the coordinates calculated.
        calculateCoordinates(newDotArray);
    }
    getDrawingPane().repaint();
}
Also used : ArrayList(java.util.ArrayList) ColorAttr(org.knime.core.data.property.ColorAttr) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) Point(java.awt.Point) DataArray(org.knime.base.node.util.DataArray)

Example 4 with DataArray

use of org.knime.base.node.util.DataArray in project knime-core by knime.

the class ScatterMatrixPlotter method updatePaintModel.

/**
 * Creates the nominal coordinates with the selected column names,
 * calculates the surrounding rectangle for the scatter matrix elements,
 * then maps the points to the screen coordinates, associates the
 * {@link org.knime.base.node.viz.plotter.scatter.DotInfo}s with the
 * referring
 * {@link
 * org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixElement}
 * and passes them to the
 * {@link
 * org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixDrawingPane}.
 * The {@link
 * org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixDrawingPane}
 * then extracts the dots from the
 *{@link org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixElement}
 * and stores them in a
 * {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray}.
 *
 * @see org.knime.base.node.viz.plotter.AbstractPlotter#updatePaintModel()
 */
@Override
public synchronized void updatePaintModel() {
    // clear the drawing pane
    ((ScatterMatrixDrawingPane) getDrawingPane()).setDotInfoArray(null);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setScatterMatrixElements(null);
    // get the number of columns c
    if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null) {
        return;
    }
    DataArray data = getDataProvider().getDataArray(getDataArrayIdx());
    // get the first columns
    if (m_selectedColumns == null) {
        m_selectedColumns = new LinkedHashSet<String>();
        for (int i = 0; i < DEFAULT_NR_COLS && i < data.getDataTableSpec().getNumColumns(); i++) {
            // add them to selected columns
            String colName = data.getDataTableSpec().getColumnSpec(i).getName();
            m_selectedColumns.add(colName);
        }
        if (data.getDataTableSpec().getNumColumns() > DEFAULT_NR_COLS) {
            getProperties().setSelectedIndex(MultiColumnPlotterProperties.COLUMN_FILTER_IDX);
        }
        ((ScatterMatrixProperties) getProperties()).updateColumnSelection(data.getDataTableSpec(), m_selectedColumns);
    }
    if (m_selectedColumns.size() == 0) {
        getDrawingPane().repaint();
        return;
    }
    Set<DataCell> selectedColumnCells = new LinkedHashSet<DataCell>();
    m_coordinates = new ArrayList<Coordinate>();
    List<Integer> columnIndices = new ArrayList<Integer>();
    for (String name : m_selectedColumns) {
        int idx = data.getDataTableSpec().findColumnIndex(name);
        if (idx >= 0) {
            selectedColumnCells.add(new StringCell(name));
            DataColumnSpec colSpec = data.getDataTableSpec().getColumnSpec(idx);
            columnIndices.add(idx);
            Coordinate coordinate = Coordinate.createCoordinate(colSpec);
            m_coordinates.add(coordinate);
        }
    }
    // create coordinates with the column names
    createNominalXCoordinate(selectedColumnCells);
    // reverse list for y axis...
    List<DataCell> reverseList = new ArrayList<DataCell>(selectedColumnCells);
    Collections.reverse(reverseList);
    createNominalYCoordinate(new LinkedHashSet<DataCell>(reverseList));
    m_hMargin = (int) (getDrawingPaneDimension().height * H_MARGIN_FACTOR);
    m_vMargin = (int) (getDrawingPaneDimension().width * V_MARGIN_FACTOR);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setHorizontalMargin(m_hMargin);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setVerticalMargin(m_vMargin);
    // set the offset for the column axes
    getXAxis().setStartTickOffset(m_vMargin);
    getYAxis().setStartTickOffset(m_hMargin);
    int nrOfColumns = selectedColumnCells.size();
    // and update the properties
    int width = (getDrawingPaneDimension().width - (nrOfColumns * GAP) - (2 * m_vMargin)) / nrOfColumns;
    m_matrixElementWidth = width;
    int height = (getDrawingPaneDimension().height - (nrOfColumns * GAP) - (2 * m_hMargin)) / nrOfColumns;
    int rowNr = 0;
    ScatterMatrixElement[][] matrixElements = new ScatterMatrixElement[nrOfColumns][nrOfColumns];
    for (DataRow row : data) {
        for (int i = 0; i < nrOfColumns; i++) {
            for (int j = 0; j < nrOfColumns; j++) {
                Coordinate xCoordinate = m_coordinates.get(i);
                Coordinate yCoordinate = m_coordinates.get(j);
                DataCell xValue = row.getCell(columnIndices.get(i));
                DataCell yValue = row.getCell(columnIndices.get(j));
                int x = -1;
                int y = -1;
                int xOffset = (i * (width + GAP)) + m_vMargin;
                int yOffset = (j * (height + GAP)) + m_hMargin;
                ScatterMatrixElement matrixElement = matrixElements[i][j];
                if (matrixElement == null) {
                    matrixElement = new ScatterMatrixElement(new Point(xOffset, yOffset), width, height, xCoordinate, yCoordinate);
                    matrixElements[i][j] = matrixElement;
                }
                if (!xValue.isMissing()) {
                    x = (int) xCoordinate.calculateMappedValue(xValue, width - (2 * getDotSize()), true);
                    // offset
                    x += xOffset + getDotSize();
                }
                if (!yValue.isMissing()) {
                    y = (int) (height - yCoordinate.calculateMappedValue(yValue, height - (2 * getDotSize()), true));
                    // v offset
                    y += yOffset - getDotSize();
                }
                boolean hilite = delegateIsHiLit(row.getKey());
                if (!hilite && isHideMode()) {
                    continue;
                }
                if (isHideMode() && hilite) {
                    hilite = false;
                }
                DotInfo dot = new DotInfo(x, y, row.getKey(), hilite, data.getDataTableSpec().getRowColor(row), data.getDataTableSpec().getRowSizeFactor(row), rowNr);
                dot.setShape(data.getDataTableSpec().getRowShape(row));
                dot.setXDomainValue(xValue);
                dot.setYDomainValue(yValue);
                matrixElement.addDot(dot);
            // dotList.add(dot);
            }
        // j
        }
        // i
        rowNr++;
    }
    // rows
    // jitter
    jitter(matrixElements);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setScatterMatrixElements(matrixElements);
    getDrawingPane().repaint();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) ArrayList(java.util.ArrayList) Point(java.awt.Point) DataRow(org.knime.core.data.DataRow) DataArray(org.knime.base.node.util.DataArray) Point(java.awt.Point) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 5 with DataArray

use of org.knime.base.node.util.DataArray in project knime-core by knime.

the class SotaNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
    File file = new File(internDir, TREE_FILE);
    FileInputStream fis = new FileInputStream(file);
    ModelContentRO modelContent = ModelContent.loadFromXML(fis);
    // Load settings
    int inDataSize = 0;
    int origDataSize = 0;
    try {
        m_sota.setUseHierarchicalFuzzyData(modelContent.getBoolean(SotaPortObject.CFG_KEY_USE_FUZZY_HIERARCHY));
        m_sota.setMaxHierarchicalLevel(modelContent.getInt(SotaPortObject.CFG_KEY_MAX_FUZZY_LEVEL));
        inDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_INDATA_SIZE);
        origDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_ORIGDATA_SIZE);
    } catch (InvalidSettingsException e1) {
        IOException ioe = new IOException("Could not load settings," + "due to invalid settings in model content !");
        ioe.initCause(e1);
        fis.close();
        throw ioe;
    }
    // Load in data
    DataTable table = DataContainer.readFromZip(new File(internDir, IN_DATA_FILE));
    final DataArray inData = new DefaultDataArray(table, 1, inDataSize);
    m_sota.setInData(inData);
    // Load orig data
    table = DataContainer.readFromZip(new File(internDir, ORIG_DATA_FILE));
    final DataArray origData = new DefaultDataArray(table, 1, origDataSize);
    m_sota.setOriginalData(origData);
    // Load tree
    SotaTreeCell root = new SotaTreeCell(0, false);
    try {
        root.loadFrom(modelContent, 0, null, false);
    } catch (InvalidSettingsException e) {
        IOException ioe = new IOException("Could not load tree cells," + "due to invalid settings in model content !");
        ioe.initCause(e);
        fis.close();
        throw ioe;
    }
    m_sota.setRoot(root);
    fis.close();
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) ModelContentRO(org.knime.core.node.ModelContentRO) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) DataArray(org.knime.base.node.util.DataArray)

Aggregations

DataArray (org.knime.base.node.util.DataArray)23 DataTableSpec (org.knime.core.data.DataTableSpec)8 DataRow (org.knime.core.data.DataRow)7 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)6 DataCell (org.knime.core.data.DataCell)6 Point (java.awt.Point)5 ArrayList (java.util.ArrayList)5 DataProvider (org.knime.base.node.viz.plotter.DataProvider)5 StringCell (org.knime.core.data.def.StringCell)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 Color (java.awt.Color)3 ColorAttr (org.knime.core.data.property.ColorAttr)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 FilterColumnTable (org.knime.base.data.filter.column.FilterColumnTable)2 LinearRegressionContent (org.knime.base.node.mine.regression.linear.LinearRegressionContent)2 DotInfo (org.knime.base.node.viz.plotter.scatter.DotInfo)2