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 voidclipArea(Canvas canvas, double width, double height)Clips an area on the canvas context, using theContext2dItemof the canvas.
The area is specified by size.
Starting points are 0.voidclipArea(Canvas canvas, double x, double y, double width, double height)Clips an area on the canvas context, using theContext2dItemof the canvas.
The area is specified by coordinates and size.voidclipArea(Canvas canvas, IsArea area)Clips an area on the canvas context, using theContext2dItemof the canvas.voidclipArea(Context2dItem context, double width, double height)Clips an area on the canvas context.
The area is specified by size.
Starting points are 0.voidclipArea(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.voidclipArea(Context2dItem context, IsArea area)Clips an area on the canvas context.voidclipArea(IsChart chart)Clips an area on the canvas context using theChartAreaNodeof the chart.voidclipArea(IsChart chart, double width, double height)Clips an area on the canvas context, using theCanvasof the chart.
The area is specified by size.
Starting points are 0.voidclipArea(IsChart chart, double x, double y, double width, double height)Clips an area on the canvas context, using theCanvasof the chart.
The area is specified by coordinates and size.voidclipArea(IsChart chart, IsArea area)Clips an area on the canvas context, using theCanvasof the chart.NativeObjectclone(NativeObject source)Returns a deep copy of source without keeping references on objects and arrays.StringformatNumber(double number)Format a number using a localized number formatter.
It uses the locale of the browser.StringformatNumber(double number, String locale)Format a number using a localized number formatter.StringformatNumber(double number, String locale, NumberFormatOptions options)Format a number using a localized number formatter.StringformatNumber(double number, CLocale locale)Format a number using a localized number formatter.StringformatNumber(double number, CLocale locale, NumberFormatOptions options)Format a number using a localized number formatter.static Helpersget()Singleton method to get the instanceEventPointgetRelativePosition(ChartEventContext eventContext)A common occurrence is taking an event, such as a click, and finding the data coordinates on the chart where the event occurred.EventPointgetRelativePosition(IsChart chart, BaseNativeEvent event)A common occurrence is taking an event, such as a click, and finding the data coordinates on the chart where the event occurred.EventPointgetRelativePosition(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.NativeObjectmergeIf(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.IsImmutableFonttoFont(IsDefaultFont font)Parses font options and returns a normalized font object.IsImmutableFonttoFont(FontItem font)Parses font options and returns a normalized font object.StringtoFontString(IsDefaultFont font)Builds the font string (shorthand property of CSS font) to use in the canvas object.
See here CSS specification.StringtoFontString(FontItem font)Builds the font string (shorthand property of CSS font) to use in the canvas object.
See here CSS specification.voidunclipArea(Context2dItem context)Unclips the area previously set.
-
-
-
Method Detail
-
get
public static Helpers get()
Singleton method to get the instance- Returns:
- helper instance
-
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(ChartEventContext eventContext)
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:
eventContext- event context 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, BaseNativeEvent 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 theChartAreaNodeof the chart.- Parameters:
chart- chart instance
-
clipArea
public void clipArea(IsChart chart, IsArea area)
Clips an area on the canvas context, using theCanvasof 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 theCanvasof 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 theCanvasof 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 theContext2dItemof 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 theContext2dItemof 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 theContext2dItemof 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.NumberFormatconstructor- 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.NumberFormatconstructor- 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.NumberFormatconstructoroptions-Intlnumber 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.NumberFormatconstructoroptions-Intlnumber format options- Returns:
- a number formatted string
-
-