Search in sources :

Example 11 with NumericCoordinate

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

Example 12 with NumericCoordinate

use of org.knime.base.util.coordinate.NumericCoordinate in project knime-core by knime.

the class ScatterPlotter method setXColumn.

/**
 * Sets new x columns and recalculates/repaints.
 *
 * @param xColName name of the new x column to plot
 */
public void setXColumn(final String xColName) {
    setXColName(xColName);
    // tell the headers to display the new column names
    getColHeader().setToolTipText(getXColName());
    // check if the column names set so far are valid
    // this check also checks the y axis
    // if invalid a boolean flag is set in the method for later use
    checkColumns();
    if (m_rowContainer == null) {
        return;
    }
    DataTableSpec tSpec = m_rowContainer.getDataTableSpec();
    int idx = tSpec.findColumnIndex(getXColName());
    if (idx >= 0) {
        Coordinate xCoordinate = Coordinate.createCoordinate(tSpec.getColumnSpec(idx));
        if (xCoordinate == null) {
            m_xIndex = -1;
        } else {
            // check whether the bounds are set properly
            if (!xCoordinate.isNominal()) {
                if (!((NumericCoordinate) xCoordinate).isMinDomainValueSet()) {
                    ((NumericCoordinate) xCoordinate).setMinDomainValue(getXmin());
                }
                if (!((NumericCoordinate) xCoordinate).isMaxDomainValueSet()) {
                    ((NumericCoordinate) xCoordinate).setMaxDomainValue(getXmax());
                }
            }
            getColHeader().setCoordinate(xCoordinate);
            m_xIndex = idx;
        }
    } else {
        // set -1 to indicate an invalid column index
        m_xIndex = -1;
    }
    // redo everything if two columns are available
    if (!m_invalidColumn) {
        updateDotsAndPaint();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate)

Aggregations

NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)12 Coordinate (org.knime.base.util.coordinate.Coordinate)8 DoubleCell (org.knime.core.data.def.DoubleCell)7 DataProvider (org.knime.base.node.viz.plotter.DataProvider)4 DataTableSpec (org.knime.core.data.DataTableSpec)4 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)3 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)3 Point (java.awt.Point)2 RegressionContent (org.knime.base.node.mine.regression.RegressionContent)2 LinearRegressionContent (org.knime.base.node.mine.regression.linear.LinearRegressionContent)2 DataArray (org.knime.base.node.util.DataArray)2 Dimension (java.awt.Dimension)1 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)1 IntCell (org.knime.core.data.def.IntCell)1