use of org.knime.core.data.property.SizeHandler 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())));
}
use of org.knime.core.data.property.SizeHandler in project knime-core by knime.
the class SizeManager2NodeModel method execute.
/**
* Is invoked during the node's execution to make the size settings.
*
* @param data the input data array
* @param exec the execution monitor
* @return the same input data table whereby the DataTableSpec contains
* additional size infos
* @throws CanceledExecutionException if user canceled execution
*
* @see NodeModel#execute(BufferedDataTable[],ExecutionContext)
*/
@Override
protected PortObject[] execute(final PortObject[] data, final ExecutionContext exec) throws CanceledExecutionException {
final DataTableSpec inSpec = (DataTableSpec) data[INPORT].getSpec();
final String columnName = m_column.getStringValue();
final DataColumnSpec cspec = inSpec.getColumnSpec(columnName);
SizeHandler sizeHandler = createSizeHandler(cspec);
final DataTableSpec newSpec = appendSizeHandler(inSpec, columnName, sizeHandler);
BufferedDataTable changedSpecTable = exec.createSpecReplacerTable((BufferedDataTable) data[INPORT], newSpec);
DataTableSpec modelSpec = new DataTableSpec(newSpec.getColumnSpec(m_column.getStringValue()));
SizeHandlerPortObject viewPort = new SizeHandlerPortObject(modelSpec, sizeHandler.toString() + " based on column \"" + m_column.getStringValue() + "\"");
return new PortObject[] { changedSpecTable, viewPort };
}
use of org.knime.core.data.property.SizeHandler in project knime-core by knime.
the class SizeManager2NodeModel method configure.
/**
* @param inSpecs the input specs passed to the output port
* @return the same as the input spec
*
* @throws InvalidSettingsException if a column is not available
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final String column = m_column.getStringValue();
DataTableSpec inSpec = (DataTableSpec) inSpecs[INPORT];
if (column == null || !inSpec.containsName(column)) {
throw new InvalidSettingsException("Column " + column + " not found.");
}
DataColumnSpec cspec = inSpec.getColumnSpec(column);
if (!cspec.getDomain().hasBounds()) {
throw new InvalidSettingsException("No bounds defined for column: " + column);
}
SizeHandler sizeHandler = createSizeHandler(cspec);
DataTableSpec outSpec = appendSizeHandler(inSpec, m_column.getStringValue(), sizeHandler);
DataTableSpec modelSpec = new DataTableSpec(outSpec.getColumnSpec(m_column.getStringValue()));
return new DataTableSpec[] { outSpec, modelSpec };
}
use of org.knime.core.data.property.SizeHandler in project knime-core by knime.
the class DataColumnSpecCreator method merge.
/**
* Merges the existing {@link DataColumnSpec} with a second
* {@link DataColumnSpec}. If they have equal structure, the domain
* information and properties from both DataColumnSpecs is merged,
* Color, Shape and Size-Handlers are compared (must be equal).
*
* @param cspec2 the second {@link DataColumnSpec}.
*
* @see DataTableSpec#mergeDataTableSpecs(DataTableSpec...)
* @throws IllegalArgumentException if the structure (type and name) does
* not match, if the domain cannot be merged, if the Color-,
* Shape- or SizeHandlers are different or the sub element
* names are not equal.
*/
public void merge(final DataColumnSpec cspec2) {
if (!cspec2.getName().equals(m_name) || !cspec2.getType().equals(m_type)) {
throw new IllegalArgumentException("Structures of DataColumnSpecs" + " do not match.");
}
DataColumnDomain domain2 = cspec2.getDomain();
boolean hasDomainChanged = false;
final Set<DataCell> myValues = m_domain.getValues();
final Set<DataCell> oValues = domain2.getValues();
Set<DataCell> newValues;
if (myValues == null || oValues == null) {
newValues = null;
hasDomainChanged |= myValues != null;
} else if (myValues.equals(oValues)) {
newValues = myValues;
} else {
newValues = new LinkedHashSet<DataCell>(myValues);
newValues.addAll(oValues);
hasDomainChanged = true;
}
DataValueComparator comparator = m_type.getComparator();
final DataCell myLower = m_domain.getLowerBound();
final DataCell oLower = domain2.getLowerBound();
DataCell newLower;
if (myLower == null || oLower == null) {
newLower = null;
hasDomainChanged |= myLower != null;
} else if (myLower.equals(oLower)) {
newLower = myLower;
} else if (comparator.compare(myLower, oLower) > 0) {
newLower = oLower;
hasDomainChanged = true;
} else {
newLower = myLower;
}
final DataCell myUpper = m_domain.getUpperBound();
final DataCell oUpper = domain2.getUpperBound();
DataCell newUpper;
if (myUpper == null || oUpper == null) {
newUpper = null;
hasDomainChanged |= myUpper != null;
} else if (myUpper.equals(oUpper)) {
newUpper = myUpper;
} else if (comparator.compare(myUpper, oUpper) < 0) {
newUpper = oUpper;
hasDomainChanged = true;
} else {
newUpper = myUpper;
}
if (hasDomainChanged) {
setDomain(new DataColumnDomain(newLower, newUpper, newValues));
}
// check for redundant color handler
ColorHandler colorHandler2 = cspec2.getColorHandler();
if (!Objects.equals(m_colorHandler, colorHandler2)) {
LOGGER.warn("Column has already a color handler attached, ignoring new handler.");
}
// check for redundant shape handler
ShapeHandler shapeHandler2 = cspec2.getShapeHandler();
if (!Objects.equals(m_shapeHandler, shapeHandler2)) {
LOGGER.warn("Column has already a shape handler attached, ignoring new handler.");
}
// check for redundant size handler
SizeHandler sizeHandler2 = cspec2.getSizeHandler();
if (!Objects.equals(m_sizeHandler, sizeHandler2)) {
LOGGER.warn("Column has already a size handler attached, ignoring new handler.");
}
// check for redundant filter handler
FilterHandler filterHandler = cspec2.getFilterHandler().orElse(null);
if (!Objects.equals(m_filterHandler, filterHandler)) {
LOGGER.warn("Column has already a filter handler attached, ignoring new handler.");
}
// merge properties, take intersection
DataColumnProperties prop2 = cspec2.getProperties();
Map<String, String> mergedProps = new HashMap<String, String>();
Enumeration<String> e = m_properties.properties();
while (e.hasMoreElements()) {
String key = e.nextElement();
String value = m_properties.getProperty(key);
if (prop2.getProperty(key) != null && prop2.getProperty(key).equals(value)) {
mergedProps.put(key, value);
}
}
if (mergedProps.size() != m_properties.size()) {
setProperties(new DataColumnProperties(mergedProps));
}
List<String> elNames2 = cspec2.getElementNames();
String[] elNames2Array = elNames2.toArray(new String[elNames2.size()]);
String[] elNamesArray = m_elementNames == null ? new String[] { m_name } : m_elementNames;
if (!Arrays.deepEquals(elNamesArray, elNames2Array)) {
throw new IllegalArgumentException("Element names are not equal");
}
}
use of org.knime.core.data.property.SizeHandler in project knime-core by knime.
the class DataColumnSpec method load.
/**
* Reads name, type, domain, and properties from the given
* <code>ConfigRO</code> and - if available - size, shape, and color
* handler. Returns a new <code>DataColumnSpec</code> object initialized
* with the information read.
*
* @param config to read properties from
* @return a new column spec object
* @throws InvalidSettingsException if one of the non-optional properties is
* not available or can't be initialized
* @throws NullPointerException if the config object is <code>null</code>
*/
public static DataColumnSpec load(final ConfigRO config) throws InvalidSettingsException {
String name = config.getString(CFG_COLUMN_NAME);
String[] elNames = config.getStringArray(CFG_ELEMENT_NAMES, (String[]) null);
if (elNames == null) {
elNames = new String[] { name };
}
DataType type = DataType.load(config.getConfig(CFG_COLUMN_TYPE));
DataColumnDomain domain = DataColumnDomain.load(config.getConfig(CFG_COLUMN_DOMAIN));
DataColumnProperties properties = DataColumnProperties.load(config.getConfig(CFG_COLUMN_PROPS));
ColorHandler color = null;
if (config.containsKey(CFG_COLORS)) {
color = ColorHandler.load(config.getConfig(CFG_COLORS));
}
SizeHandler size = null;
if (config.containsKey(CFG_SIZES)) {
size = SizeHandler.load(config.getConfig(CFG_SIZES));
}
ShapeHandler shape = null;
if (config.containsKey(CFG_SHAPES)) {
shape = ShapeHandler.load(config.getConfig(CFG_SHAPES));
}
FilterHandler filter = null;
if (config.containsKey(CFG_FILTER)) {
filter = FilterHandler.load(config.getConfig(CFG_FILTER));
}
final DataColumnMetaDataManager metaDataManager;
if (config.containsKey(CFG_META_DATA)) {
metaDataManager = DataColumnMetaDataManager.load(config.getConfig(CFG_META_DATA));
} else {
// create an empty meta data object to avoid issues with NPEs
metaDataManager = DataColumnMetaDataManager.EMPTY;
}
return new DataColumnSpec(name, elNames, type, domain, properties, size, color, shape, filter, metaDataManager);
}
Aggregations