org.knime.base.util.coordinate
Class Coordinate

java.lang.Object
  extended by org.knime.base.util.coordinate.Coordinate
Direct Known Subclasses:
NominalCoordinate, NumericCoordinate

public abstract class Coordinate
extends Object

The abstract class for all coordinate classes. A concrete coordinate depends on whether it is nominal or numeric, etc. All coordinates have an underlying DataColumnSpec. Ticks have to be created and mapped to their domain values.

Author:
Christoph Sieb, University of Konstanz, Stephan Sellien, University of Konstanz

Field Summary
static int DEFAULT_ABSOLUTE_TICK_DIST
          The default tick distance in pixel.
 
Constructor Summary
protected Coordinate(DataColumnSpec dataColumnSpec)
          Creates a coordinate from a data column spec.
 
Method Summary
static void addCoordinateFactory(Class<? extends DataValue> valueClass, CoordinateFactory factory)
          Adds a coordinate factory class.
abstract  void addDesiredValues(DataValue... values)
          Adds a value which should have a tick.
static void addMappingMethod(Class<? extends DataValue> clazz, String id, MappingMethod mappingMethod)
          Adds a MappingMethod to the internal registry.
static void addPolicy(Class<? extends DataValue> dataValue, String id, PolicyStrategy strategy)
          Registers a strategy.
protected  DataCell applyMappingMethod(DataCell datacell)
          Applies the mapping method.
 double calculateMappedValue(DataCell domainValueCell, double absoluteLength)
          Returns the mapping of a domain value for this coordinate axis.
 double calculateMappedValue(DataCell domainValueCell, double absoluteLength, boolean naturalMapping)
          Deprecated. Use calculateMappedValue(DataCell, double) instead.
protected abstract  double calculateMappedValueInternal(DataCell domainValueCell, double absoluteLength)
          Returns the mapping of a domain value for this coordinate axis.
 void clearDesiredValues()
          Clears the desired values.
static Coordinate createCoordinate(DataColumnSpec dataColumnSpec)
          Factory method to create a coordinate for a given column spec.
 MappingMethod getActiveMappingMethod()
          Gets the mapping method which should be applied.
 Set<MappingMethod> getCompatibleMappingMethods()
          Returns the mapping methods compatible to this coordinate's data type.
 Set<PolicyStrategy> getCompatiblePolicies()
          Returns the compatible policies for this data value.
 PolicyStrategy getCurrentPolicy()
          Returns the current tick policy.
(package private)  DataColumnSpec getDataColumnSpec()
          Returns the underlying DataColumnSpec.
 DataValue[] getDesiredValues()
          Returns the desired values.
protected  Set<DataValue> getDesiredValuesSet()
          Returns the set for the desired values.
 DataColumnDomain getDomain()
          Returns the domain used in this moment after applying the active mapping method.
 MappingMethod getMappingMethod(String id)
          Returns the MappingMethod with the given id if available.
 double getNegativeInfinity()
          Returns the value for negative infinity after mapping.
protected  PolicyStrategy getPolicyStategy(String policy)
          Returns the strategy for the given policy.
 double getPositiveInfinity()
          Returns the value for positive infinity after mapping.
 CoordinateMapping[] getTickPositions(double absoluteLength)
          Returns an array with the position of all ticks and their corresponding domain values given an absolute length.
 CoordinateMapping[] getTickPositions(double absoluteLength, boolean naturalMapping)
          Deprecated. Use getTickPositions(double) instead.
protected abstract  CoordinateMapping[] getTickPositionsWithLabels(double absoluteLength)
          Returns an array with the position of all ticks and their corresponding domain values given an absolute length.
abstract  double getUnusedDistBetweenTicks(double absoluteLength)
          Returns the range according to the mapping in which no values can have values.
abstract  boolean isNominal()
          Whether this coordinate is a nominal one.
 void setActiveMappingMethod(MappingMethod method)
          Sets the mapping method which should be applied.
 void setPolicy(PolicyStrategy policy)
          Sets the current PolicyStrategy.
 void setPolicy(String id)
          Sets the current PolicyStrategy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ABSOLUTE_TICK_DIST

