Class ScaleItem

  • All Implemented Interfaces:
    IsArea
    Direct Known Subclasses:
    AxisItem

    public class ScaleItem
    extends BaseBoxNodeItem<AxisPosition>
    Wraps the scale item of CHART JS chart.
    This is a wrapper of scale of Chart (of CHART.JS).
    Author:
    Andrea "Stock" Stocchero
    • Constructor Detail

      • ScaleItem

        public ScaleItem​(CallbacksEnvelop<NativeObject> envelop)
        Creates the item using an envelop (from callbacks package) of native java script object which contains all properties.
        Parameters:
        envelop - envelop of native java script object which contains all properties.
    • Method Detail

      • getChart

        public final IsChart getChart()
        Returns the CHARBA chart instance.
        Returns:
        the CHARBA chart instance
      • getId

        public final ScaleId getId()
        Returns the id of scale
        Returns:
        the id of scale.
      • getCharbaId

        public final int getCharbaId()
        Returns the unique id of scale.
        Returns:
        the unique id of scale.
      • getDateAdapter

        public final DateAdapter getDateAdapter()
        Returns the date adapter of the scale if the scale is a time or time series, otherwise new date adapter.
        Returns:
        the date adapter of the scale if the scale is a time or time series, otherwise new date adapter
      • getAxis

        public final AxisKind getAxis()
        Which kind of axis this is.
        Possible values are: ''x', 'y' or 'r'.
        Returns:
        the kind of axis.
      • getType

        public final AxisType getType()
        Returns the type of scale
        Returns:
        the type of scale.
      • getMax

        public final double getMax()
        Returns the max value of scale.
        Returns:
        the max value of scale.
      • getMin

        public final double getMin()
        Returns the minimum value of scale.
        Returns:
        the minimum value of scale.
      • getMaxAsString

        public final String getMaxAsString()
        Returns the max value of scale.
        Returns:
        the max value of scale.
      • getMinAsString

        public final String getMinAsString()
        Returns the minimum value of scale.
        Returns:
        the minimum value of scale.
      • getMaxAsDate

        public final Date getMaxAsDate()
        Returns the max value of scale.
        Returns:
        the max value of scale. If missing returns is null.
      • getMinAsDate

        public final Date getMinAsDate()
        Returns the minimum value of scale.
        Returns:
        the minimum value of scale. If missing returns is null.
      • getTicks

        public final List<ScaleTickItem> getTicks()
        Returns the list of ticks.
        Returns:
        the list of ticks.
      • getLabelRotation

        public final double getLabelRotation()
        Returns the label rotation ratio.
        Returns:
        the label rotation ratio.
      • getStart

        public final double getStart()
        Returns the start value of scale.
        Returns:
        the start value of scale.
      • getEnd

        public final double getEnd()
        Returns the end value of scale.
        Returns:
        the end value of scale.
      • getXCenter

        public final int getXCenter()
        Returns the X center of scale.
        Returns:
        the X center of scale.
      • getYCenter

        public final int getYCenter()
        Returns the Y center of scale.
        Returns:
        the Y center of scale.
      • getDrawingArea

        public final int getDrawingArea()
        Returns the drawing area dimension of scale.
        Returns:
        the drawing area dimension of scale.
      • getPointLabels

        public final List<String> getPointLabels()
        Returns the list of point labels of scale.
        Returns:
        the list of point labels of scale.
      • getLabelItems

        public List<ScaleLabelItem> getLabelItems()
        Returns the labels computed in the scale.
        Returns:
        the labels computed in the scale.
      • isHorizontal

        public final boolean isHorizontal()
        Returns true if the scale is horizontal.
        Returns:
        true if the scale is horizontal
      • format

        public final String format​(Date time)
        Formats the time passed as argument with date configuration.
        Parameters:
        time - epoch time to format
        Returns:
        formatted time
      • format

        public final String format​(long time)
        Formats the time passed as argument with date configuration.
        Parameters:
        time - epoch time to format
        Returns:
        formatted time
      • format

        public final String format​(Date time,
                                   String format)
        Formats the time passed as argument with passed format.
        Parameters:
        time - epoch time to format
        format - string format to apply
        Returns:
        formatted time
      • format

        public final String format​(long time,
                                   String format)
        Formats the time passed as argument with passed format.
        Parameters:
        time - epoch time to format
        format - string format to apply
        Returns:
        formatted time
      • getValueAtEvent

        public final ScaleValueItem getValueAtEvent​(HasNativeEvent container)
        Returns the value on the axis related to an event position.
        Parameters:
        container - event container instance used to get the value from the scale
        Returns:
        the value on the axis related to an event position
      • getValueAtEvent

        public final ScaleValueItem getValueAtEvent​(NativeAbstractMouseEvent event)
        Returns the value on the axis related to an event position.
        Parameters:
        event - event instance used to get the value from the scale
        Returns:
        the value on the axis related to an event position
      • getValueAtPixel

        public final ScaleValueItem getValueAtPixel​(double position)
        Returns the value on the axis related to a position, passed as pixels.
        Parameters:
        position - position in pixel used to get the value from the scale
        Returns:
        the value on the axis related to a position, passed as pixels
      • getDecimalForPixel

        public final double getDecimalForPixel​(double pixel)
        Used to get the data value from a given pixel.
        This is the inverse of getPixelForValue.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        pixel - pixel value
        Returns:
        the data value from a given pixel
      • getPixelForDecimal

        public final double getPixelForDecimal​(double decimal)
        Utility for getting the pixel location of a percentage of scale.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        decimal - number value to use
        Returns:
        the pixel location of a percentage of scale
      • getPixelForTick

        public final double getPixelForTick​(double index)
        Returns the location of the tick at the given index.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        index - tick index to use
        Returns:
        the location of the tick at the given index
      • getLabelForValue

        public final String getLabelForValue​(double value)
        Used to get the label to display in the tooltip for the given value.
        Parameters:
        value - value of the data
        Returns:
        the label to display in the tooltip for the given value
      • getPixelForStringValue

        public final double getPixelForStringValue​(String value)
        Returns the location of the given data point.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        value - value of the data
        Returns:
        the location of the given data point
      • getPixelForStringValue

        public final double getPixelForStringValue​(String value,
                                                   double index)
        Returns the location of the given data point.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        value - value of the data as string
        index - index of the data
        Returns:
        the location of the given data point
      • getPixelForDateValue

        public final double getPixelForDateValue​(Date value)
        Returns the location of the given data point.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        value - value of the data
        Returns:
        the location of the given data point
      • getPixelForDateValue

        public final double getPixelForDateValue​(Date value,
                                                 double index)
        Returns the location of the given data point.
        Value can either be an index or a numerical value.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        value - value of the data as date
        index - index of the data
        Returns:
        the location of the given data point
      • getPixelForValue

        public final double getPixelForValue​(double value)
        Returns the location of the given data point.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        value - value of the data
        Returns:
        the location of the given data point
      • getPixelForValue

        public final double getPixelForValue​(double value,
                                             double index)
        Returns the location of the given data point.
        Value can either be an index or a numerical value.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        value - value of the data
        index - index of the data
        Returns:
        the location of the given data point
      • getValueForPixel

        public final double getValueForPixel​(double pixel)
        Used to get the data value from a given pixel.
        This is the inverse of getPixelForValue.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Parameters:
        pixel - pixel value
        Returns:
        the data value from a given pixel
      • getBaseValue

        public final double getBaseValue()
        Returns the minimum chart value.
        Returns:
        the minimum chart value
      • getBasePixel

        public final double getBasePixel()
        Returns the pixel for the minimum chart value.
        The coordinate (0, 0) is at the upper-left corner of the canvas.
        Returns:
        the pixel for the minimum chart value
      • getDistanceFromCenterForValue

        public final double getDistanceFromCenterForValue​(double value)
        Returns the distance from the center of a specific value.
        Parameters:
        value - the value of to check
        Returns:
        the distance from the center of a specific value
      • getValueForDistanceFromCenter

        public final double getValueForDistanceFromCenter​(double distance)
        Returns the value calculated applying the specific distance from the center.
        Parameters:
        distance - the distance which must be applied
        Returns:
        the value calculated applying the specific distance from the center.
      • isInside

        public default boolean isInside​(NativeBaseEvent event)
        Returns true if the chart event is inside of a chart element, otherwise false.
        Parameters:
        event - event to check if inside of a chart element.
        Returns:
        true if the chart event is inside a chart element, otherwise false
      • isInside

        public default boolean isInside​(HasNativeEvent container)
        Returns true if the chart event is inside of this box, otherwise false.
        Parameters:
        container - event container to check if inside the box
        Returns:
        true if the chart event is inside of this box, otherwise false