Class DefaultNumericAxis

  • All Implemented Interfaces:
    Axis, javafx.beans.Observable, javafx.css.Styleable, javafx.event.EventTarget
    Direct Known Subclasses:
    CategoryAxis

    public class DefaultNumericAxis
    extends AbstractAxis
    A axis class that plots a range of numbers with major tick marks every "tickUnit". You can use any Number type with this axis, Long, Double, BigDecimal etc.

    Compared to the NumberAxis, this one has a few additional features:

    Author:
    rstein
    • Field Detail

      • DEFAULT_LOG_MIN_VALUE

        public static final double DEFAULT_LOG_MIN_VALUE
        See Also:
        Constant Field Values
      • isUpdating

        protected boolean isUpdating
      • isLogAxis

        protected boolean isLogAxis
    • Constructor Detail

      • DefaultNumericAxis

        public DefaultNumericAxis​(java.lang.String axisLabel)
        Creates an auto-ranging Axis.
        Parameters:
        axisLabel - the axis label
      • DefaultNumericAxis

        public DefaultNumericAxis​(java.lang.String axisLabel,
                                  java.lang.String unit)
        Creates an auto-ranging Axis.
        Parameters:
        axisLabel - the axis label
        unit - the unit of the axis axis label
      • DefaultNumericAxis

        public DefaultNumericAxis()
        Creates an auto-ranging Axis.
      • DefaultNumericAxis

        public DefaultNumericAxis​(double lowerBound,
                                  double upperBound,
                                  double tickUnit)
        Creates a non-auto-ranging Axis with the given upper bound, lower bound and tick unit.
        Parameters:
        lowerBound - the lower bound of the axis
        upperBound - the upper bound of the axis
        tickUnit - the tick unit, i.e. space between tick marks
      • DefaultNumericAxis

        public DefaultNumericAxis​(java.lang.String axisLabel,
                                  double lowerBound,
                                  double upperBound,
                                  double tickUnit)
        Create a non-auto-ranging Axis with the given upper bound, lower bound and tick unit.
        Parameters:
        axisLabel - the axis label
        lowerBound - the lower bound of the axis
        upperBound - the upper bound of the axis
        tickUnit - the tick unit, i.e. space between tick marks
    • Method Detail

      • getAxisTransform

        public AxisTransform getAxisTransform()
        Gets the transformation (linear, logarithmic, etc) applied to the values of this axis.
        Returns:
        the axis transformation
      • forceZeroInRangeProperty

        public javafx.beans.property.BooleanProperty forceZeroInRangeProperty()
        When true zero is always included in the visible range. This only has effect if auto-ranging is on.
        Returns:
        forceZeroInRange property
      • isForceZeroInRange

        public boolean isForceZeroInRange()
        Returns the value of the forceZeroInRangeProperty().
        Returns:
        value of the forceZeroInRange property
      • setForceZeroInRange

        public void setForceZeroInRange​(boolean value)
        Sets the value of the forceZeroInRangeProperty().
        Parameters:
        value - if true, zero is always included in the visible range
      • logAxisProperty

        public javafx.beans.property.BooleanProperty logAxisProperty()
        When true axis is being a log-axis (default = false)
        Returns:
        logAxis property
        See Also:
        for more infomation
      • isLogAxis

        public boolean isLogAxis()
        Returns the value of the logAxisProperty().
        Returns:
        value of the logAxis property
      • setLogAxis

        public void setLogAxis​(boolean value)
        Sets the value of the logAxisProperty().
        Parameters:
        value - if true, log axis is drawn
      • getLogAxisType

        public LogAxisType getLogAxisType()
        Returns:
        the log axis Type @see LogAxisType
      • logarithmBaseProperty

        public javafx.beans.property.DoubleProperty logarithmBaseProperty()
        Base of the logarithm used by the axis, must be grater than 1.

        Default value: 10

        Returns:
        base of the logarithm
      • getLogarithmBase

        public double getLogarithmBase()
        Returns the value of the logarithmBaseProperty().
        Returns:
        base of the logarithm
      • setLogarithmBase

        public void setLogarithmBase​(double value)
        Sets value of the logarithmBaseProperty().
        Parameters:
        value - base of the logarithm, value > 1
      • calculateMajorTickValues

        protected java.util.List<java.lang.Double> calculateMajorTickValues​(double axisLength,
                                                                            AxisRange axisRange)
        Description copied from class: AbstractAxis
        Calculate a list of all the data values for each tick mark in range
        Specified by:
        calculateMajorTickValues in class AbstractAxis
        Parameters:
        axisLength - The length of the axis in display units
        axisRange - A range object returned from autoRange()
        Returns:
        A list of tick marks that fit along the axis if it was the given length
      • calculateMinorTickValues

        protected java.util.List<java.lang.Double> calculateMinorTickValues()
        Description copied from class: AbstractAxis
        Calculate a list of the data values for every minor tick mark
        Specified by:
        calculateMinorTickValues in class AbstractAxis
        Returns:
        List of data values where to draw minor tick marks
      • autoRange

        protected AxisRange autoRange​(double minValue,
                                      double maxValue,
                                      double length,
                                      double labelSize)
        Overrides:
        autoRange in class AbstractAxis
      • getEffectiveRange

        protected static double getEffectiveRange​(double min,
                                                  double max)
      • clampBoundToZero

        protected static double clampBoundToZero​(double paddedBound,
                                                 double bound)
        If padding pushed the bound above or below zero - stick it to zero.
        Parameters:
        paddedBound - padded version of bound
        bound - computed raw version of bound
        Returns:
        clamped value
      • computeTickUnit

        protected double computeTickUnit​(double rawTickUnit)
      • computePreferredTickUnit

        public double computePreferredTickUnit​(double axisLength)
        Computes the preferred tick unit based on the upper/lower bounds and the length of the axis in screen coordinates.
        Specified by:
        computePreferredTickUnit in class AbstractAxis
        Parameters:
        axisLength - the length in screen coordinates
        Returns:
        the tick unit
      • getDisplayPosition

        public double getDisplayPosition​(double value)
        Get the display position along this axis for a given value. If the value is not in the current range, the returned value will be an extrapolation of the display position. -- cached double optimised version (shaves of 50% on delays)
        Specified by:
        getDisplayPosition in interface Axis
        Overrides:
        getDisplayPosition in class AbstractAxis
        Parameters:
        value - The data value to work out display position for
        Returns:
        display position
      • getValueForDisplay

        public double getValueForDisplay​(double displayPosition)
        Get the data value for the given display position on this axis. If the axis is a CategoryAxis this will be the nearest value. -- cached double optimised version (shaves of 50% on delays)
        Parameters:
        displayPosition - A pixel position on this axis
        Returns:
        the nearest data value to the given pixel position or null if not on axis;
      • getZeroPosition

        public double getZeroPosition()
        Get the display position of the zero line along this axis.
        Specified by:
        getZeroPosition in interface Axis
        Overrides:
        getZeroPosition in class AbstractAxis
        Returns:
        display position or Double.NaN if zero is not in current range;
      • isValueOnAxis

        public boolean isValueOnAxis​(double value)
        Checks if the given value is plottable on this axis
        Specified by:
        isValueOnAxis in interface Axis
        Overrides:
        isValueOnAxis in class AbstractAxis
        Parameters:
        value - The value to check if its on axis
        Returns:
        true if the given value is plottable on this axis
      • requestAxisLayout

        public void requestAxisLayout()
        Description copied from class: AbstractAxis
        Request that the axis is laid out in the next layout pass. This replaces requestLayout() as it has been overridden to do nothing so that changes to children's bounds etc do not cause a layout. This was done as a optimisation as the Axis knows the exact minimal set of changes that really need layout to be updated. So we only want to request layout then, not on any child change.
        Specified by:
        requestAxisLayout in interface Axis
        Overrides:
        requestAxisLayout in class AbstractAxis
      • updateCachedVariables

        protected void updateCachedVariables()
        Description copied from class: AbstractAxis
        to be overwritten by derived class that want to cache variables for efficiency reasons
        Overrides:
        updateCachedVariables in class AbstractAxis