Search in sources :

Example 1 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 double min, final double max) {
    DataColumnDomainCreator xDomainCreator = new DataColumnDomainCreator();
    double actualMin = min;
    double actualMax = max;
    if (getXAxis() != null && getXAxis().getCoordinate() != null && m_preserve) {
        if (!(getXAxis().getCoordinate() instanceof NumericCoordinate)) {
            return;
        }
        actualMin = Math.min(min, ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue());
        actualMax = Math.max(max, ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue());
    }
    xDomainCreator.setLowerBound(new DoubleCell(actualMin));
    xDomainCreator.setUpperBound(new DoubleCell(actualMax));
    DataColumnSpecCreator xSpecCreator = new DataColumnSpecCreator("X", DoubleCell.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) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 2 with NumericCoordinate

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

the class AbstractPlotter method createYCoordinate.

/**
 * Recalculates the domain of the y 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 createYCoordinate(final double min, final double max) {
    DataColumnDomainCreator yDomainCreator = new DataColumnDomainCreator();
    double actualMin = min;
    double actualMax = max;
    if (getYAxis() != null && getYAxis().getCoordinate() != null && m_preserve) {
        if (!(getYAxis().getCoordinate() instanceof NumericCoordinate)) {
            return;
        }
        actualMin = Math.min(min, ((NumericCoordinate) getYAxis().getCoordinate()).getMinDomainValue());
        actualMax = Math.max(max, ((NumericCoordinate) getYAxis().getCoordinate()).getMaxDomainValue());
    }
    yDomainCreator.setLowerBound(new DoubleCell(actualMin));
    yDomainCreator.setUpperBound(new DoubleCell(actualMax));
    DataColumnSpecCreator ySpecCreator = new DataColumnSpecCreator("Y", DoubleCell.TYPE);
    ySpecCreator.setDomain(yDomainCreator.createDomain());
    Coordinate yCoordinate = Coordinate.createCoordinate(ySpecCreator.createSpec());
    if (getYAxis() == null) {
        Axis yAxis = new Axis(Axis.VERTICAL, getDrawingPaneDimension().height);
        setYAxis(yAxis);
    }
    getYAxis().setCoordinate(yCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 3 with NumericCoordinate

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

the class TwoColumnProperties method updateRangeSpinner.

/**
 * Updates the values of the range spinner acording to the current
 * columns.
 *
 * @param xColumn selected x column
 * @param yColumn selected y column
 */
protected void updateRangeSpinner(final DataColumnSpec xColumn, final DataColumnSpec yColumn) {
    Coordinate xCoordinate = Coordinate.createCoordinate(xColumn);
    Coordinate yCoordinate = Coordinate.createCoordinate(yColumn);
    if (xCoordinate == null || xCoordinate.isNominal()) {
        // disable: no ranges
        m_xMinSpinner.setEnabled(false);
        m_xMaxSpinner.setEnabled(false);
    } else {
        // enable
        m_xMinSpinner.setEnabled(true);
        m_xMaxSpinner.setEnabled(true);
        // get min and max values
        double xMin = ((NumericCoordinate) xCoordinate).getMinDomainValue();
        double xMax = ((NumericCoordinate) xCoordinate).getMaxDomainValue();
        // set them
        m_xMinSpinner.setValue(xMin);
        m_xMaxSpinner.setValue(xMax);
    }
    if (yCoordinate == null || yCoordinate.isNominal()) {
        // disable: no ranges
        m_yMinSpinner.setEnabled(false);
        m_yMaxSpinner.setEnabled(false);
    } else {
        // enable
        m_yMinSpinner.setEnabled(true);
        m_yMaxSpinner.setEnabled(true);
        // get min and max values
        double yMin = ((NumericCoordinate) yCoordinate).getMinDomainValue();
        double yMax = ((NumericCoordinate) yCoordinate).getMaxDomainValue();
        // set them
        m_yMinSpinner.setValue(yMin);
        m_yMaxSpinner.setValue(yMax);
    }
}
Also used : Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate)

Example 4 with NumericCoordinate

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

the class ScatterPlotter method setYColumn.

/**
 * Sets new y columns and recalculates/repaints.
 *
 * @param yColName name of the new y column to plot
 */
public void setYColumn(final String yColName) {
    setYColName(yColName);
    // tell the headers to display the new column names
    getRowHeader().setToolTipText(getYColName());
    // 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();
    // set the chosen column specs via a coordinate into the
    // axis headers
    int idx = tSpec.findColumnIndex(getYColName());
    if (idx >= 0) {
        Coordinate yCoordinate = Coordinate.createCoordinate(tSpec.getColumnSpec(idx));
        if (yCoordinate == null) {
            m_yIndex = -1;
        } else {
            // check whether the bounds are set properly
            if (!yCoordinate.isNominal()) {
                if (!((NumericCoordinate) yCoordinate).isMinDomainValueSet()) {
                    ((NumericCoordinate) yCoordinate).setMinDomainValue(getYmin());
                }
                if (!((NumericCoordinate) yCoordinate).isMaxDomainValueSet()) {
                    ((NumericCoordinate) yCoordinate).setMaxDomainValue(getYmax());
                }
            }
            getRowHeader().setCoordinate(yCoordinate);
            m_yIndex = idx;
        }
    } else {
        // set -1 to indicate an invalid column index
        m_yIndex = -1;
    }
    // redo everything
    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)

Example 5 with NumericCoordinate

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

the class AbstractHistogramPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
public void updatePaintModel() {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    final Coordinate xCoordinates = getXCoordinate();
    final Coordinate yCoordinates = getAggregationCoordinate();
    final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    setHistogramBinRectangle(vizModel, xCoordinates, yCoordinates);
    final double drawingHeight = drawingSpace.getHeight();
    if (!yCoordinates.isNominal() && ((NumericCoordinate) yCoordinates).getMinDomainValue() < 0) {
        final int baseLine = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(0), drawingHeight));
        drawingPane.setBaseLine(Integer.valueOf(baseLine));
    } else {
        drawingPane.setBaseLine(null);
    }
    if (vizModel.isShowGridLines()) {
        final int[] gridLines = getGridLineCoordinates(yCoordinates, drawingHeight);
        drawingPane.setGridLines(gridLines);
    } else {
        drawingPane.setGridLines(null);
    }
    // update the properties panel as well since something could have changed
    drawingPane.setHistogramVizModel(vizModel, true);
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) Dimension(java.awt.Dimension) Point(java.awt.Point)

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