Class ConfigurationOptions
- java.lang.Object
-
- org.pepstock.charba.client.configuration.ConfigurationOptions
-
- All Implemented Interfaces:
HasAnimation,ConfigurationElement,AddHandlerEventHandler,EventHandler,RemoveHandlerEventHandler
- Direct Known Subclasses:
AbstractPieOptions,ScalesOptions,TreeMapOptions
public abstract class ConfigurationOptions extends Object implements ConfigurationElement, HasAnimation
Base object which maps chart configuration.
CHARBA stores the unique chart ID in the CHART.JS chart options usingcharbaIdproperty key.
Important topics to take care:
Responsive
When it comes to change the chart size based on the window size, a major limitation is that the canvas render size (canvas.width and .height) can not be expressed with relative values, contrary to the display size (canvas.style.width and .height). Furthermore, these sizes are independent from each other and thus the canvas render size does not adjust automatically based on the display size, making the rendering inaccurate.
It provides a few options to enable responsiveness and control the resize behavior of charts by detecting when the canvas display size changes and update the render size accordingly.
Legend
Sometimes you need a very complex legend. In these cases, it makes sense to generate an HTML legend. Charts provide a generateLegend() method on their prototype that returns an HTML string for the legend. To configure how this legend is generated, you can set the legendCallback.- Author:
- Andrea "Stock" Stocchero
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedConfigurationOptions(IsChart chart, IsDefaultScaledOptions defaultValues)Builds the object storing the chart instance and defaults options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterAxisConfigurationUpdate(Axis axis)Invoked after the axis options has been updated.protected voidafterConfigurationUpdate()Invoked after the chart options has been updated.protected voidbeforeAxisConfigurationUpdate(Axis axis)Invoked before the axis options are going to be updated.protected voidbeforeConfigurationUpdate()Invoked before the chart options are going to be updated.AnimationContainergetAnimationContainer()Returns an animation container instance to use in the default methods of this interface.doublegetAspectRatio()Canvas aspect ratio (i.e.protected AxisgetAxisById(int id)Returns the axis by the unique CHARBA id of scale ornullif not axis.IsColorgetBackgroundColor()Returns the default background color to use in the chart, on all objects, if not override by the specific configuration.StringgetBackgroundColorAsString()Returns the default background color to use in the chart, on all objects, if not override by the specific configuration.IsColorgetBorderColor()Returns the default border color to use in the chart, on all objects, if not override by the specific configuration.StringgetBorderColorAsString()Returns the default border color to use in the chart, on all objects, if not override by the specific configuration.IsChartgetChart()Returns the chart instanceIsColorgetColor()Returns the default color to use in the chart, on all objects, if not override by the specific configuration.StringgetColorAsString()Returns the default color to use in the chart, on all objects, if not override by the specific configuration.protected TgetConfiguration()Returns the configuration element.DatasetsgetDatasets()Returns the data sets element.doublegetDevicePixelRatio()The chart's canvas will use a 1:1 pixel ratio, unless the physical display has a higher pixel ratio (e.g.ElementsgetElements()Returns the elements element.Set<Event>getEvents()Returns the browser events that the chart should listen to.FillergetFiller()Returns the filler plugin configuration.FontgetFont()Returns the font element.HovergetHover()Returns the hover element.InteractiongetInteraction()Returns the interaction element.LayoutgetLayout()Returns the layout element.LegendgetLegend()Returns the legend element.CLocalegetLocale()Returns the locale instance for internationalization.PluginsgetPlugins()Returns the plugins element.doublegetResizeDelay()Returns the delay the resize update by give amount of milliseconds.
This can ease the resize process by debouncing update of the elements.SubtitlegetSubtitle()Returns the subtitle element.TitlegetTitle()Returns the title element.TooltipsgetTooltips()Returns the tooltips element.booleanhasAxisClickHandlers()Returnstrueif there is any axis click handler, otherwisefalse.booleanhasAxisEnterHandlers()Returnstrueif there is any axis enter handler, otherwisefalse.booleanhasAxisHoverHandlers()Returnstrueif there is any axis hover handler, otherwisefalse.booleanhasAxisLeaveHandlers()Returnstrueif there is any axis leave handler, otherwisefalse.booleanhasDatasetSelectionHandlers()Returnstrueif there is any data set selection handler, otherwisefalse.booleanhasSubtitleClickHandlers()Returnstrueif there is any subtitle click handler, otherwisefalse.booleanhasSubtitleEnterHandlers()Returnstrueif there is any subtitle enter handler, otherwisefalse.booleanhasSubtitleLeaveHandlers()Returnstrueif there is any subtitle leave handler, otherwisefalse.booleanhasTitleClickHandlers()Returnstrueif there is any title click handler, otherwisefalse.booleanhasTitleEnterHandlers()Returnstrueif there is any title enter handler, otherwisefalse.booleanhasTitleLeaveHandlers()Returnstrueif there is any title leave handler, otherwisefalse.booleanisDestroyOnDetach()Returnstrueif the chart is configured to be destroyed on the detach from DIV element, otherwisefalse.booleanisDrawOnAttach()Returnstrueif the chart is configured to be drawn on the attach of DIV element, otherwisefalse.booleanisMaintainAspectRatio()Returns the maintaining of the original canvas aspect ratio (width / height) when resizing.booleanisResponsive()Returns the resizing of the chart canvas when its container does.voidload(IsChart chart, Configuration configuration)Called to enable to load in the a configuration object the specific configuration item (by native object).ChartEnvelop<NativeObject>loadNativeObject(ChartEnvelop<NativeObject> envelop)Returns the native object instance inside an envelop.
It can be called only fromorg.pepstock.charba.clientpackage.voidloadOptions(ChartEnvelop<NativeObject> envelop)Merges chart default options (by chart.defaults[type]), default scale options (by chart.defaults.scale) and global options (by chart.defaults.global) and chart options.
The chain of priority is:
chart options chart default options (by chart.defaults[type]) default scale options (by chart.defaults.scale) global options (by chart.defaults.global)voidmerge(NativeObjectContainer source, String property)Merge a native object in the this one with a specific property name.
This is used by plugins implementation (native java script ones) when they are not using the standard way to add plugin configuration in the options of chart.voidonAdd(AddHandlerEvent event)Invoked when a new event handler is added.voidonRemove(RemoveHandlerEvent event)Invoked when a chart event handler is removed.voidsetAspectRatio(double ratio)Canvas aspect ratio (i.e.voidsetBackgroundColor(String backgroundColor)Sets the default background color to use in the chart, on all objects, if not override by the specific configuration.voidsetBackgroundColor(IsColor backgroundColor)Sets the default background color to use in the chart, on all objects, if not override by the specific configuration.voidsetBorderColor(String borderColor)Sets the default border color to use in the chart, on all objects, if not override by the specific configuration.voidsetBorderColor(IsColor borderColor)Sets the default border color to use in the chart, on all objects, if not override by the specific configuration.voidsetChartOptions(ChartEnvelop<NativeObject> envelop)Sets the chart options as underlying configuration options, after the first draw of the chart.
Leveraging on proxy, this is mandatory and enables the possibility to use only the configuration options to update the chart options at runtime.voidsetColor(String color)Sets the default color to use in the chart, on all objects, if not override by the specific configuration.voidsetColor(IsColor color)Sets the default color to use in the chart, on all objects, if not override by the specific configuration.protected voidsetConfiguration(T configuration)voidsetDestroyOnDetach(boolean destroyOnDetach)Setstrueif the chart is configured to be destroyed on the detach from DIV element, otherwisefalse.voidsetDevicePixelRatio(double ratio)The chart's canvas will use a 1:1 pixel ratio, unless the physical display has a higher pixel ratio (e.g.voidsetDrawOnAttach(boolean drawOnAttach)Setstrueif the chart is configured to be draw on the attach of DIV element, otherwisefalse.voidsetEvents(Event... events)Sets the browser events that the chart should listen to.voidsetLocale(CLocale locale)Sets the locale instance for internationalization.voidsetMaintainAspectRatio(boolean maintainAspectRatio)Sets the maintaining of the original canvas aspect ratio (width / height) when resizing.voidsetResizeDelay(int delay)Sets the delay the resize update by give amount of milliseconds.
This can ease the resize process by debouncing update of the elements.voidsetResponsive(boolean responsive)Sets the resizing of the chart canvas when its container does.StringtoJSON()Returns the JSON representation of the object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.pepstock.charba.client.configuration.HasAnimation
getAnimation, getAnimations, getTransitions, isAnimationEnabled, setAnimationEnabled
-
-
-
-
Constructor Detail
-
ConfigurationOptions
protected ConfigurationOptions(IsChart chart, IsDefaultScaledOptions defaultValues)
Builds the object storing the chart instance and defaults options.- Parameters:
chart- chart instancedefaultValues- defaults options
-
-
Method Detail
-
loadOptions
public final void loadOptions(ChartEnvelop<NativeObject> envelop)
Merges chart default options (by chart.defaults[type]), default scale options (by chart.defaults.scale) and global options (by chart.defaults.global) and chart options.
The chain of priority is:
- chart options
- chart default options (by chart.defaults[type])
- default scale options (by chart.defaults.scale)
- global options (by chart.defaults.global)
- Parameters:
envelop- the envelop for options as native options
-
setChartOptions
public final void setChartOptions(ChartEnvelop<NativeObject> envelop)
Sets the chart options as underlying configuration options, after the first draw of the chart.
Leveraging on proxy, this is mandatory and enables the possibility to use only the configuration options to update the chart options at runtime.- Parameters:
envelop- envelop for chart options as native options
-
beforeConfigurationUpdate
protected void beforeConfigurationUpdate()
Invoked before the chart options are going to be updated.
-
afterConfigurationUpdate
protected void afterConfigurationUpdate()
Invoked after the chart options has been updated.
-
beforeAxisConfigurationUpdate
protected void beforeAxisConfigurationUpdate(Axis axis)
Invoked before the axis options are going to be updated.- Parameters:
axis- axis instance which is going to be updated
-
afterAxisConfigurationUpdate
protected void afterAxisConfigurationUpdate(Axis axis)
Invoked after the axis options has been updated.- Parameters:
axis- axis instance which has been updated
-
getAnimationContainer
public final AnimationContainer getAnimationContainer()
Description copied from interface:HasAnimationReturns an animation container instance to use in the default methods of this interface.- Specified by:
getAnimationContainerin interfaceHasAnimation- Returns:
- an animation container instance
-
getHover
public Hover getHover()
Returns the hover element.- Returns:
- the hover
-
getInteraction
public Interaction getInteraction()
Returns the interaction element.- Returns:
- the interaction
-
getLayout
public Layout getLayout()
Returns the layout element.- Returns:
- the layout
-
getLegend
public Legend getLegend()
Returns the legend element.- Returns:
- the legend
-
getTitle
public Title getTitle()
Returns the title element.- Returns:
- the title
-
getSubtitle
public Subtitle getSubtitle()
Returns the subtitle element.- Returns:
- the subtitle
-
getTooltips
public Tooltips getTooltips()
Returns the tooltips element.- Returns:
- the tooltips
-
getElements
public Elements getElements()
Returns the elements element.- Returns:
- the elements
-
getDatasets
public Datasets getDatasets()
Returns the data sets element.- Returns:
- the data sets
-
getPlugins
public Plugins getPlugins()
Returns the plugins element.- Returns:
- the plugins
-
getFiller
public Filler getFiller()
Returns the filler plugin configuration.- Returns:
- the filler plugin configuration
-
getFont
public Font getFont()
Returns the font element.- Returns:
- the font element
-
getAxisById
protected Axis getAxisById(int id)
Returns the axis by the unique CHARBA id of scale ornullif not axis.- Parameters:
id- the unique CHARBA id of scale- Returns:
- the axis or
nullif not axis.
-
setEvents
public void setEvents(Event... events)
Sets the browser events that the chart should listen to.- Parameters:
events- the browser events that the chart should listen to.
-
getEvents
public Set<Event> getEvents()
Returns the browser events that the chart should listen to.- Returns:
- the browser events that the chart should listen to.
-
setLocale
public void setLocale(CLocale locale)
Sets the locale instance for internationalization.- Parameters:
locale- the locale instance
-
getLocale
public CLocale getLocale()
Returns the locale instance for internationalization.- Returns:
- the locale instance
-
setResponsive
public void setResponsive(boolean responsive)
Sets the resizing of the chart canvas when its container does.- Parameters:
responsive- the resizing of the chart canvas when its container does.
-
isResponsive
public boolean isResponsive()
Returns the resizing of the chart canvas when its container does.- Returns:
- the resizing of the chart canvas when its container does.
-
setMaintainAspectRatio
public void setMaintainAspectRatio(boolean maintainAspectRatio)
Sets the maintaining of the original canvas aspect ratio (width / height) when resizing.- Parameters:
maintainAspectRatio- the maintaining of the original canvas aspect ratio (width / height) when resizing.
-
isMaintainAspectRatio
public boolean isMaintainAspectRatio()
Returns the maintaining of the original canvas aspect ratio (width / height) when resizing.- Returns:
- the maintaining of the original canvas aspect ratio (width / height) when resizing.
-
setAspectRatio
public void setAspectRatio(double ratio)
Canvas aspect ratio (i.e. width / height, a value of 1 representing a square canvas).
Note that this option is ignored if the height is explicitly defined either as attribute or via the style.- Parameters:
ratio- the aspect ratio.
-
getAspectRatio
public double getAspectRatio()
Canvas aspect ratio (i.e. width / height, a value of 1 representing a square canvas).
Note that this option is ignored if the height is explicitly defined either as attribute or via the style.- Returns:
- the aspect ratio.
-
setResizeDelay
public void setResizeDelay(int delay)
Sets the delay the resize update by give amount of milliseconds.
This can ease the resize process by debouncing update of the elements.- Parameters:
delay- the delay the resize update by give amount of milliseconds
-
getResizeDelay
public double getResizeDelay()
Returns the delay the resize update by give amount of milliseconds.
This can ease the resize process by debouncing update of the elements.- Returns:
- the delay the resize update by give amount of milliseconds
-
setDevicePixelRatio
public void setDevicePixelRatio(double ratio)
The chart's canvas will use a 1:1 pixel ratio, unless the physical display has a higher pixel ratio (e.g. Retina displays). Setting devicePixelRatio to a value other than 1 will force the canvas size to be scaled by that amount.- Parameters:
ratio- the pixel ratio.
-
getDevicePixelRatio
public double getDevicePixelRatio()
The chart's canvas will use a 1:1 pixel ratio, unless the physical display has a higher pixel ratio (e.g. Retina displays). Setting devicePixelRatio to a value other than 1 will force the canvas size to be scaled by that amount. Returns the pixel ratio.- Returns:
- the pixel ratio..
-
isDrawOnAttach
public boolean isDrawOnAttach()
Returnstrueif the chart is configured to be drawn on the attach of DIV element, otherwisefalse.- Returns:
- the drawOnAttach
trueif the chart is configured to be drawn on the attach of DIV element, otherwisefalse.
-
setDrawOnAttach
public void setDrawOnAttach(boolean drawOnAttach)
Setstrueif the chart is configured to be draw on the attach of DIV element, otherwisefalse.- Parameters:
drawOnAttach- the drawOnAttach to set
-
isDestroyOnDetach
public boolean isDestroyOnDetach()
Returnstrueif the chart is configured to be destroyed on the detach from DIV element, otherwisefalse.- Returns:
- the destroyOnDetach
trueif the chart is configured to be destroyed on the detach from DIV element, otherwisefalse.
-
setDestroyOnDetach
public void setDestroyOnDetach(boolean destroyOnDetach)
Setstrueif the chart is configured to be destroyed on the detach from DIV element, otherwisefalse.- Parameters:
destroyOnDetach- the destroyOnDetach to set
-
setColor
public void setColor(IsColor color)
Sets the default color to use in the chart, on all objects, if not override by the specific configuration.- Parameters:
color- color to use in the chart.
-
setColor
public void setColor(String color)
Sets the default color to use in the chart, on all objects, if not override by the specific configuration.- Parameters:
color- color to use in the chart.
-
getColorAsString
public String getColorAsString()
Returns the default color to use in the chart, on all objects, if not override by the specific configuration.- Returns:
- color to use in the chart.
-
getColor
public IsColor getColor()
Returns the default color to use in the chart, on all objects, if not override by the specific configuration.- Returns:
- color to use in the chart.
-
setBackgroundColor
public void setBackgroundColor(IsColor backgroundColor)
Sets the default background color to use in the chart, on all objects, if not override by the specific configuration.- Parameters:
backgroundColor- background color to use in the chart.
-
setBackgroundColor
public void setBackgroundColor(String backgroundColor)
Sets the default background color to use in the chart, on all objects, if not override by the specific configuration.- Parameters:
backgroundColor- background color to use in the chart.
-
getBackgroundColorAsString
public String getBackgroundColorAsString()
Returns the default background color to use in the chart, on all objects, if not override by the specific configuration.- Returns:
- background color to use in the chart.
-
getBackgroundColor
public IsColor getBackgroundColor()
Returns the default background color to use in the chart, on all objects, if not override by the specific configuration.- Returns:
- background color to use in the chart.
-
setBorderColor
public void setBorderColor(IsColor borderColor)
Sets the default border color to use in the chart, on all objects, if not override by the specific configuration.- Parameters:
borderColor- border color to use in the chart.
-
setBorderColor
public void setBorderColor(String borderColor)
Sets the default border color to use in the chart, on all objects, if not override by the specific configuration.- Parameters:
borderColor- border color to use in the chart.
-
getBorderColorAsString
public String getBorderColorAsString()
Returns the default border color to use in the chart, on all objects, if not override by the specific configuration.- Returns:
- border color to use in the chart.
-
getBorderColor
public IsColor getBorderColor()
Returns the default border color to use in the chart, on all objects, if not override by the specific configuration.- Returns:
- border color to use in the chart.
-
hasDatasetSelectionHandlers
public final boolean hasDatasetSelectionHandlers()
Returnstrueif there is any data set selection handler, otherwisefalse.- Returns:
trueif there is any data set selection handler, otherwisefalse.
-
hasTitleClickHandlers
public final boolean hasTitleClickHandlers()
Returnstrueif there is any title click handler, otherwisefalse.- Returns:
trueif there is any title click handler, otherwisefalse.
-
hasTitleEnterHandlers
public final boolean hasTitleEnterHandlers()
Returnstrueif there is any title enter handler, otherwisefalse.- Returns:
trueif there is any title enter handler, otherwisefalse.
-
hasTitleLeaveHandlers
public final boolean hasTitleLeaveHandlers()
Returnstrueif there is any title leave handler, otherwisefalse.- Returns:
trueif there is any title leave handler, otherwisefalse.
-
hasSubtitleClickHandlers
public final boolean hasSubtitleClickHandlers()
Returnstrueif there is any subtitle click handler, otherwisefalse.- Returns:
trueif there is any subtitle click handler, otherwisefalse.
-
hasSubtitleEnterHandlers
public final boolean hasSubtitleEnterHandlers()
Returnstrueif there is any subtitle enter handler, otherwisefalse.- Returns:
trueif there is any subtitle enter handler, otherwisefalse.
-
hasSubtitleLeaveHandlers
public final boolean hasSubtitleLeaveHandlers()
Returnstrueif there is any subtitle leave handler, otherwisefalse.- Returns:
trueif there is any subtitle leave handler, otherwisefalse.
-
hasAxisClickHandlers
public final boolean hasAxisClickHandlers()
Returnstrueif there is any axis click handler, otherwisefalse.- Returns:
trueif there is any axis click handler, otherwisefalse.
-
hasAxisHoverHandlers
public final boolean hasAxisHoverHandlers()
Returnstrueif there is any axis hover handler, otherwisefalse.- Returns:
trueif there is any axis hover handler, otherwisefalse.
-
hasAxisEnterHandlers
public final boolean hasAxisEnterHandlers()
Returnstrueif there is any axis enter handler, otherwisefalse.- Returns:
trueif there is any axis enter handler, otherwisefalse.
-
hasAxisLeaveHandlers
public final boolean hasAxisLeaveHandlers()
Returnstrueif there is any axis leave handler, otherwisefalse.- Returns:
trueif there is any axis leave handler, otherwisefalse.
-
onAdd
public final void onAdd(AddHandlerEvent event)
Description copied from interface:AddHandlerEventHandlerInvoked when a new event handler is added.- Specified by:
onAddin interfaceAddHandlerEventHandler- Parameters:
event- event to be consumed
-
onRemove
public final void onRemove(RemoveHandlerEvent event)
Description copied from interface:RemoveHandlerEventHandlerInvoked when a chart event handler is removed.- Specified by:
onRemovein interfaceRemoveHandlerEventHandler- Parameters:
event- event to be consumed
-
load
public final void load(IsChart chart, Configuration configuration)
Description copied from interface:ConfigurationElementCalled to enable to load in the a configuration object the specific configuration item (by native object).- Specified by:
loadin interfaceConfigurationElement- Parameters:
chart- chart instanceconfiguration- chart configuration instance
-
setConfiguration
protected final void setConfiguration(T configuration)
- Parameters:
configuration- the configuration to set
-
getConfiguration
protected final T getConfiguration()
Returns the configuration element.- Returns:
- the configuration element.
-
merge
public final void merge(NativeObjectContainer source, String property)
Merge a native object in the this one with a specific property name.
This is used by plugins implementation (native java script ones) when they are not using the standard way to add plugin configuration in the options of chart.- Parameters:
source- native object container to addproperty- property name
-
toJSON
public final String toJSON()
Returns the JSON representation of the object.- Returns:
- the JSON representation of the object.
-
loadNativeObject
public final ChartEnvelop<NativeObject> loadNativeObject(ChartEnvelop<NativeObject> envelop)
Returns the native object instance inside an envelop.
It can be called only fromorg.pepstock.charba.clientpackage.- Parameters:
envelop- envelop instance which will contain the native object- Returns:
- the envelop, passed as argument, loaded with the native object
-
getChart
public final IsChart getChart()
Returns the chart instance- Returns:
- the chart
-
-