Search in sources :

Example 36 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class ParallelCoordinatesPlotter method updateAxesPosition.

/**
 * Updates the x position and the height of the parallel axes.
 */
private synchronized void updateAxesPosition() {
    int width = getDrawingPaneDimension().width;
    int height = getDrawingPaneDimension().height - ParallelCoordinateDrawingPane.TOP_SPACE - ParallelCoordinateDrawingPane.BOTTOM_SPACE;
    if (getDrawingPane() instanceof ParallelCoordinateDrawingPane) {
        List<ParallelAxis> axes = ((ParallelCoordinateDrawingPane) getDrawingPane()).getAxes();
        // set the x positions
        if (axes != null) {
            for (ParallelAxis axis : axes) {
                axis.setXPosition((int) getXAxis().getCoordinate().calculateMappedValue(new StringCell(axis.getName()), width));
                axis.setHeight(height);
            }
            ((ParallelCoordinateDrawingPane) getDrawingPane()).setAxes(axes);
        }
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell) Point(java.awt.Point)

Example 37 with StringCell

use of org.knime.core.data.def.StringCell 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 38 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class DendrogramPlotter method createViewModelFor.

/**
 * Recursive method to convert the result of the hierachical clustering
 * result represented by a
 * {@link org.knime.base.node.viz.plotter.dendrogram.DendrogramNode} into a
 * {@link org.knime.base.node.viz.plotter.dendrogram.BinaryTree} of
 * {@link org.knime.base.node.viz.plotter.dendrogram.DendrogramPoint}s.
 *
 * @param node the node to convert
 * @return the visual model of the passed
 * {@link org.knime.base.node.viz.plotter.dendrogram.DendrogramNode}
 */
private BinaryTreeNode<DendrogramPoint> createViewModelFor(final DendrogramNode node) {
    if (getXAxis() == null || getXAxis().getCoordinate() == null || getYAxis() == null || getYAxis().getCoordinate() == null) {
        updatePaintModel();
    }
    BinaryTreeNode<DendrogramPoint> viewNode;
    // distinction between cluster node and leaf:
    int y = getMappedYValue(new DoubleCell(node.getDist()));
    int x;
    DendrogramPoint p;
    if (!node.isLeaf()) {
        x = getXPosition(node);
        p = new DendrogramPoint(new Point(x, y), node.getDist());
    } else {
        DataRow row = node.getLeafDataPoint();
        x = getMappedXValue(new StringCell(row.getKey().getString()));
        p = new DendrogramPoint(new Point(x, y), node.getDist());
        DataTableSpec spec = getDataProvider().getDataArray(1).getDataTableSpec();
        p.setColor(spec.getRowColor(row));
        p.setShape(spec.getRowShape(row));
        p.setRelativeSize(spec.getRowSizeFactor(row));
        p.setHilite(delegateIsHiLit(row.getKey()));
    }
    viewNode = new BinaryTreeNode<DendrogramPoint>(p);
    Set<RowKey> keys = new LinkedHashSet<RowKey>();
    getRowKeys(node, keys);
    viewNode.getContent().addRows(keys);
    viewNode.getContent().setSelected(m_selected.contains(viewNode.getContent()));
    viewNode.getContent().setHilite(delegateIsHiLit(keys));
    if (node.getFirstSubnode() != null) {
        BinaryTreeNode<DendrogramPoint> leftNode = createViewModelFor(node.getFirstSubnode());
        leftNode.setParent(viewNode);
        viewNode.setLeftChild(leftNode);
    }
    if (node.getSecondSubnode() != null) {
        BinaryTreeNode<DendrogramPoint> rightNode = createViewModelFor(node.getSecondSubnode());
        rightNode.setParent(viewNode);
        viewNode.setRightChild(rightNode);
    }
    return viewNode;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) StringCell(org.knime.core.data.def.StringCell) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) Point(java.awt.Point) DataRow(org.knime.core.data.DataRow) Point(java.awt.Point)

Example 39 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class AdapterCellTest method testAddMissingValuesViaClone.

/**
 * Checks whether we can add missing values to an adapter via
 * {@link AdapterCell#cloneAndAddAdapter(DataCell, Class...)}.
 *
 * @throws Exception if an error occurs
 */
