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;
}
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;
}
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);
}
}
Aggregations