Class Helpers


  • public final class Helpers
    extends Object
    Singleton object to use the helpers utility of CHART.JS.
    It maps the java script object chart.helpers.
    Author:
    Andrea "Stock" Stocchero
    • Method Detail

      • get

        public static Helpers get()
        Singleton method to get the instance
        Returns:
        helper instance
      • loadInteraction

        public void loadInteraction​(InteractionEnvelop<NativeObject> envelop)
        Loads the interaction module from CHART.JS.
        Parameters:
        envelop - object to wrap the native object of interaction
      • mergeIf

        public NativeObject mergeIf​(NativeObject target,
                                    NativeObject source)
        Recursively deep copies source properties in the target only if not defined in target.
        IMPORTANT: target is not cloned and will be updated with source properties.
        Parameters:
        target - the target object in which all sources are merged into.
        source - object to merge in the target.
        Returns:
        the target object. If target and source are nulls, an empty native object is returned is returned.
      • clone

        public NativeObject clone​(NativeObject source)
        Returns a deep copy of source without keeping references on objects and arrays.
        Parameters:
        source - the object to clone.
        Returns:
        a clone of source object
      • getRelativePosition

        public EventPoint getRelativePosition​(AbstractEvent event)
        A common occurrence is taking an event, such as a click, and finding the data coordinates on the chart where the event occurred. It provides the relative point on canvas.
        Parameters:
        event - native event to be used for getting the point.
        Returns:
        a point object
      • getRelativePosition

        public EventPoint getRelativePosition​(IsChart chart,
                                              AbstractEvent event)
        A common occurrence is taking an event, such as a click, and finding the data coordinates on the chart where the event occurred. It provides the relative point on canvas.
        Parameters:
        chart - chart instance
        event - native event to be used for getting the point.
        Returns:
        a point object
      • getRelativePosition

        public EventPoint getRelativePosition​(IsChart chart,
                                              NativeBaseEvent event)
        A common occurrence is taking an event, such as a click, and finding the data coordinates on the chart where the event occurred. It provides the relative point on canvas.
        Parameters:
        chart - chart instance
        event - native event to be used for getting the point.
        Returns:
        a point object
      • toFont

        public IsImmutableFont toFont​(IsDefaultFont font)
        Parses font options and returns a normalized font object.
        Parameters:
        font - a object that contains font options to be parsed.
        Returns:
        a font object
      • toFont

        public IsImmutableFont toFont​(FontItem font)
        Parses font options and returns a normalized font object.
        Parameters:
        font - a object that contains font options to be parsed.
        Returns:
        a font object
      • toFontString

        public String toFontString​(IsDefaultFont font)
        Builds the font string (shorthand property of CSS font) to use in the canvas object.
        See here CSS specification.
        Parameters:
        font - a object that contains font options to be parsed.
        Returns:
        the font string to use in the canvas object.
      • toFontString

        public String toFontString​(FontItem font)
        Builds the font string (shorthand property of CSS font) to use in the canvas object.
        See here CSS specification.
        Parameters:
        font - a object that contains font options to be parsed.
        Returns:
        the font string to use in the canvas object.
      • clipArea

        public void clipArea​(IsChart chart)
        Clips an area on the canvas context using the ChartAreaNode of the chart.
        Parameters:
        chart - chart instance
      • clipArea

        public void clipArea​(IsChart chart,
                             IsArea area)
        Clips an area on the canvas context, using the Canvas of the chart.
        Parameters:
        chart - chart instance
        area - area to clip on the context
      • clipArea

        public void clipArea​(IsChart chart,
                             double width,
                             double height)
        Clips an area on the canvas context, using the Canvas of the chart.
        The area is specified by size.
        Starting points are 0.
        Parameters:
        chart - chart instance
        width - the rectangle's width. Positive values are to the right, and negative to the left
        height - the rectangle's height. Positive values are down, and negative are up
      • clipArea

        public void clipArea​(IsChart chart,
                             double x,
                             double y,
                             double width,
                             double height)
        Clips an area on the canvas context, using the Canvas of the chart.
        The area is specified by coordinates and size.
        Parameters:
        chart - chart instance
        x - the x-axis coordinate of the rectangle's starting point
        y - the y-axis coordinate of the rectangle's starting point
        width - the rectangle's width. Positive values are to the right, and negative to the left
        height - the rectangle's height. Positive values are down, and negative are up
      • clipArea

        public void clipArea​(Canvas canvas,
                             IsArea area)
        Clips an area on the canvas context, using the Context2dItem of the canvas.
        Parameters:
        canvas - canvas where to apply the clippping
        area - area to clip on the context
      • clipArea

        public void clipArea​(Canvas canvas,
                             double width,
                             double height)
        Clips an area on the canvas context, using the Context2dItem of the canvas.
        The area is specified by size.
        Starting points are 0.
        Parameters:
        canvas - canvas where to apply the clippping
        width - the rectangle's width. Positive values are to the right, and negative to the left
        height - the rectangle's height. Positive values are down, and negative are up
      • clipArea

        public void clipArea​(Canvas canvas,
                             double x,
                             double y,
                             double width,
                             double height)
        Clips an area on the canvas context, using the Context2dItem of the canvas.
        The area is specified by coordinates and size.
        Parameters:
        canvas - canvas where to apply the clippping
        x - the x-axis coordinate of the rectangle's starting point
        y - the y-axis coordinate of the rectangle's starting point
        width - the rectangle's width. Positive values are to the right, and negative to the left
        height - the rectangle's height. Positive values are down, and negative are up
      • clipArea

        public void clipArea​(Context2dItem context,
                             IsArea area)
        Clips an area on the canvas context.
        Parameters:
        context - context of the canvas
        area - area to clip on the context
      • clipArea

        public void clipArea​(Context2dItem context,
                             double width,
                             double height)
        Clips an area on the canvas context.
        The area is specified by size.
        Starting points are 0.
        Parameters:
        context - context of the canvas
        width - the rectangle's width. Positive values are to the right, and negative to the left
        height - the rectangle's height. Positive values are down, and negative are up
      • clipArea

        public void clipArea​(Context2dItem context,
                             double x,
                             double y,
                             double width,
                             double height)
        Clips an area on the canvas context.
        The area is specified by coordinates and size.
        Parameters:
        context - context of the canvas
        x - the x-axis coordinate of the rectangle's starting point
        y - the y-axis coordinate of the rectangle's starting point
        width - the rectangle's width. Positive values are to the right, and negative to the left
        height - the rectangle's height. Positive values are down, and negative are up
      • unclipArea

        public void unclipArea​(Context2dItem context)
        Unclips the area previously set.
        Parameters:
        context - context of the canvas where an area has been clipped.
      • formatNumber

        public String formatNumber​(double number)
        Format a number using a localized number formatter.
        It uses the locale of the browser.
        Parameters:
        number - the number to format
        Returns:
        a number formatted string
      • formatNumber

        public String formatNumber​(double number,
                                   CLocale locale)
        Format a number using a localized number formatter.
        Parameters:
        number - the number to format
        locale - the locale to pass to the Intl.NumberFormat constructor
        Returns:
        a number formatted string
      • formatNumber

        public String formatNumber​(double number,
                                   String locale)
        Format a number using a localized number formatter.
        Parameters:
        number - the number to format
        locale - the locale to pass to the Intl.NumberFormat constructor
        Returns:
        a number formatted string
      • formatNumber

        public String formatNumber​(double number,
                                   CLocale locale,
                                   NumberFormatOptions options)
        Format a number using a localized number formatter.
        Parameters:
        number - the number to format
        locale - the locale to pass to the Intl.NumberFormat constructor
        options - Intl number format options
        Returns:
        a number formatted string
      • formatNumber

        public String formatNumber​(double number,
                                   String locale,
                                   NumberFormatOptions options)
        Format a number using a localized number formatter.
        Parameters:
        number - the number to format
        locale - the locale to pass to the Intl.NumberFormat constructor
        options - Intl number format options
        Returns:
        a number formatted string
      • interpolate

        public double interpolate​(double from,
                                  double to,
                                  double factor)
        Returns an interpolated value for a number for a specific type from CHART.JS.
        Parameters:
        from - starting value
        to - ending value
        factor - interpolation factor
        Returns:
        interpolated value for specific type
      • interpolate

        public String interpolate​(String from,
                                  String to,
                                  double factor)
        Returns an interpolated value for a color (as string) for a specific type from CHART.JS.
        Parameters:
        from - starting value
        to - ending value
        factor - interpolation factor
        Returns:
        interpolated value for specific type
      • interpolate

        public IsColor interpolate​(IsColor from,
                                   IsColor to,
                                   double factor)
        Returns an interpolated value for a color for a specific type from CHART.JS.
        Parameters:
        from - starting value
        to - ending value
        factor - interpolation factor
        Returns:
        interpolated value for specific type
      • interpolate

        public boolean interpolate​(boolean from,
                                   boolean to,
                                   double factor)
        Returns an interpolated value for a boolean for a specific type from CHART.JS.
        Parameters:
        from - starting value
        to - ending value
        factor - interpolation factor
        Returns:
        interpolated value for specific type