public static final int DEFAULT_ABSOLUTE_TICK_DIST
The default tick distance in pixel.

See Also:
Constant Field Values
Constructor Detail

Coordinate

protected Coordinate(DataColumnSpec dataColumnSpec)
Creates a coordinate from a data column spec.

Parameters:
dataColumnSpec - the underlying column spec to set
Method Detail

addDesiredValues

public abstract void addDesiredValues(DataValue... values)
Adds a value which should have a tick.

Parameters:
values - the desired value

getDesiredValuesSet

protected Set<DataValue> getDesiredValuesSet()
Returns the set for the desired values.

Returns:
the desired value set

clearDesiredValues

public void clearDesiredValues()
Clears the desired values.


getPolicyStategy

protected PolicyStrategy getPolicyStategy(String policy)
Returns the strategy for the given policy.

Parameters:
policy - the numeric tick policy
Returns:
the according strategy

getCompatiblePolicies

public Set<PolicyStrategy> getCompatiblePolicies()
Returns the compatible policies for this data value.

Returns:
the compatible policies or null if none.

addPolicy

public static void addPolicy(Class<? extends DataValue> dataValue,
                             String id,
                             PolicyStrategy strategy)
Registers a strategy.

Parameters:
dataValue - the according DataValue.
id - a unique identifier
strategy - the PolicyStrategy

getCurrentPolicy

public PolicyStrategy getCurrentPolicy()
Returns the current tick policy.

Returns:
the current tick policy, or null if none.

setPolicy

public void setPolicy(PolicyStrategy policy)
Sets the current PolicyStrategy.

Parameters:
policy - the new PolicyStrategy
Throws:
IllegalArgumentException - if desired policy does not fit to this coordinate

setPolicy

public void setPolicy(String id)
Sets the current PolicyStrategy.

Parameters:
id - the unique identifier of the desired policy
Throws:
IllegalArgumentException - if desired policy does not exist.

getDesiredValues

public DataValue[] getDesiredValues()
Returns the desired values.

Returns:
the desired values as array or null, if not set

addCoordinateFactory

public static void addCoordinateFactory(Class<? extends DataValue> valueClass,
                                        CoordinateFactory factory)
Adds a coordinate factory class. Warning: Existing factory classes will be replaced.

Parameters:
valueClass - the data value
factory - the according coordinate factory

createCoordinate

public static Coordinate createCoordinate(DataColumnSpec dataColumnSpec)
Factory method to create a coordinate for a given column spec. The type of the column is determined and dependent on that the corresponding coordinate is created.

Parameters:
dataColumnSpec - the column spec to create the coordinate from
Returns:
the created coordinate, null if not possible

getDataColumnSpec

DataColumnSpec getDataColumnSpec()
Returns the underlying DataColumnSpec. If MappingMethods are set, they will be applied to the domain. The domain must not be equal to the original DataColumnSpec.

Returns:
the underlying column spec of this coordinate

getTickPositions

@Deprecated
public CoordinateMapping[] getTickPositions(double absoluteLength,
                                                       boolean naturalMapping)
Deprecated. Use getTickPositions(double) instead.

Returns an array with the position of all ticks and their corresponding domain values given an absolute length.

Parameters:
absoluteLength - the absolute length the domain is mapped on
naturalMapping - if true the mapping values are rounded to the next integer equivalent
Returns:
the mapping of tick positions and corresponding domain values

getTickPositions

public CoordinateMapping[] getTickPositions(double absoluteLength)
Returns an array with the position of all ticks and their corresponding domain values given an absolute length.

Parameters:
absoluteLength - the absolute length the domain is mapped on
Returns:
the mapping of tick positions and corresponding domain values

getTickPositionsWithLabels

protected abstract CoordinateMapping[] getTickPositionsWithLabels(double absoluteLength)
Returns an array with the position of all ticks and their corresponding domain values given an absolute length.

Parameters:
absoluteLength - the absolute length the domain is mapped on
Returns:
the mapping of tick positions and corresponding domain values

calculateMappedValue

