Search in sources :

Example 16 with DataArray

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

the class ParallelCoordinatesPlotter method updatePaintModel.

// ----------- painting ----------------
/**
 * Creates a nominal x axis with the names of the selected columns,
 * the referring
 * {@link org.knime.base.node.viz.plotter.parcoord.ParallelAxis} for each
 * column and calculates the lines with the mapped values which are passed
 * together with the axes to the
 * {@link org.knime.base.node.viz.plotter.parcoord
 * .ParallelCoordinateDrawingPane}.
 *
 * @see org.knime.base.node.viz.plotter.AbstractPlotter#updatePaintModel()
 */
@Override
public synchronized void updatePaintModel() {
    if (getDataProvider() != null && getDataProvider().getDataArray(getDataArrayIdx()) != null) {
        DataArray array = getDataProvider().getDataArray(getDataArrayIdx());
        Set<DataCell> columns = new LinkedHashSet<DataCell>();
        m_axes = new LinkedList<ParallelAxis>();
        if (m_columnNames == null) {
            initColumnNames(array);
        }
        // create the x axis
        for (String columnName : m_columnNames) {
            DataColumnSpec colSpec = array.getDataTableSpec().getColumnSpec(columnName);
            if (colSpec == null) {
                initColumnNames(array);
                updatePaintModel();
                break;
            }
            columns.add(new StringCell(colSpec.getName()));
            m_axes.add(ParallelAxis.createParallelAxis(colSpec));
        }
        createNominalXCoordinate(columns);
        if (getDrawingPane() instanceof ParallelCoordinateDrawingPane) {
            ((ParallelCoordinateDrawingPane) getDrawingPane()).setAxes(m_axes);
            updateAxesPosition();
            m_lines = calculateLines();
            ((ParallelCoordinateDrawingPane) getDrawingPane()).setLines(m_lines);
        }
        if (getProperties() instanceof MultiColumnPlotterProperties) {
            Set<String> selectedColumns = new LinkedHashSet<String>();
            selectedColumns.addAll(m_columnNames);
            ((MultiColumnPlotterProperties) getProperties()).updateColumnSelection(array.getDataTableSpec(), selectedColumns);
        }
    }
    getDrawingPane().repaint();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) MultiColumnPlotterProperties(org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties) DataArray(org.knime.base.node.util.DataArray)

Example 17 with DataArray

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

the class ScatterPlotter method calculateCoordinates.

/**
 * Given the actual size of the drawing pane, the actual zoom factor, and
 * min/max values it calculates the screen coordinates for each dot info in
 * the array passed in. It accesses the model to retrieve the actual values
 * of the rows. It changes the contents of the DotInfos passed in. It also
 * triggers resorting of the sorted lists in the dot container.
 *
 * @param dotsArray the array containing the dots.
 */
protected synchronized void calculateCoordinates(final DotInfoArray dotsArray) {
    final DataProvider provider = getDataProvider();
    if ((provider == null) || !isScatterPlotterDrawingPane()) {
        // TODO: maybe return the calculated dot info array???
        return;
    }
    if (dotsArray == null) {
        return;
    }
    DotInfo[] dots = dotsArray.getDots();
    if ((dots == null) || (dots.length == 0)) {
        return;
    }
    DataArray data = getDataProvider().getDataArray(getDataArrayIdx());
    // check whether there is a row container
    if (data == null) {
        return;
    }
    // get the coordinates from the headers
    Coordinate xCoordinate = getXAxis().getCoordinate();
    Coordinate yCoordinate = getYAxis().getCoordinate();
    // if one of the coordinates is missing returns
    if (xCoordinate == null || yCoordinate == null) {
        return;
    }
    // calculate the mapping for each domain value
    for (int i = 0; i < dots.length; i++) {
        // as the dots may have been sorted the loop index does not
        // neccessarily corresponds with the row ids any more
        // therefore the row id is retrieved from the dot info
        int rowId = dots[i].getRowIndex();
        DataRow row = data.getRow(rowId);
        DataCell xCell = row.getCell(getSelectedXColumnIndex());
        DataCell yCell = row.getCell(getSelectedYColumnIndex());
        if (!xCell.isMissing() && !yCell.isMissing()) {
            // temp variables for the coordinates
            int x = getMappedXValue(xCell);
            // need to be transformed to lower left origin later on
            // (see below)
            int y = getMappedYValue(yCell);
            // if one of the values is not a valid one set -1 for both
            if (x < 0 || y < 0) {
                dots[i].setXCoord(-1);
                dots[i].setYCoord(-1);
            } else {
                // here was the offset used
                dots[i].setXCoord(x);
                dots[i].setYCoord(y);
            }
        } else {
            // at least one coordinate is missing, set invalid screen coord
            dots[i].setXCoord(-1);
            dots[i].setYCoord(-1);
        }
    }
    if ((xCoordinate.isNominal() || yCoordinate.isNominal())) {
        if (getProperties() instanceof ScatterPlotterProperties) {
            getScatterPlotterProperties().getJitterSlider().setEnabled(true);
        }
        // the max dot size is subtracted as a dot can vary in size
        int width = getDrawingPaneDimension().width - (2 * m_dotSize);
        int height = getDrawingPaneDimension().height - (2 * m_dotSize);
        // for jittering only 90% of the available space are used
        // to avoid that the dots of different nominal values touces each
        // other
        int xAxisJitterRange = (int) (Math.round(xCoordinate.getUnusedDistBetweenTicks(width)) * 0.9);
        int yAxisJitterRange = (int) (Math.round(yCoordinate.getUnusedDistBetweenTicks(height)) * 0.9);
        jitterDots(dots, xAxisJitterRange, yAxisJitterRange);
    } else {
        // bugfix 1253
        if (getProperties() instanceof ScatterPlotterProperties) {
            getScatterPlotterProperties().getJitterSlider().setEnabled(false);
        }
    }
    getScatterPlotterDrawingPane().setDotInfoArray(new DotInfoArray(dots));
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) Coordinate(org.knime.base.util.coordinate.Coordinate) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) DataArray(org.knime.base.node.util.DataArray) Point(java.awt.Point)

