Search in sources :

Example 1 with SizeHandler

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())));
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) SizeHandler(org.knime.core.data.property.SizeHandler) SizeModelDouble(org.knime.core.data.property.SizeModelDouble)

Example 2 with SizeHandler

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) SizeHandler(org.knime.core.data.property.SizeHandler) BufferedDataTable(org.knime.core.node.BufferedDataTable) SizeHandlerPortObject(org.knime.core.node.port.viewproperty.SizeHandlerPortObject) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SizeHandlerPortObject(org.knime.core.node.port.viewproperty.SizeHandlerPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 3 with SizeHandler

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SizeHandler(org.knime.core.data.property.SizeHandler) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 4 with SizeHandler

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");
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ShapeHandler(org.knime.core.data.property.ShapeHandler) FilterHandler(org.knime.core.data.property.filter.FilterHandler) SizeHandler(org.knime.core.data.property.SizeHandler) ColorHandler(org.knime.core.data.property.ColorHandler)

Example 5 with SizeHandler

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);
}
Also used : SizeHandler(org.knime.core.data.property.SizeHandler) ShapeHandler(org.knime.core.data.property.ShapeHandler) ColorHandler(org.knime.core.data.property.ColorHandler) FilterHandler(org.knime.core.data.property.filter.FilterHandler)

Aggregations

SizeHandler (org.knime.core.data.property.SizeHandler)7 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 DataTableSpec (org.knime.core.data.DataTableSpec)4 ColorHandler (org.knime.core.data.property.ColorHandler)3 ShapeHandler (org.knime.core.data.property.ShapeHandler)3 FilterHandler (org.knime.core.data.property.filter.FilterHandler)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 DataCell (org.knime.core.data.DataCell)1 DataColumnDomain (org.knime.core.data.DataColumnDomain)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DataType (org.knime.core.data.DataType)1 DoubleValue (org.knime.core.data.DoubleValue)1