@SuppressWarnings("unchecked")
@Test
public void testAddMissingValuesViaClone() throws Exception {
    MyAdapterCell c1 = new MyAdapterCell(new StringCell("Test"), StringValue.class);
    AdapterCell c2 = c1.cloneAndAddAdapter(new MissingCell("Something went wrong"), DoubleValue.class);
    MissingValue m2 = c2.getAdapterError(DoubleValue.class);
    assertThat("No missing value found for StringValue", m2, is(not(nullValue())));
    assertThat("Unexpected error message in missing value", m2.getError(), is("Something went wrong"));
}
Also used : StringCell(org.knime.core.data.def.StringCell) Test(org.junit.Test)

Example 40 with StringCell

use of org.knime.core.data.def.StringCell in project knime-core by knime.

the class DataTableDomainCreatorTest method testInitValues.

/**
 * Checks whether possible values are initialized correctly if requested.
 */
@Test
public void testInitValues() {
    DataColumnSpecCreator colSpecCrea = new DataColumnSpecCreator("String col", StringCell.TYPE);
    DataColumnDomainCreator domainCrea = new DataColumnDomainCreator();
    domainCrea.setValues(Collections.singleton(new StringCell("v99")));
    colSpecCrea.setDomain(domainCrea.createDomain());
    DataColumnSpec stringColSpec = colSpecCrea.createSpec();
    DataTableSpec tableSpec = new DataTableSpec(stringColSpec);
    RowKey rowKey = new RowKey("Row0");
    DataTableDomainCreator domainCreator = new DataTableDomainCreator(tableSpec, true);
    domainCreator.setMaxPossibleValues(2);
    // check initial values
    Set<DataCell> expectedValues = new LinkedHashSet<>();
    expectedValues.add(new StringCell("v99"));
    DataColumnDomain colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
    assertThat("Unexpected possible values", colDomain.getValues(), is(expectedValues));
    // add two values
    expectedValues.add(new StringCell("v1"));
    domainCreator.updateDomain(new DefaultRow(rowKey, "v1"));
    colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
    assertThat("Unexpected possible values", colDomain.getValues(), is(expectedValues));
    // check whether a initial set of more than 60 possible values is retained if no new possible values
    // appear in the data
    domainCrea = new DataColumnDomainCreator();
    Set<DataCell> initialValues = new HashSet<>();
    for (int i = 0; i < 100; i++) {
        initialValues.add(new StringCell(Integer.toString(i)));
    }
    domainCrea.setValues(initialValues);
    colSpecCrea.setDomain(domainCrea.createDomain());
    stringColSpec = colSpecCrea.createSpec();
    tableSpec = new DataTableSpec(stringColSpec);
    domainCreator = new DataTableDomainCreator(tableSpec, true);
    domainCreator.setMaxPossibleValues(60);
    // check initial values
    colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
    assertThat("Unexpected possible values", colDomain.getValues(), is(initialValues));
    // add already existing value
    domainCreator.updateDomain(new DefaultRow(rowKey, "2"));
    colDomain = domainCreator.createSpec().getColumnSpec(0).getDomain();
    assertThat("Unexpected possible values", colDomain.getValues(), is(initialValues));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringCell(org.knime.core.data.def.StringCell) DefaultRow(org.knime.core.data.def.DefaultRow) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Aggregations

StringCell (org.knime.core.data.def.StringCell)176 DataCell (org.knime.core.data.DataCell)130 DoubleCell (org.knime.core.data.def.DoubleCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)65 IntCell (org.knime.core.data.def.IntCell)55 DataRow (org.knime.core.data.DataRow)52 DataTableSpec (org.knime.core.data.DataTableSpec)49 ArrayList (java.util.ArrayList)41 DataColumnSpec (org.knime.core.data.DataColumnSpec)37 RowKey (org.knime.core.data.RowKey)36 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)26 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)26 DataType (org.knime.core.data.DataType)22 LinkedHashSet (java.util.LinkedHashSet)21 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)19 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)16 LinkedHashMap (java.util.LinkedHashMap)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)11