Search in sources :

Example 96 with DoubleValue

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

the class NumericCoordinate method getMaxDomainValue.

/**
 * @return Returns the maxDomainValue.
 */
public final double getMaxDomainValue() {
    DataCell cell = new DoubleCell(m_maxDomainValue);
    cell = applyMappingMethod(cell);
    return ((DoubleValue) cell).getDoubleValue();
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell)

Example 97 with DoubleValue

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

the class NumericCoordinate method getMinDomainValue.

/**
 * @return Returns the minDomainValue.
 */
public final double getMinDomainValue() {
    DataCell cell = new DoubleCell(m_minDomainValue);
    cell = applyMappingMethod(cell);
    return ((DoubleValue) cell).getDoubleValue();
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell)

Example 98 with DoubleValue

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

the class NumericCoordinate method getTickPositionsWithLabels.

/**
 * Returns an array with the positions of all ticks and their corresponding
 * domain values given an absolute length. The pre-specified tick policy
 * also influences the tick positions, e.g. ascending or descending.
 *
 * @param absolutLength the absolute length the domain is mapped on
 *
 * @return the mapping of tick positions and corresponding domain values
 */
@Override
protected CoordinateMapping[] getTickPositionsWithLabels(final double absolutLength) {
    CoordinateMapping[] coordMap = getTickPositionsInternal(absolutLength);
    if (coordMap == null || coordMap.length < 1 || getActiveMappingMethod() == null || getCurrentPolicy() == null || !getCurrentPolicy().isMappingAllowed()) {
        return coordMap;
    }
    CoordinateMapping[] result = new CoordinateMapping[coordMap.length];
    int index = 0;
    for (CoordinateMapping cm : coordMap) {
        // each numeric coordinate must have exactly one value per tick
        // and each tick a numeric value ( = DoubleValue ) set.
        DoubleValue value = (DoubleValue) cm.getValues()[0];
        double val = getActiveMappingMethod().getLabel(new DoubleCell(value.getDoubleValue()));
        result[index++] = new DoubleCoordinateMapping("" + val, val, cm.getMappingValue());
    }
    return result;
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell)

Example 99 with DoubleValue

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

the class BasicPlotter method addLine.

/**
 * Plots the column in the table specified by the column index as a
 * line plot.
 *
 * @param table the table containing the data to be plotted.
 * @param xIdx - the x column index specifying the data to be plotted.
 * @param yIdx - the x column index specifying the data to be plotted.
 * @param color the color of the line (may be null)
 * @param stroke the stroke of the line (may be null)
 */
public void addLine(final DataArray table, final int xIdx, final int yIdx, final Color color, final Stroke stroke) {
    if (!(getDrawingPane() instanceof BasicDrawingPane)) {
        return;
    }
    if (!table.getDataTableSpec().getColumnSpec(yIdx).getType().isCompatible(DoubleValue.class)) {
        return;
    }
    // if (!checkCompatibleAxis()) {
    // return;
    // }
    // x axis
    DataColumnSpec xColSpec = table.getDataTableSpec().getColumnSpec(xIdx);
    if (xColSpec.getType().isCompatible(NominalValue.class)) {
        Set<DataCell> rowKeys = new LinkedHashSet<DataCell>();
        for (int i = 0; i < table.size(); i++) {
            rowKeys.add(new StringCell(table.getRow(i).getKey().getString()));
        }
        createNominalXCoordinate(rowKeys);
    } else if (xColSpec.getType().isCompatible(DoubleValue.class)) {
        double newXMin = ((DoubleValue) xColSpec.getDomain().getLowerBound()).getDoubleValue();
        double newXMax = ((DoubleValue) xColSpec.getDomain().getUpperBound()).getDoubleValue();
        createXCoordinate(newXMin, newXMax);
    } else {
        return;
    }
    double newYMin = ((DoubleValue) table.getDataTableSpec().getColumnSpec(yIdx).getDomain().getLowerBound()).getDoubleValue();
    double newYMax = ((DoubleValue) table.getDataTableSpec().getColumnSpec(yIdx).getDomain().getUpperBound()).getDoubleValue();
    createYCoordinate(newYMin, newYMax);
    BasicLine line = new BasicLine();
    if (color != null) {
        line.setColor(color);
    }
    if (stroke != null) {
        line.setStroke(stroke);
    }
    // int x = 0;
    for (DataRow row : table) {
        DataCell value = row.getCell(yIdx);
        if (!value.isMissing()) {
            int mappedX = getMappedXValue(row.getCell(xIdx));
            int mappedY = getMappedYValue(value);
            DataCellPoint domainPoint = new DataCellPoint(row.getCell(xIdx), value);
            line.addDomainValue(domainPoint);
            Point p = new Point(mappedX, mappedY);
            line.addPoint(p);
        } else {
            // if value.isMissing() -> create newLine
            ((BasicDrawingPane) getDrawingPane()).addDrawingElement(line);
            line = new BasicLine();
            line.setColor(color);
            line.setStroke(stroke);
        }
    // x++;
    }
    ((BasicDrawingPane) getDrawingPane()).addDrawingElement(line);
    fitToScreen();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Point(java.awt.Point) DataRow(org.knime.core.data.DataRow) Point(java.awt.Point) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 100 with DoubleValue

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

the class BasicPlotter method addBasicDrawingElement.

/**
 * Adds a drawing element to the drawing pane. The mapping of the domain
 * values to the screen coordinates is done here
 * Only numeric values are supported. All the rest like color
 * and stroke setting has to be done outside.
 * @param element a drawing element.
 */
public void addBasicDrawingElement(final BasicDrawingElement element) {
    if (!(getDrawingPane() instanceof BasicDrawingPane)) {
        return;
    }
    double minX = Integer.MAX_VALUE;
    double maxX = Integer.MIN_VALUE;
    double minY = Integer.MAX_VALUE;
    double maxY = Integer.MIN_VALUE;
    for (DataCellPoint p : element.getDomainValues()) {
        // determine the min and max values for the coordinates
        if (!p.getX().getType().isCompatible(DoubleValue.class) || !p.getY().getType().isCompatible(DoubleValue.class)) {
            LOGGER.warn("a basic drawing element can onyl be defined for " + "numeric values!");
            return;
        }
        double x = ((DoubleValue) p.getX()).getDoubleValue();
        double y = ((DoubleValue) p.getY()).getDoubleValue();
        minX = Math.min(x, minX);
        maxX = Math.max(x, maxX);
        minY = Math.min(y, minY);
        maxY = Math.max(y, maxY);
    }
    createXCoordinate(minX, maxX);
    createYCoordinate(minY, maxY);
    // calculate the mapped values
    List<Point> newPoints = new LinkedList<Point>();
    for (DataCellPoint p : element.getDomainValues()) {
        double mappedX = getXAxis().getCoordinate().calculateMappedValue(p.getX(), getDrawingPaneDimension().width);
        double mappedY = getYAxis().getCoordinate().calculateMappedValue(p.getY(), getDrawingPaneDimension().height);
        newPoints.add(new Point((int) mappedX, (int) getScreenYCoordinate(mappedY)));
    }
    element.setPoints(newPoints);
    ((BasicDrawingPane) getDrawingPane()).addDrawingElement(element);
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) Point(java.awt.Point) LinkedList(java.util.LinkedList)

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