Package com.metsci.glimpse.core.axis
Class Axis1D
- java.lang.Object
-
- com.metsci.glimpse.core.axis.Axis1D
-
- Direct Known Subclasses:
TaggedAxis1D
,WrappedAxis1D
public class Axis1D extends Object
A one dimensional numeric axis. Has minimum and maximum bounds which represent its current extent. Constraints can also be set on the axis which constrain what values the minimum and maximum bounds can take on. Axis1D can be part of a hierarchy of axes which all mirror changes in each other, making it easy to set up a series of linked plots. Axis1D also supports locking its aspect ratio with respect to another (usually orthogonal) axis in order to ensure that the ratio of the scales of the two axes remains consistent. Axis1D are associated with one of twoGlimpseLayout
implementations:GlimpseAxisLayout1D
andGlimpseAxisLayout2D
. When aGlimpsePainter
is added to aGlimpseLayout
, it paints based on the bounds provided by the Axis1D associated with theGlimpseLayout
.- Author:
- ulman
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAxisListener(AxisListener1D listener)
Adds a listener which will be notified whenever this axis changes.void
applyConstraints()
Adjusts the min and max values of the axis to conform to the various axis constraints like absolute bounds and locked min/max.Axis1D
clone()
double
getAbsoluteMax()
double
getAbsoluteMin()
Set<Axis1D>
getChildren()
Axis1D
getLockedAspectAxis()
double
getLockedAspectRatio()
double
getLockMax()
double
getLockMin()
double
getMax()
double
getMaxSpan()
double
getMin()
double
getMinSpan()
double
getMouseValue()
Axis1D
getParent()
double
getPixelsPerValue()
double
getSelectionCenter()
double
getSelectionSize()
int
getSizePixels()
UpdateMode
getUpdateMode()
boolean
isInitialized()
boolean
isLockMax()
boolean
isLockMin()
boolean
isMaxSpanConstrained()
boolean
isMinSpanConstrained()
boolean
isSelectionLocked()
void
lock()
Locks both the minimum and maximum value of this axis to their current values.void
lockAspectRatio(Axis1D orthogonalAxis, double aspectRatio)
Locks the aspect ratio between this axis and a provided orthogonal aspect to a fixed ratio.void
lockMax()
Locks the maximum value of this axis to its current max value.void
lockMax(double value)
Locks the maximum value of this axis to a fixed value.void
lockMin()
Locks the minimum value of this axis to its current min value.void
lockMin(double value)
Locks the minimum value of this axis to a fixed value.void
removeAxisListener(AxisListener1D listener)
Removes the provided listener from the list of listeners which are notified when this axis changes.double
screenPixelToValue(double pixel)
void
setAbsoluteMax(double max)
Sets the absolute maximum value of this axis.void
setAbsoluteMin(double min)
Sets the absolute minimum value of this axis.void
setConstrainMaxSpan(boolean constrain)
If true, the maximum difference set by setMaxSpan() is enforced.void
setConstrainMinSpan(boolean constrain)
If true, the minimum difference set by setMinSpan() is enforced.void
setInitialized()
Should be called once axisSizePixels has been properly set (usually once the underlying canvas associated with this Axis1D has been drawn).void
setLinkChildren(boolean link)
void
setMax(double value)
Sets the maximum value of this axis.void
setMaxSpan(double diff)
Constrains the maximum difference between the axis max and min values.void
setMin(double value)
Sets the minimum value of this axis.void
setMinSpan(double diff)
Constrains the minimum difference between the axis max and min values.void
setMouseValue(double value)
Sets the position of the mouse in axis value space.void
setParent(Axis1D newParent)
Allows a group of axis which should mirror each other to be defined by placing them in a tree-hierarchy.void
setParent(Axis1D newParent, boolean duplicateChild)
void
setSelectionCenter(double value)
Sets the center of the selected range of this axis.void
setSelectionLock(boolean lock)
Locks the selected region of this axis so that it does not adjust.void
setSelectionSize(double value)
Sets the size of the selected range of this axis.void
setSizePixels(int newSize)
Sets the pixel size of this axis.void
setSizePixels(int newSize, boolean initialize)
Sets the pixel size of this axis.void
setUpdateMode(UpdateMode mode)
Sets the UpdateMode of this axis.String
toString()
void
unlock()
Unlocks the minimum an maximum values of this axis.void
unlockAspectRatio()
Removes the aspect ratio locking which was established through a call to lockAspectRatio( ).void
unlockMax()
Unlocks the maximum value of this axis.void
unlockMin()
Unlocks the minimum value of this axis.void
updateLinkedAxes()
void
updateLinkedAxes(Axis1D... ignore)
void
validate()
Ensures that the axis min and max values do not violate any constraints and publishes this axis' values to all linked axes.int
valueToScreenPixel(double value)
double
valueToScreenPixelUnits(double value)
-
-
-
Field Detail
-
logger
public static Logger logger
-
-
Constructor Detail
-
Axis1D
public Axis1D(Axis1D parent)
-
Axis1D
public Axis1D()
-
-
Method Detail
-
clone
public Axis1D clone()
-
validate
public void validate()
Ensures that the axis min and max values do not violate any constraints and publishes this axis' values to all linked axes. Should be called after any Axis1D setter methods are called.
-
setParent
public void setParent(Axis1D newParent)
Allows a group of axis which should mirror each other to be defined by placing them in a tree-hierarchy. Whenever this Axis1D or any axis linked to it through its parents or children is modified (and validate() is called to indicate it has been modified), all linked axis are update.- Parameters:
newParent
- The new parent for this axis.
-
setParent
public void setParent(Axis1D newParent, boolean duplicateChild)
-
setLinkChildren
public void setLinkChildren(boolean link)
-
getParent
public Axis1D getParent()
-
addAxisListener
public void addAxisListener(AxisListener1D listener)
Adds a listener which will be notified whenever this axis changes.- Parameters:
listener
-
-
removeAxisListener
public void removeAxisListener(AxisListener1D listener)
Removes the provided listener from the list of listeners which are notified when this axis changes.- Parameters:
listener
-
-
lockAspectRatio
public void lockAspectRatio(Axis1D orthogonalAxis, double aspectRatio)
Locks the aspect ratio between this axis and a provided orthogonal aspect to a fixed ratio. Whenever either axis updates the other will adjust to maintain the desired aspect.- Parameters:
orthogonalAxis
- The axis to remain at a fixed aspect ratio with.aspectRatio
- The aspect ratio to maintain.
-
setMinSpan
public void setMinSpan(double diff)
Constrains the minimum difference between the axis max and min values.- Parameters:
diff
-
-
setMaxSpan
public void setMaxSpan(double diff)
Constrains the maximum difference between the axis max and min values.- Parameters:
diff
-
-
setConstrainMinSpan
public void setConstrainMinSpan(boolean constrain)
If true, the minimum difference set by setMinSpan() is enforced.- Parameters:
constrain
-
-
setConstrainMaxSpan
public void setConstrainMaxSpan(boolean constrain)
If true, the maximum difference set by setMaxSpan() is enforced.- Parameters:
constrain
-
-
isMinSpanConstrained
public boolean isMinSpanConstrained()
-
isMaxSpanConstrained
public boolean isMaxSpanConstrained()
-
unlockAspectRatio
public void unlockAspectRatio()
Removes the aspect ratio locking which was established through a call to lockAspectRatio( ).
-
lockMin
public void lockMin(double value)
Locks the minimum value of this axis to a fixed value.- Parameters:
value
-
-
lockMax
public void lockMax(double value)
Locks the maximum value of this axis to a fixed value.- Parameters:
value
-
-
lock
public void lock()
Locks both the minimum and maximum value of this axis to their current values.
-
lockMin
public void lockMin()
Locks the minimum value of this axis to its current min value.
-
lockMax
public void lockMax()
Locks the maximum value of this axis to its current max value.
-
unlock
public void unlock()
Unlocks the minimum an maximum values of this axis.
-
unlockMin
public void unlockMin()
Unlocks the minimum value of this axis.
-
unlockMax
public void unlockMax()
Unlocks the maximum value of this axis.
-
setUpdateMode
public void setUpdateMode(UpdateMode mode)
Sets the UpdateMode of this axis. This determines how the axis reacts when it is resized.- Parameters:
mode
-- See Also:
UpdateMode
-
setMin
public void setMin(double value)
Sets the minimum value of this axis.- Parameters:
value
-
-
setMax
public void setMax(double value)
Sets the maximum value of this axis.- Parameters:
value
-
-
setAbsoluteMin
public void setAbsoluteMin(double min)
Sets the absolute minimum value of this axis. The minimum value of the axis is allowed to take on any values as long as it does not fall below the absolute minimum.- Parameters:
min
-
-
setAbsoluteMax
public void setAbsoluteMax(double max)
Sets the absolute maximum value of this axis. The maximum value of the axis is allowed to take on any values as long as it does not rise above the absolute maximum.- Parameters:
max
-
-
setSelectionSize
public void setSelectionSize(double value)
Sets the size of the selected range of this axis.- Parameters:
value
-
-
setSelectionCenter
public void setSelectionCenter(double value)
Sets the center of the selected range of this axis.- Parameters:
value
-
-
setSelectionLock
public void setSelectionLock(boolean lock)
Locks the selected region of this axis so that it does not adjust.- Parameters:
lock
-
-
setMouseValue
public void setMouseValue(double value)
Sets the position of the mouse in axis value space.- Parameters:
value
-
-
setSizePixels
public void setSizePixels(int newSize)
Sets the pixel size of this axis.- Parameters:
newSize
-
-
setSizePixels
public void setSizePixels(int newSize, boolean initialize)
Sets the pixel size of this axis. Provides an option to not mark the axis as initialized. This is useful for orthogonal linked axes which must both be initialized before applying constraints.- Parameters:
newSize
-
-
setInitialized
public void setInitialized()
Should be called once axisSizePixels has been properly set (usually once the underlying canvas associated with this Axis1D has been drawn).
-
getMinSpan
public double getMinSpan()
-
getMaxSpan
public double getMaxSpan()
-
getLockedAspectAxis
public Axis1D getLockedAspectAxis()
-
getLockedAspectRatio
public double getLockedAspectRatio()
-
getLockMin
public double getLockMin()
-
getLockMax
public double getLockMax()
-
isLockMin
public boolean isLockMin()
- Returns:
- true if the minimum value of the axis is locked.
-
isLockMax
public boolean isLockMax()
- Returns:
- true if the maximum value of the axis is locked.
-
isInitialized
public boolean isInitialized()
- Returns:
- true if the axis is initialized (and should have a valid value for its pixel size.
-
getUpdateMode
public UpdateMode getUpdateMode()
- Returns:
- the axis' UpdateMode
- See Also:
UpdateMode
-
getMin
public double getMin()
- Returns:
- the minimum numeric value displayed by the axis.
-
getMax
public double getMax()
- Returns:
- the maximum numeric value displayed by the axis.
-
getAbsoluteMin
public double getAbsoluteMin()
- Returns:
- the minimum value that getMin() can return.
-
getAbsoluteMax
public double getAbsoluteMax()
- Returns:
- the maximum value that getMax() can return.
-
getSelectionSize
public double getSelectionSize()
- Returns:
- the size of the selected area on the axis in axis units.
-
getSelectionCenter
public double getSelectionCenter()
- Returns:
- the center of the selected area on the axis in axis units.
-
isSelectionLocked
public boolean isSelectionLocked()
- Returns:
- true if the selected region is locked and not updating as the mouse moves.
-
getSizePixels
public int getSizePixels()
- Returns:
- the size of the axis in screen pixels.
-
getMouseValue
public double getMouseValue()
- Returns:
- the position of the mouse cursor in axis units.
-
getPixelsPerValue
public double getPixelsPerValue()
- Returns:
- the number of screen pixels per numeric value.
-
screenPixelToValue
public double screenPixelToValue(double pixel)
- Returns:
- the numeric value corresponding to the given screen pixel.
-
valueToScreenPixel
public int valueToScreenPixel(double value)
- Returns:
- the screen pixel corresponding to the given numeric value.
-
valueToScreenPixelUnits
public double valueToScreenPixelUnits(double value)
- Returns:
- the screen pixel corresponding to the given numeric value (w/o truncation).
-
applyConstraints
public void applyConstraints()
Adjusts the min and max values of the axis to conform to the various axis constraints like absolute bounds and locked min/max.
-
updateLinkedAxes
public void updateLinkedAxes()
-
updateLinkedAxes
public void updateLinkedAxes(Axis1D... ignore)
-
-