Search in sources :

Example 26 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class SizeManager2NodeModel method createSizeHandler.

/**
 * Create SizeHandler based on given DataColumnSpec.
 * @param cspec spec with minimum and maximum bound
 * @return SizeHandler
 */
private SizeHandler createSizeHandler(final DataColumnSpec cspec) {
    // get the domain range for the double size handler
    double minimum = ((DoubleValue) cspec.getDomain().getLowerBound()).getDoubleValue();
    double maximum = ((DoubleValue) cspec.getDomain().getUpperBound()).getDoubleValue();
    return new SizeHandler(new SizeModelDouble(minimum, maximum, m_factor.getDoubleValue(), SizeModelDouble.Mapping.valueOf(m_mapping.getStringValue())));
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) SizeHandler(org.knime.core.data.property.SizeHandler) SizeModelDouble(org.knime.core.data.property.SizeModelDouble)

Example 27 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class AscendingNumericTickPolicyStrategy method makeTicks.

private Double[] makeTicks(final double min, final double max, final int count) {
    double minimum = Math.min(min, max);
    minimum = (minimum <= Double.NEGATIVE_INFINITY ? -Double.MAX_VALUE : minimum);
    double maximum = Math.max(min, max);
    maximum = (maximum >= Double.POSITIVE_INFINITY ? Double.MAX_VALUE : maximum);
    if (count == 1) {
        return new Double[] { (minimum + maximum) / 2 };
    }
    // so step is <= Double.MAX_VALUE
    double step = Math.log10((maximum - minimum) / count);
    double base = Math.floor(step);
    double frac = step - base;
    if (minimum == maximum || Double.isInfinite(step) || Double.isNaN(step) || Double.isInfinite(base) || Double.isNaN(base) || Double.isInfinite(frac) || Double.isNaN(frac)) {
        return new Double[] { (minimum + maximum) / 2 };
    }
    ArrayList<Double> result = new ArrayList<Double>();
    if (frac < 0.1) {
        frac = 1;
    } else if (frac < 0.4) {
        frac = 2;
    } else if (frac < 0.6) {
        frac = 2.5;
    } else if (frac < 0.8) {
        frac = 5;
    } else {
        frac = 1;
        base += frac;
    }
    step = frac * Math.pow(10, base);
    double value = minimum;
    while (value + 0.55 * step < maximum) {
        if (result.size() == 0 || result.get(result.size() - 1) + EPSILON * step < value) {
            boolean add = true;
            for (DataValue v : getValues()) {
                if (v instanceof DoubleValue) {
                    double desVal = ((DoubleValue) v).getDoubleValue();
                    if (value + EPSILON * step > desVal && value < desVal) {
                        add = false;
                    } else if (value - EPSILON * step < desVal && value > desVal) {
                        add = false;
                    }
                }
            }
            if (add) {
                result.add(value);
            }
        }
        int m = 1;
        while (value + m * step == value) {
            m++;
        }
        value += m * step;
    }
    if (result.get(result.size() - 1) < maximum) {
        // enough space?
        if (result.get(result.size() - 1) + EPSILON * step > maximum) {
            result.remove(result.size() - 1);
        }
        result.add(maximum);
    }
    for (DataValue v : getValues()) {
        if (v instanceof DoubleValue) {
            double val = ((DoubleValue) v).getDoubleValue();
            if (!result.contains(val) && val > minimum && val < maximum) {
                result.add(val);
            }
        }
    }
    Collections.sort(result);
    return result.toArray(new Double[0]);
}
Also used : DataValue(org.knime.core.data.DataValue) DoubleValue(org.knime.core.data.DoubleValue) ArrayList(java.util.ArrayList)

Example 28 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class IntervalBinCreator method createBins.

/**
 * @param colSpec the column specification
 * @param numberOfBins the number of bins to create
 * @return the created bins
 */
public List<E> createBins(final DataColumnSpec colSpec, final int numberOfBins) {
    // set the bounds for binning
    final DataColumnDomain domain = colSpec.getDomain();
    final DataCell lowerBoundCell = domain.getLowerBound();
    if (lowerBoundCell == null || lowerBoundCell.isMissing() || !lowerBoundCell.getType().isCompatible(DoubleValue.class)) {
        throw new IllegalArgumentException("The lower bound of the binning column domain " + "should be defined");
    }
    final double lowerBound = ((DoubleValue) lowerBoundCell).getDoubleValue();
    final DataCell upperBoundCell = domain.getUpperBound();
    if (upperBoundCell == null || upperBoundCell.isMissing() || !upperBoundCell.getType().isCompatible(DoubleValue.class)) {
        throw new IllegalArgumentException("The upper bound of the binning column domain " + "should be defined");
    }
    final double upperBound = ((DoubleValue) upperBoundCell).getDoubleValue();
    int noOfBins = numberOfBins;
    // start the binning
    if (noOfBins < 1) {
        noOfBins = AbstractHistogramVizModel.DEFAULT_NO_OF_BINS;
    }
    if ((lowerBound - upperBound) == 0) {
        noOfBins = 1;
    }
    final boolean isInteger = colSpec.getType().isCompatible(LongValue.class);
    double binInterval = BinningUtil.createBinInterval(upperBound, lowerBound, noOfBins, isInteger);
    final double calculatedLowerBound = BinningUtil.createBinStart(lowerBound, binInterval, isInteger);
    if (calculatedLowerBound != lowerBound) {
        binInterval = BinningUtil.createBinInterval(upperBound, calculatedLowerBound, noOfBins, isInteger);
    }
    double leftBoundary = calculatedLowerBound;
    final double lastBoundary = BinningUtil.myRoundedBorders(upperBound, binInterval, AbstractHistogramVizModel.INTERVAL_DIGITS, isInteger);
    // increase bin interval if we have rounding problems
    while (leftBoundary + (binInterval * noOfBins) < lastBoundary) {
        binInterval = binInterval + binInterval * 0.001;
    }
    boolean firstBar = true;
    createList(noOfBins);
    for (int i = 0; i < noOfBins; i++) {
        // I have to use this rounding method to avoid problems with very
        // small intervals. If the interval is very small it could happen
        // that we get the same boundaries for several bars by rounding the
        // borders
        double rightBoundary;
        if (isInteger && binInterval == 1) {
            rightBoundary = leftBoundary;
        } else {
            rightBoundary = BinningUtil.myRoundedBorders(leftBoundary + binInterval, binInterval, AbstractHistogramVizModel.INTERVAL_DIGITS, isInteger);
        }
        final String binCaption = BinningUtil.createBarName(firstBar, leftBoundary, rightBoundary);
        firstBar = false;
        addBin(binCaption, leftBoundary, rightBoundary);
        // boundary
        if (isInteger && binInterval == 1) {
            leftBoundary = rightBoundary + binInterval;
        } else {
            leftBoundary = rightBoundary;
        }
    }
    return getBins();
}
Also used : DataColumnDomain(org.knime.core.data.DataColumnDomain) DoubleValue(org.knime.core.data.DoubleValue) DataCell(org.knime.core.data.DataCell)