public double calculateMappedValue(DataCell domainValueCell,
                                   double absoluteLength)
Returns the mapping of a domain value for this coordinate axis. The mapping is done according to the given absolute length.

The value is not the position on the screen. Since the java coordinate system is upside down simply subtract the returned value from the screen height to calculate the screen position.

Parameters:
domainValueCell - the data cell with the domain value to map
absoluteLength - the absolute length on which the domain value is mapped on
Returns:
the mapped value

calculateMappedValue

@Deprecated
public double calculateMappedValue(DataCell domainValueCell,
                                              double absoluteLength,
                                              boolean naturalMapping)
Deprecated. Use calculateMappedValue(DataCell, double) instead.

Returns the mapping of a domain value for this coordinate axis. The mapping is done according to the given absolute length. The value is not the position on the screen. Since the java coordinate system is upside down simply subtract the returned value from the screen height to calculate the screen position.

Parameters:
domainValueCell - the data cell with the domain value to map
absoluteLength - the absolute length on which the domain value is mapped on
naturalMapping - if true the return value will be a double but with zeros after the decimal dot
Returns:
the mapped value

calculateMappedValueInternal

protected abstract double calculateMappedValueInternal(DataCell domainValueCell,
                                                       double absoluteLength)
Returns the mapping of a domain value for this coordinate axis. The mapping is done according to the given absolute length.

The value is not the position on the screen. Since the java coordinate system is upside down simply subtract the returned value from the screen height to calculate the screen position.

Parameters:
domainValueCell - the data cell with the domain value to map
absoluteLength - the absolute length on which the domain value is mapped on
Returns:
the mapped value

isNominal

public abstract boolean isNominal()
Whether this coordinate is a nominal one. Nominal coordinates must be treated differently in some cases, i.e. when rendering in a scatterplot nominal values are very likely to be drawn above each other which requires jittering.

Returns:
true, if this coordinate is a nominal one

getUnusedDistBetweenTicks

public abstract double getUnusedDistBetweenTicks(double absoluteLength)
Returns the range according to the mapping in which no values can have values. This distance will not occur in floating point numbers. For nominal values it is most likely to occur. For discrete values like integers, it will happen when the integer range is smaller than the available pixels.

Parameters:
absoluteLength - the absolute length available for this coordinate
Returns:
the unused mapping range per domain value

addMappingMethod

public static void addMappingMethod(Class<? extends DataValue> clazz,
                                    String id,
                                    MappingMethod mappingMethod)
Adds a MappingMethod to the internal registry.

Parameters:
clazz - the according class, must extend DataValue
id - a unique identifier
mappingMethod - a MappingMethod

getCompatibleMappingMethods

public Set<MappingMethod> getCompatibleMappingMethods()
Returns the mapping methods compatible to this coordinate's data type.

Returns:
a Set of MappingMethods

getMappingMethod

public MappingMethod getMappingMethod(String id)
Returns the MappingMethod with the given id if available.

Parameters:
id - the unique identifier
Returns:
a MappingMethod or null if id is not registered.

setActiveMappingMethod

public void setActiveMappingMethod(MappingMethod method)
Sets the mapping method which should be applied.

Parameters:
method - a MappingMethod

getActiveMappingMethod

public MappingMethod getActiveMappingMethod()
Gets the mapping method which should be applied.

Returns:
the MappingMethod which currently will be applied or null if none

applyMappingMethod

protected DataCell applyMappingMethod(DataCell datacell)
Applies the mapping method.

Parameters:
datacell - value to be mapped
Returns:
the mapped value

getDomain

public DataColumnDomain getDomain()
Returns the domain used in this moment after applying the active mapping method. This must not be equal to the original domain!

Returns:
the domain

getPositiveInfinity

public double getPositiveInfinity()
Returns the value for positive infinity after mapping. Necessary to recognize infinity after scaling e.g..

Returns:
the value for positive infinity.

getNegativeInfinity

public double getNegativeInfinity()
Returns the value for negative infinity after mapping. Necessary to recognize infinity after scaling e.g..

Returns:
the value for negative infinity.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.