Package org.pepstock.charba.client
Class Helpers
- java.lang.Object
-
- org.pepstock.charba.client.Helpers
-
public final class Helpers extends Object
Singleton object to use the helpers utility of CHART.JS.
It maps the java script objectchart.helpers
.- Author:
- Andrea "Stock" Stocchero
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clipArea(Canvas canvas, double width, double height)
Clips an area on the canvas context, using theContext2dItem
of the canvas.
The area is specified by size.
Starting points are 0.void
clipArea(Canvas canvas, double x, double y, double width, double height)
Clips an area on the canvas context, using theContext2dItem
of the canvas.
The area is specified by coordinates and size.void
clipArea(Canvas canvas, IsArea area)
Clips an area on the canvas context, using theContext2dItem
of the canvas.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.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.void
clipArea(Context2dItem context, IsArea area)
Clips an area on the canvas context.void
clipArea(IsChart chart)
Clips an area on the canvas context using theChartAreaNode
of the chart.void
clipArea(IsChart chart, double width, double height)
Clips an area on the canvas context, using theCanvas
of the chart.
The area is specified by size.
Starting points are 0.void
clipArea(IsChart chart, double x, double y, double width, double height)
Clips an area on the canvas context, using theCanvas
of the chart.
The area is specified by coordinates and size.void
clipArea(IsChart chart, IsArea area)
Clips an area on the canvas context, using theCanvas
of the chart.NativeObject
clone(NativeObject source)
Returns a deep copy of source without keeping references on objects and arrays.String
formatNumber(double number)
Format a number using a localized number formatter.
It uses the locale of the browser.String
formatNumber(double number, String locale)
Format a number using a localized number formatter.String
formatNumber(double number, String locale, NumberFormatOptions options)
Format a number using a localized number formatter.String
formatNumber(double number, CLocale locale)
Format a number using a localized number formatter.String
formatNumber(double number, CLocale locale, NumberFormatOptions options)
Format a number using a localized number formatter.static Helpers
get()
Singleton method to get the instanceEventPoint
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.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.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.boolean
interpolate(boolean from, boolean to, double factor)
Returns an interpolated value for a boolean for a specific type from CHART.JS.double
interpolate(double from, double to, double factor)
Returns an interpolated value for a number for a specific type from CHART.JS.String
interpolate(String from, String to, double factor)
Returns an interpolated value for a color (as string) for a specific type from CHART.JS.IsColor
interpolate(IsColor from, IsColor to, double factor)
Returns an interpolated value for a color for a specific type from CHART.JS.void
loadInteraction(InteractionEnvelop<NativeObject> envelop)
Loads the interaction module from CHART.JS.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.IsImmutableFont
toFont(IsDefaultFont font)
Parses font options and returns a normalized font object.IsImmutableFont
toFont(FontItem font)
Parses font options and returns a normalized font object.String
toFontString(IsDefaultFont font)
Builds the font string (shorthand property of CSS font) to use in the canvas object.
See here CSS specification.String
toFontString(FontItem font)
Builds the font string (shorthand property of CSS font) to use in the canvas object.
See here CSS specification.void
unclipArea(Context2dItem context)
Unclips the area previously set.
-
-
-
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 instanceevent
- 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 instanceevent
- 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 theChartAreaNode
of the chart.- Parameters:
chart
- chart instance
-
clipArea
public void clipArea(IsChart chart, IsArea area)
Clips an area on the canvas context, using theCanvas
of the chart.- Parameters:
chart
- chart instancearea
- area to clip on the context
-
clipArea
public void clipArea(IsChart chart, double width, double height)
Clips an area on the canvas context, using theCanvas
of the chart.
The area is specified by size.
Starting points are 0.- Parameters:
chart
- chart instancewidth
- the rectangle's width. Positive values are to the right, and negative to the leftheight
- 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 theCanvas
of the chart.
The area is specified by coordinates and size.- Parameters:
chart
- chart instancex
- the x-axis coordinate of the rectangle's starting pointy
- the y-axis coordinate of the rectangle's starting pointwidth
- the rectangle's width. Positive values are to the right, and negative to the leftheight
- 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 theContext2dItem
of the canvas.- Parameters:
canvas
- canvas where to apply the clipppingarea
- area to clip on the context
-
clipArea
public void clipArea(Canvas canvas, double width, double height)
Clips an area on the canvas context, using theContext2dItem
of the canvas.
The area is specified by size.
Starting points are 0.- Parameters:
canvas
- canvas where to apply the clipppingwidth
- the rectangle's width. Positive values are to the right, and negative to the leftheight
- 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 theContext2dItem
of the canvas.
The area is specified by coordinates and size.- Parameters:
canvas
- canvas where to apply the clipppingx
- the x-axis coordinate of the rectangle's starting pointy
- the y-axis coordinate of the rectangle's starting pointwidth
- the rectangle's width. Positive values are to the right, and negative to the leftheight
- 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 canvasarea
- 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 canvaswidth
- the rectangle's width. Positive values are to the right, and negative to the leftheight
- 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 canvasx
- the x-axis coordinate of the rectangle's starting pointy
- the y-axis coordinate of the rectangle's starting pointwidth
- the rectangle's width. Positive values are to the right, and negative to the leftheight
- 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 formatlocale
- the locale to pass to theIntl.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 formatlocale
- the locale to pass to theIntl.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 formatlocale
- the locale to pass to theIntl.NumberFormat
constructoroptions
-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 formatlocale
- the locale to pass to theIntl.NumberFormat
constructoroptions
-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 valueto
- ending valuefactor
- 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 valueto
- ending valuefactor
- 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 valueto
- ending valuefactor
- 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 valueto
- ending valuefactor
- interpolation factor- Returns:
- interpolated value for specific type
-
-