Example 29 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class Axis method createToolTip.

private String createToolTip(final CoordinateMapping coordMapping) {
    String tooltip = "";
    for (DataValue v : coordMapping.getValues()) {
        if (v == null) {
            continue;
        }
        if (v instanceof DoubleValue) {
            double value = ((DoubleValue) v).getDoubleValue();
            if (Double.isNaN(value) || Double.isInfinite(value)) {
                continue;
            }
            tooltip += new BigDecimal(value, new MathContext(25)) + " ";
        } else {
            tooltip += v.toString() + " ";
        }
    }
    return tooltip.trim();
}
Also used : DataValue(org.knime.core.data.DataValue) DoubleValue(org.knime.core.data.DoubleValue) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext)

Example 30 with DoubleValue

use of org.knime.core.data.DoubleValue in project knime-core by knime.

the class BasicPlotter method interpolateLine.

private List<Point> interpolateLine(final BasicDrawingElement line, final boolean x, final boolean y) {
    // add points between every two points
    List<Point> newPoints = new ArrayList<Point>();
    List<DataCellPoint> domainValues = line.getDomainValues();
    for (int i = 0; i < domainValues.size() - 1; i++) {
        DoubleValue x1 = (DoubleValue) domainValues.get(i).getX();
        DoubleValue y1 = (DoubleValue) domainValues.get(i).getY();
        DoubleValue x2 = (DoubleValue) domainValues.get(i + 1).getX();
        DoubleValue y2 = (DoubleValue) domainValues.get(i + 1).getY();
        // computed unmapped deltas and distance for calculating the
        // interpolation points below
        double unmappedDeltaX = x2.getDoubleValue() - x1.getDoubleValue();
        double unmappedDeltaY = y2.getDoubleValue() - y1.getDoubleValue();
        double unmappedDistance = Math.sqrt((unmappedDeltaX * unmappedDeltaX) + (unmappedDeltaY * unmappedDeltaY));
        // computed mapped distance for determining the number of
        // interpolation points
        double mappedDeltaX = getMappedXValue((DataCell) x2) - getMappedXValue((DataCell) x1);
        double mappedDeltaY = getMappedYValue((DataCell) y2) - getMappedYValue((DataCell) y1);
        double mappedDistance = Math.sqrt((mappedDeltaX * mappedDeltaX) + (mappedDeltaY * mappedDeltaY));
        // compute at least 10 interpolation points, just to be on the safe
        // side
        mappedDistance = Math.max(10, mappedDistance);
        for (int j = 0; j <= mappedDistance; j += 1) {
            double newX = x1.getDoubleValue() + (unmappedDeltaX / unmappedDistance) * j;
            double newY = y1.getDoubleValue() + (unmappedDeltaY / unmappedDistance) * j;
            // either x or Y
            if (x && newX < 1.0) {
                continue;
            }
            if (y && newY < 1.0) {
                continue;
            }
            newX = getMappedXValue(new DoubleCell(newX));
            newY = getMappedYValue(new DoubleCell(newY));
            newPoints.add(new Point((int) newX, (int) newY));
        }
    }
    return newPoints;
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) DataCell(org.knime.core.data.DataCell) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

DoubleValue (org.knime.core.data.DoubleValue)154 DataCell (org.knime.core.data.DataCell)103 DataRow (org.knime.core.data.DataRow)71 DataColumnSpec (org.knime.core.data.DataColumnSpec)38 DataTableSpec (org.knime.core.data.DataTableSpec)38 DoubleCell (org.knime.core.data.def.DoubleCell)32 ArrayList (java.util.ArrayList)26 BufferedDataTable (org.knime.core.node.BufferedDataTable)26 DataType (org.knime.core.data.DataType)23 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)21 LinkedHashMap (java.util.LinkedHashMap)18 IntValue (org.knime.core.data.IntValue)15 HashMap (java.util.HashMap)14 RowIterator (org.knime.core.data.RowIterator)14 RowKey (org.knime.core.data.RowKey)13 DefaultRow (org.knime.core.data.def.DefaultRow)13 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 LongValue (org.knime.core.data.LongValue)10 StringValue (org.knime.core.data.StringValue)10 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)10