Search in sources :

Example 26 with DataValue

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

the class NominalCoordinate method calculateMappedValueInternal.

/**
 * Calculates a numeric mapping assuming a column with a given number of
 * possible values.
 *
 * {@inheritDoc}
 */
@Override
protected double calculateMappedValueInternal(final DataCell domainValueCell, final double absoluteLength) {
    // get the mapping for all values dependent on the absolute mapping
    // length
    CoordinateMapping[] mappings = getTickPositions(absoluteLength);
    // get the mapping position of the domain value from the mapping array
    double mappedValue = -1;
    for (CoordinateMapping mapping : mappings) {
        for (DataValue v : mapping.getValues()) {
            if (v.equals(domainValueCell)) {
                mappedValue = mapping.getMappingValue();
                return mappedValue;
            }
        }
    }
    return -1;
}
Also used : DataValue(org.knime.core.data.DataValue)

Example 27 with DataValue

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

the class NominalCoordinate method getReducedTickPositions.

/**
 * @param absLength the available length.
 * @return a reduced mapping with a minimum distance between the values and
 *         dots if some values were left out,
 */
public CoordinateMapping[] getReducedTickPositions(final int absLength) {
    if (m_numberPossibleValues <= 0) {
        return null;
    }
    int tickWidth = (int) Math.ceil(absLength / (double) m_numberPossibleValues);
    if (tickWidth == 0) {
        tickWidth = 1;
    }
    int leaveOut = DEFAULT_ABSOLUTE_TICK_DIST / tickWidth;
    CoordinateMapping[] mappings = getTickPositions(absLength);
    CoordinateMapping[] reduced;
    if (leaveOut > 1) {
        // no desired value
        reduced = new CoordinateMapping[mappings.length / leaveOut + 1];
        for (int i = 0; i < reduced.length; i++) {
            int index = i * leaveOut;
            if (index > mappings.length - 1) {
                index = mappings.length - 1;
            }
            if (i % 2 == 0) {
                reduced[i] = mappings[index];
            } else {
                reduced[i] = new NominalCoordinateMapping("...", mappings[index].getMappingValue());
                if (leaveOut == 1) {
                    String val = mappings[index].getDomainValueAsString();
                    reduced[i] = new NominalCoordinateMapping(val, mappings[index].getMappingValue());
                }
                List<DataValue> tickValues = new ArrayList<DataValue>();
                int start = (i - 1) * leaveOut + 1;
                int end = (i + 1) * leaveOut;
                if (end >= mappings.length) {
                    end = mappings.length - 1;
                }
                if (i == reduced.length - 2) {
                // end = mappings.length - 2;
                }
                for (int j = start; j < end; j++) {
                    for (DataValue dv : mappings[j].getValues()) {
                        tickValues.add(dv);
                    }
                }
                reduced[i].setValues(tickValues.toArray(new DataValue[0]));
            }
        }
    } else {
        reduced = mappings;
    }
    return reduced;
}
Also used : DataValue(org.knime.core.data.DataValue) ArrayList(java.util.ArrayList)

Example 28 with DataValue

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

the class ValueFactoryUtils method loadDataTypeFromJson.

private static DataType loadDataTypeFromJson(final ObjectNode config) {
    var elementTypeNode = config.get(CFG_COLLECTION_ELEMENT_TYPE);
    DataType elementType = elementTypeNode != null ? loadDataTypeFromJson((ObjectNode) elementTypeNode) : null;
    var cellClassNode = config.get(CFG_CELL_CLASS);
    JsonNode adapterClassNames = config.get(CFG_ADAPTER_CLASSES);
    List<Class<? extends DataValue>> adapterClasses = adapterClassNames != null ? jsonNodeToClassList(adapterClassNames) : List.of();
    if (cellClassNode != null) {
        var cellClassName = cellClassNode.asText();
        var cellClass = REGISTRY.getCellClass(cellClassName).orElseThrow(() -> new IllegalStateException(String.format("DataCell implementation '%s' not found.", cellClassName)));
        return DataType.getType(cellClass, elementType, adapterClasses);
    } else {
        var valueClasses = jsonNodeToClassList(config.get(CFG_VALUE_CLASSES));
        return DataType.createNonNativeType(valueClasses, elementType, adapterClasses);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DataValue(org.knime.core.data.DataValue) DataType(org.knime.core.data.DataType) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

DataValue (org.knime.core.data.DataValue)28 DataCell (org.knime.core.data.DataCell)9 DoubleValue (org.knime.core.data.DoubleValue)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 DataType (org.knime.core.data.DataType)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 StringCell (org.knime.core.data.def.StringCell)5 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 DataRow (org.knime.core.data.DataRow)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 FileInputStream (java.io.FileInputStream)2 JMenu (javax.swing.JMenu)2