Search in sources :

Example 6 with NumericCoordinate

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

the class ParallelAxis method createParallelAxis.

/**
 * Factory method to get an instance of a <code>ParallelAxis</code>.
 * Determines whether a
 * {@link org.knime.base.node.viz.plotter.parcoord.NumericParallelAxis} or
 * a {@link org.knime.base.node.viz.plotter.parcoord.NominalParallelAxis}
 * should be returned, based on the passed
 * {@link org.knime.core.data.DataColumnSpec}.
 *
 * @param colSpec the column spec for this parallel axis.
 * @return either a nominal or a numeric parallel axis based on the column
 * spec.
 * @see Coordinate
 */
public static ParallelAxis createParallelAxis(final DataColumnSpec colSpec) {
    Coordinate coordinate = Coordinate.createCoordinate(colSpec);
    ParallelAxis axis;
    if (coordinate instanceof NumericCoordinate) {
        axis = new NumericParallelAxis();
    } else {
        axis = new NominalParallelAxis();
    }
    axis.setName(colSpec.getName());
    axis.setCoordinate(coordinate);
    return axis;
}
Also used : Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate)

Example 7 with NumericCoordinate

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

the class AbstractPlotter method createXCoordinate.

/**
 * Recalculates the domain of the x axis. If preserve is set to false the
 * passed values are taken as min and max no matter was was set before. If
 * preserve is set to true (default) the possibly already available min and
 * max values are preserved.
 *
 * @param min the min value
 * @param max the max value {@link AbstractPlotter#setPreserve(boolean)}
 */
public void createXCoordinate(final int min, final int max) {
    DataColumnDomainCreator xDomainCreator = new DataColumnDomainCreator();
    int actualMin = min;
    int actualMax = max;
    if (getXAxis() != null && getXAxis().getCoordinate() != null && m_preserve) {
        if (!(getXAxis().getCoordinate() instanceof NumericCoordinate)) {
            return;
        }
        actualMin = (int) Math.min(min, ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue());
        actualMax = (int) Math.max(max, ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue());
    }
    xDomainCreator.setLowerBound(new IntCell(actualMin));
    xDomainCreator.setUpperBound(new IntCell(actualMax));
    DataColumnSpecCreator xSpecCreator = new DataColumnSpecCreator("X", IntCell.TYPE);
    xSpecCreator.setDomain(xDomainCreator.createDomain());
    Coordinate xCoordinate = Coordinate.createCoordinate(xSpecCreator.createSpec());
    if (getXAxis() == null) {
        Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
        setXAxis(xAxis);
    }
    getXAxis().setCoordinate(xCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) Point(java.awt.Point) IntCell(org.knime.core.data.def.IntCell)

Example 8 with NumericCoordinate

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

the class LinReg2LinePlotter 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;
    }
    RegressionContent content = ((LinReg2DataProvider) dataProvider).getLinRegContent();
    if (content == null) {
        return;
    }
    List<String> includedList = content.getCovariates();
    String target = content.getSpec().getTargetCols().get(0).getName();
    // set the target column to fix
    ((LinReg2LinePlotterProperties) getProperties()).setTargetColumn(target);
    // get the included columns
    ((LinReg2LinePlotterProperties) getProperties()).setIncludedColumns(includedList.toArray(new String[includedList.size()]));
    // update the combo boxes
    DataTableSpec spec = getDataProvider().getDataArray(0).getDataTableSpec();
    ((LinReg2LinePlotterProperties) getProperties()).update(spec);
    super.updatePaintModel();
    double xMin = ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue();
    double xMax = ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue();
    String xName = getSelectedXColumn().getName();
    if (!xName.equals(target) && includedList.contains(xName)) {
        double yMin = getApproximationFor(xName, xMin, content);
        double yMax = getApproximationFor(xName, xMax, content);
        ((LinReg2LineDrawingPane) getDrawingPane()).setLineFirstPoint(getMappedXValue(new DoubleCell(xMin)), getMappedYValue(new DoubleCell(yMin)));
        ((LinReg2LineDrawingPane) getDrawingPane()).setLineLastPoint(getMappedXValue(new DoubleCell(xMax)), getMappedYValue(new DoubleCell(yMax)));
        getDrawingPane().repaint();
    }
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) RegressionContent(org.knime.base.node.mine.regression.RegressionContent) DataTableSpec(org.knime.core.data.DataTableSpec) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate)

Example 9 with NumericCoordinate

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

the class LinReg2LinePlotter 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;
    }
    RegressionContent content = ((LinReg2DataProvider) dataProvider).getLinRegContent();
    if (content == null) {
        return;
    }
    double xMin = ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue();
    double xMax = ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue();
    String xName = getSelectedXColumn().getName();
    List<String> includedList = content.getCovariates();
    String target = content.getSpec().getTargetCols().get(0).getName();
    if (!xName.equals(target) && includedList.contains(xName)) {
        double yMin = getApproximationFor(xName, xMin, content);
        double yMax = getApproximationFor(xName, xMax, content);
        ((LinReg2LineDrawingPane) getDrawingPane()).setLineFirstPoint(getMappedXValue(new DoubleCell(xMin)), getMappedYValue(new DoubleCell(yMin)));
        ((LinReg2LineDrawingPane) getDrawingPane()).setLineLastPoint(getMappedXValue(new DoubleCell(xMax)), getMappedYValue(new DoubleCell(yMax)));
    }
}
Also used : DataProvider(org.knime.base.node.viz.plotter.DataProvider) RegressionContent(org.knime.base.node.mine.regression.RegressionContent) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate)

Example 10 with NumericCoordinate

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

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