Search in sources :

Example 11 with Coordinate

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

the class BoxPlotter method createNormalizedCoordinates.

/**
 * @param statistics
 */
protected void createNormalizedCoordinates(final Map<DataColumnSpec, double[]> statistics) {
    m_coordinates = new LinkedHashMap<DataColumnSpec, Coordinate>();
    for (DataColumnSpec colSpec : statistics.keySet()) {
        m_coordinates.put(colSpec, Coordinate.createCoordinate(colSpec));
    }
    // hack to achieve an empty y axis
    createNominalYCoordinate(new LinkedHashSet<DataCell>());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) DataCell(org.knime.core.data.DataCell)

Example 12 with Coordinate

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

the class ConditionalBoxPlotter method createNormalizedCoordinates.

/**
 * {@inheritDoc}
 */
@Override
protected void createNormalizedCoordinates(final Map<DataColumnSpec, double[]> statistics) {
    // create y-axis that consider the input domain
    Map<DataColumnSpec, Coordinate> coordinates = new LinkedHashMap<DataColumnSpec, Coordinate>();
    for (DataColumnSpec colSpec : statistics.keySet()) {
        /*
             * Pass the input domain's min and max values of the numerical
             * column to all box plots by providing the column spec of the
             * numerical column to all box plots. In this way they all use the
             * same scale and the whole domain range is displayed.
             */
        coordinates.put(colSpec, Coordinate.createCoordinate(colSpec));
    }
    setCoordinates(coordinates);
    /*DataColumnDomain domain = numColSpec.getDomain();
        double min = ((DoubleValue)domain.getLowerBound()).getDoubleValue();
        double max = ((DoubleValue)domain.getUpperBound()).getDoubleValue();
        createYCoordinate(min, max);*/
    // hack to achieve an empty y axis
    createNominalYCoordinate(new LinkedHashSet<DataCell>());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) DataCell(org.knime.core.data.DataCell) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with Coordinate

use of org.knime.base.util.coordinate.Coordinate 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 14 with Coordinate

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

the class Rule2DPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
protected void updatePaintModel() {
    super.updatePaintModel();
    if (m_rules != null) {
        Rule2DDrawingPane drawingPane = getDrawingPane();
        drawingPane.setOriginalRuleTable(m_rules);
        String xName = getXColName();
        String yName = getYColName();
        int xIdx = -1;
        int yIdx = -1;
        if (xName != null && yName != null) {
            xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
            yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
        }
        if (xIdx >= 0 && yIdx >= 0) {
            Coordinate x = getColHeader().getCoordinate();
            Coordinate y = getRowHeader().getCoordinate();
            // check if the coordinates are valid
            if (x == null || y == null) {
                return;
            }
            // calculate the coordinates of the rules here
            // List<DataRow> rows = new ArrayList<DataRow>();
            DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
            DataColumnSpec col1 = creator.createSpec();
            creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
            DataColumnSpec col2 = creator.createSpec();
            DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
            DataContainer rows = new DataContainer(spec);
            for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
                DataRow currRow = itr.next();
                DataCell[] newCells = new DataCell[2];
                for (int cell = 0; cell < currRow.getNumCells(); cell++) {
                    // if (!m_rules.getDataTableSpec().getColumnSpec(cell)
                    // .getType().isCompatible(
                    // FuzzyIntervalValue.class)) {
                    // continue;
                    // }
                    Rectangle rect = calculateDrawingRectangle();
                    double a;
                    double b;
                    double c;
                    double d;
                    if (cell == xIdx) {
                        if (currRow.getCell(cell).isMissing()) {
                            // normalize xValues
                            a = getXmin();
                            b = getXmin();
                            c = getXmax();
                            d = getXmax();
                        } else {
                            // normalize xValues
                            a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
                            b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
                            c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
                            d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
                        }
                        double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
                        double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
                        double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
                        double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
                        DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
                        newCells[0] = newInterval;
                    }
                    if (cell == yIdx) {
                        if (currRow.getCell(cell).isMissing()) {
                            a = getYmin();
                            b = getYmin();
                            c = getYmax();
                            d = getYmax();
                        } else {
                            // normalize yValues
                            a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
                            b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
                            c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
                            d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
                        }
                        double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
                        double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
                        double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
                        double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
                        DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
                        newCells[1] = newInterval;
                    }
                }
                // create new row out of the normalized cells
                rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
            }
            rows.close();
            drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
        }
        super.updatePaintModel();
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) Rectangle(java.awt.Rectangle) DataRow(org.knime.core.data.DataRow) FuzzyIntervalCell(org.knime.core.data.def.FuzzyIntervalCell) DataContainer(org.knime.core.data.container.DataContainer) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 15 with Coordinate

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

Aggregations

Coordinate (org.knime.base.util.coordinate.Coordinate)26 NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)17 Point (java.awt.Point)8 DataCell (org.knime.core.data.DataCell)8 DataColumnSpec (org.knime.core.data.DataColumnSpec)8 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)7 DoubleCell (org.knime.core.data.def.DoubleCell)7 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)6 Axis (org.knime.base.node.viz.plotter.Axis)4 DataRow (org.knime.core.data.DataRow)4 ArrayList (java.util.ArrayList)3 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)3 DotInfo (org.knime.base.node.viz.plotter.scatter.DotInfo)3 DataTableSpec (org.knime.core.data.DataTableSpec)3 StringCell (org.knime.core.data.def.StringCell)3 Dimension (java.awt.Dimension)2 Rectangle (java.awt.Rectangle)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 DataArray (org.knime.base.node.util.DataArray)2