Example 18 with DataArray

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

the class SotaNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
    if (!(inData[SotaNodeModel.INPORT] instanceof BufferedDataTable)) {
        throw new IllegalArgumentException("Given indata port object is " + " no BufferedDataTable!");
    }
    BufferedDataTable bdt = (BufferedDataTable) inData[SotaNodeModel.INPORT];
    final DataArray origRowContainer = new DefaultDataArray(bdt, 1, Integer.MAX_VALUE);
    DataTable dataTableToUse = bdt;
    int indexOfClassCol = -1;
    // get index of column containing class information
    indexOfClassCol = dataTableToUse.getDataTableSpec().findColumnIndex(m_classCol.getStringValue());
    m_sota.initializeTree(dataTableToUse, origRowContainer, exec, indexOfClassCol);
    m_sota.doTraining();
    if (m_withOutPort) {
        return new PortObject[] { new SotaPortObject(m_sota, dataTableToUse.getDataTableSpec(), indexOfClassCol) };
    }
    return new PortObject[] {};
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) BufferedDataTable(org.knime.core.node.BufferedDataTable) PortObject(org.knime.core.node.port.PortObject) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) DataArray(org.knime.base.node.util.DataArray)

Example 19 with DataArray

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

the class LinRegLinePlotter method updateSize.

/**
 * First calls super then adapts the regression line.
 */
@Override
public void updateSize() {
    if (getXAxis() == null || getXAxis().getCoordinate() == null || getYAxis() == null || getYAxis().getCoordinate() == null) {
        return;
    }
    super.updateSize();
    DataProvider dataProvider = getDataProvider();
    if (dataProvider == null) {
        return;
    }
    DataArray data = dataProvider.getDataArray(0);
    if (data == null) {
        return;
    }
    LinearRegressionContent params = ((LinRegDataProvider) dataProvider).getParams();
    if (params == null) {
        return;
    }
    double xMin = ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue();
    double xMax = ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue();
    String xName = getSelectedXColumn().getName();
    String[] temp = ((LinRegDataProvider) dataProvider).getLearningColumns();
    if (temp == null) {
        return;
    }
    List<String> includedCols = Arrays.asList(temp);
    if (!xName.equals(params.getTargetColumnName()) && includedCols.contains(xName)) {
        double yMin = params.getApproximationFor(xName, xMin);
        double yMax = params.getApproximationFor(xName, xMax);
        ((LinRegLineDrawingPane) getDrawingPane()).setLineFirstPoint(getMappedXValue(new DoubleCell(xMin)), getMappedYValue(new DoubleCell(yMin)));
        ((LinRegLineDrawingPane) getDrawingPane()).setLineLastPoint(getMappedXValue(new DoubleCell(xMax)), getMappedYValue(new DoubleCell(yMax)));
    }
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) DoubleCell(org.knime.core.data.def.DoubleCell) LinearRegressionContent(org.knime.base.node.mine.regression.linear.LinearRegressionContent) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataArray(org.knime.base.node.util.DataArray)

Example 20 with DataArray

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

the class LinRegLinePlotter method updatePaintModel.

/**
 * Retrieves the linear regression params, updates the column selection
 * boxes appropriately and adds the regression line to the scatterplot.
 */
@Override
public void updatePaintModel() {
    DataProvider dataProvider = getDataProvider();
    if (dataProvider == null) {
        return;
    }
    DataArray data = dataProvider.getDataArray(0);
    if (data == null) {
        return;
    }
    LinearRegressionContent params = ((LinRegDataProvider) dataProvider).getParams();
    if (params == null) {
        return;
    }
    // set the target column to fix
    ((LinRegLinePlotterProperties) getProperties()).setTargetColumn(params.getTargetColumnName());
    // get the included columns
    String[] includedCols = ((LinRegDataProvider) dataProvider).getLearningColumns();
    if (includedCols == null) {
        return;
    }
    ((LinRegLinePlotterProperties) getProperties()).setIncludedColumns(includedCols);
    // update the combo boxes
    DataTableSpec spec = data.getDataTableSpec();
    ((LinRegLinePlotterProperties) getProperties()).update(spec);
    super.updatePaintModel();
    double xMin = ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue();
    double xMax = ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue();
    String xName = getSelectedXColumn().getName();
    List<String> includedList = Arrays.asList(includedCols);
    if (!xName.equals(params.getTargetColumnName()) && includedList.contains(xName)) {
        double yMin = params.getApproximationFor(xName, xMin);
        double yMax = params.getApproximationFor(xName, xMax);
        ((LinRegLineDrawingPane) getDrawingPane()).setLineFirstPoint(getMappedXValue(new DoubleCell(xMin)), getMappedYValue(new DoubleCell(yMin)));
        ((LinRegLineDrawingPane) getDrawingPane()).setLineLastPoint(getMappedXValue(new DoubleCell(xMax)), getMappedYValue(new DoubleCell(yMax)));
        getDrawingPane().repaint();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataArray(org.knime.base.node.util.DataArray) DataProvider(org.knime.base.node.viz.plotter.DataProvider) LinearRegressionContent(org.knime.base.node.mine.regression.linear.LinearRegressionContent)

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