Package org.pepstock.charba.client.data
Class Dataset
- java.lang.Object
-
- org.pepstock.charba.client.commons.NativeObjectContainer
-
- org.pepstock.charba.client.commons.AbstractNode
-
- org.pepstock.charba.client.data.Dataset
-
- All Implemented Interfaces:
HasCallbackScope
,HasDataset
,IsDefaultAnimationContainer
,IsDefaultAnimationTransition
,HasAnimationOptions
- Direct Known Subclasses:
HoverFlexDataset
,LiningDataset
,MeterDataset
,SankeyDataset
public abstract class Dataset extends AbstractNode implements HasDataset, HasAnimationOptions, HasCallbackScope
The chart allows a number of properties to be specified for each data set. These are used to set display properties for a specific data set.
This is the base implementation for all data sets with common fields.- Author:
- Andrea "Stock" Stocchero
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
Dataset.CanvasObjectProperty
Name of common properties of native object related to a dataset.protected static class
Dataset.CommonProperty
Name of common properties of native object related to a dataset.
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
DEFAULT_HIDDEN
protected static boolean
DEFAULT_NORMALIZED
protected static boolean
DEFAULT_PARSING
-
Constructor Summary
Constructors Modifier Constructor Description protected
Dataset(Type type, IsDefaultOptions defaultValues, boolean hidden)
Creates the data set using a default and chart type related to the data set, adding patterns and gradients element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DatasetContext
createContext(NativeObject context)
Creates a data set context for callback.AnimationContainer
getAnimationContainer()
Returns an animation container instance to use in the default methods of this interface.ColorCallback<DatasetContext>
getBackgroundColorCallback()
Returns the background color callback, if set, otherwisenull
.ColorCallback<DatasetContext>
getBorderColorCallback()
Returns the border color callback, if set, otherwisenull
.double
getClip()
Returns how to clip relative to the chart area.
Positive value allows overflow, negative value clips that many pixels inside the chart area.Clip
getClipAsObject()
Returns how to clip relative to the chart area.
Positive value allows overflow, negative value clips that many pixels inside the chart area.List<Double>
getData()
Returns the data property of a data set for a chart is specified as a list of numbers.
Each point in the data list corresponds to the label at the same index on the x axis.List<Double>
getData(boolean binding)
Returns the data property of a data set for a chart is specified as a list of numbers.
Each point in the data list corresponds to the label at the same index on the x axis.int
getDataCount()
Returns the amount of data.Dataset
getDataset()
Gets the dataset instance.DataType
getDataType()
Returns the data type of data sets.protected String
getDefaultBackgroundColorAsString()
Returns the default background color value based on type of chart.protected String
getDefaultBorderColorAsString()
Returns the default border color value based on type of chart.protected int
getDefaultBorderWidth()
Returns the default border width value based on type of chart.protected String
getDefaultHoverBackgroundColorAsString()
Returns the default background color value based on type of chart.protected String
getDefaultHoverBorderColorAsString()
Returns the default border color value based on type of chart.protected int
getDefaultHoverBorderWidth()
Returns the default border width value based on type of chart.protected IsDefaultOptions
getDefaultValues()
Returns the default options instance.ColorCallback<DatasetContext>
getHoverBackgroundColorCallback()
Returns the hover background color callback, if set, otherwisenull
.ColorCallback<DatasetContext>
getHoverBorderColorCallback()
Returns the hover border color callback, if set, otherwisenull
.int
getId()
Returns the unique id of data sets.String
getLabel()
Returns the label for the data set which appears in the legend and tooltips.<T extends AbstractPluginOptions>
TgetOptions(String pluginId, AbstractPluginOptionsFactory<T> factory)
Returns the plugin data set configuration, if exist.
It uses a factory instance to create a plugin options.<T extends AbstractPluginOptions>
TgetOptions(AbstractPluginOptionsFactory<T> factory)
Returns the plugin options, if exist.
It uses a factory instance to create a plugin options.
If factory argument is not consistent,null
is returned.String
getScope()
Returns the scope of the data set, which is the options are used for defaults, chart defaults or chart.Type
getType()
Returns the type of data set, based on type of chart.protected IsDefaultTypedDataset
getTypedDataset()
Returns the typed data set for the type of the data set.boolean
hasOptions(String pluginId)
Checks if there is any data set configuration for a specific plugin, by its id.protected Object
invokeColorCallback(DatasetContext context, Scriptable<?,DatasetContext> callback, org.pepstock.charba.client.data.Dataset.CanvasObjectKey property, String defaultValue)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.boolean
isClip()
Returns if clips relative to the chart area.boolean
isHidden()
Returns if the data set at first drawing will appear or not.boolean
isNormalized()
Returns if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:true
option to let CHARBA know that you have done so.boolean
isParsing()
Returns how to parse the data set.
The parsing can be disabled by specifying parsing:false
at chart options or data set.
If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.void
removeOptions(String pluginId)
Removes the plugin options.void
setBackgroundColor(ColorCallback<DatasetContext> backgroundColorCallback)
Sets the background color callback.void
setBackgroundColor(NativeCallback backgroundColorCallback)
Sets the background color callback.void
setBorderColor(ColorCallback<DatasetContext> borderColorCallback)
Sets the border color callback.void
setBorderColor(NativeCallback borderColorCallback)
Sets the border color callback.void
setClip(boolean clip)
Sets how to clip relative to the chart area.
Iffalse
allows overflow, otherwisetrue
clips that many pixels inside the chart area.void
setClip(double clip)
Sets how to clip relative to the chart area.
Positive value allows overflow, negative value clips that many pixels inside the chart area.void
setClip(Clip clip)
Sets how to clip relative to the chart area, by an object which configures clipping per side.
Positive value allows overflow, negative value clips that many pixels inside the chart area.void
setData(double... values)
Sets the data property of a data set for a chart is specified as an array of numbers.
Each point in the data array corresponds to the label at the same index on the x axis.void
setData(List<Double> values)
Sets the data property of a data set for a chart is specified as a list of numbers.
Each point in the data list corresponds to the label at the same index on the x axis.protected void
setHidden(boolean hidden)
Sets if the data set will appear or not.void
setHoverBackgroundColor(ColorCallback<DatasetContext> hoverBackgroundColorCallback)
Sets the hover background color callback.void
setHoverBackgroundColor(NativeCallback hoverBackgroundColorCallback)
Sets the hover background color callback.void
setHoverBorderColor(ColorCallback<DatasetContext> hoverBorderColorCallback)
Sets the hover border color callback.void
setHoverBorderColor(NativeCallback hoverBorderColorCallback)
Sets the hover border color callback.void
setLabel(String label)
Sets the label for the data set which appears in the legend and tooltips.void
setNormalized(boolean normalized)
Sets if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:true
option to let CHARBA know that you have done so.<T extends AbstractPluginOptions>
voidsetOptions(String pluginId, T options)
Sets the plugin data set configuration.
If data set configuration options isnull
, the configuration of plugin will be removed.<T extends AbstractPluginOptions>
voidsetOptions(T options)
Sets the plugin options.void
setParsing(boolean parsing)
Sets how to parse the data set.
The parsing can be disabled by specifying parsing:false
at chart options or data set.
If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.-
Methods inherited from class org.pepstock.charba.client.commons.AbstractNode
checkAndAddToParent, getChildKey, getParentNode, getRootNode, getUpdateListener, retrieveRoot, setArrayValueAndAddToParent, setArrayValueAndAddToParent, setArrayValueAndAddToParent, setElementAndAddToParent, setInternalCallbackToModel, setInternalCallbackToModel, setUpdateListener, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent, setValueOrArrayAndAddToParent
-
Methods inherited from class org.pepstock.charba.client.commons.NativeObjectContainer
checkDefaultValuesArgument, empty, getArrayValue, getElement, getIncrementalId, getNativeChart, getNativeEvent, getNativeObject, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValueForMultipleKeyTypes, getValueForMultipleKeyTypes, getValueForMultipleKeyTypes, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, getValueOrArray, has, has, isType, keys, loadNativeObject, remove, remove, setArrayValue, setArrayValue, setArrayValue, setElement, setEmptyValue, setNewIncrementalId, setNewIncrementalId, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, toJSON, type
-
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.options.HasAnimationOptions
getAnimation, getAnimations, getTransitions, isAnimationEnabled, setAnimationEnabled
-
-
-
-
Field Detail
-
DEFAULT_HIDDEN
protected static final boolean DEFAULT_HIDDEN
- See Also:
- Constant Field Values
-
DEFAULT_PARSING
protected static final boolean DEFAULT_PARSING
- See Also:
- Constant Field Values
-
DEFAULT_NORMALIZED
protected static final boolean DEFAULT_NORMALIZED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Dataset
protected Dataset(Type type, IsDefaultOptions defaultValues, boolean hidden)
Creates the data set using a default and chart type related to the data set, adding patterns and gradients element.- Parameters:
type
- chart type related to the data setdefaultValues
- default optionshidden
- iftrue
, it will be initially hidden.
-
-
Method Detail
-
getAnimationContainer
public final AnimationContainer getAnimationContainer()
Description copied from interface:HasAnimationOptions
Returns an animation container instance to use in the default methods of this interface.- Specified by:
getAnimationContainer
in interfaceHasAnimationOptions
- Returns:
- an animation container instance
-
getDataCount
public final int getDataCount()
Returns the amount of data.- Returns:
- the amount of data
-
getId
public final int getId()
Returns the unique id of data sets.- Returns:
- the unique id of data sets
-
getScope
public final String getScope()
Returns the scope of the data set, which is the options are used for defaults, chart defaults or chart.- Specified by:
getScope
in interfaceHasCallbackScope
- Returns:
- the scope of the data set
-
getDataType
public final DataType getDataType()
Returns the data type of data sets.- Returns:
- the data type of data sets
-
getDefaultValues
protected final IsDefaultOptions getDefaultValues()
Returns the default options instance.- Returns:
- the default options instance.
-
getTypedDataset
protected final IsDefaultTypedDataset getTypedDataset()
Returns the typed data set for the type of the data set.- Returns:
- the typed data set for the type of the data set
-
getBackgroundColorCallback
public ColorCallback<DatasetContext> getBackgroundColorCallback()
Returns the background color callback, if set, otherwisenull
.- Returns:
- the background color callback, if set, otherwise
null
.
-
setBackgroundColor
public void setBackgroundColor(ColorCallback<DatasetContext> backgroundColorCallback)
Sets the background color callback.- Parameters:
backgroundColorCallback
- the background color callback.
-
setBackgroundColor
public void setBackgroundColor(NativeCallback backgroundColorCallback)
Sets the background color callback.- Parameters:
backgroundColorCallback
- the background color callback.
-
getBorderColorCallback
public ColorCallback<DatasetContext> getBorderColorCallback()
Returns the border color callback, if set, otherwisenull
.- Returns:
- the border color callback, if set, otherwise
null
.
-
setBorderColor
public void setBorderColor(ColorCallback<DatasetContext> borderColorCallback)
Sets the border color callback.- Parameters:
borderColorCallback
- the border color callback.
-
setBorderColor
public void setBorderColor(NativeCallback borderColorCallback)
Sets the border color callback.- Parameters:
borderColorCallback
- the border color callback.
-
createContext
protected final DatasetContext createContext(NativeObject context)
Creates a data set context for callback.- Parameters:
context
- native context, passed by CHART.JS- Returns:
- a data set context for callback
-
getHoverBackgroundColorCallback
public ColorCallback<DatasetContext> getHoverBackgroundColorCallback()
Returns the hover background color callback, if set, otherwisenull
.- Returns:
- the hover background color callback, if set, otherwise
null
.
-
setHoverBackgroundColor
public void setHoverBackgroundColor(ColorCallback<DatasetContext> hoverBackgroundColorCallback)
Sets the hover background color callback.- Parameters:
hoverBackgroundColorCallback
- the hover background color callback.
-
setHoverBackgroundColor
public void setHoverBackgroundColor(NativeCallback hoverBackgroundColorCallback)
Sets the hover background color callback.- Parameters:
hoverBackgroundColorCallback
- the hover background color callback.
-
getHoverBorderColorCallback
public ColorCallback<DatasetContext> getHoverBorderColorCallback()
Returns the hover border color callback, if set, otherwisenull
.- Returns:
- the hover border color callback, if set, otherwise
null
.
-
setHoverBorderColor
public void setHoverBorderColor(ColorCallback<DatasetContext> hoverBorderColorCallback)
Sets the hover border color callback.- Parameters:
hoverBorderColorCallback
- the hover border color callback.
-
setHoverBorderColor
public void setHoverBorderColor(NativeCallback hoverBorderColorCallback)
Sets the hover border color callback.- Parameters:
hoverBorderColorCallback
- the hover border color callback.
-
getDefaultBackgroundColorAsString
protected String getDefaultBackgroundColorAsString()
Returns the default background color value based on type of chart.- Returns:
- the default background color value based on type of chart.
-
getDefaultBorderColorAsString
protected String getDefaultBorderColorAsString()
Returns the default border color value based on type of chart.- Returns:
- the default border color value based on type of chart.
-
getDefaultBorderWidth
protected int getDefaultBorderWidth()
Returns the default border width value based on type of chart.- Returns:
- the default border width value based on type of chart.
-
getDefaultHoverBackgroundColorAsString
protected String getDefaultHoverBackgroundColorAsString()
Returns the default background color value based on type of chart.- Returns:
- the default background color value based on type of chart.
-
getDefaultHoverBorderColorAsString
protected String getDefaultHoverBorderColorAsString()
Returns the default border color value based on type of chart.- Returns:
- the default border color value based on type of chart.
-
getDefaultHoverBorderWidth
protected int getDefaultHoverBorderWidth()
Returns the default border width value based on type of chart.- Returns:
- the default border width value based on type of chart.
-
setHidden
protected final void setHidden(boolean hidden)
Sets if the data set will appear or not.- Parameters:
hidden
- if the data set will appear or not.
-
isHidden
public final boolean isHidden()
Returns if the data set at first drawing will appear or not.- Returns:
- if the data set at first drawing will appear or not.
-
setParsing
public void setParsing(boolean parsing)
Sets how to parse the data set.
The parsing can be disabled by specifying parsing:false
at chart options or data set.
If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.- Parameters:
parsing
- how to parse the data set.
The parsing can be disabled by specifying parsing:false
at chart options or data set.
If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
-
isParsing
public boolean isParsing()
Returns how to parse the data set.
The parsing can be disabled by specifying parsing:false
at chart options or data set.
If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.- Returns:
- how to parse the data set.
The parsing can be disabled by specifying parsing:false
at chart options or data set.
If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
-
setNormalized
public void setNormalized(boolean normalized)
Sets if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:true
option to let CHARBA know that you have done so.- Parameters:
normalized
- if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:true
option to let CHARBA know that you have done so.
-
isNormalized
public boolean isNormalized()
Returns if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:true
option to let CHARBA know that you have done so.- Returns:
- if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:
true
option to let CHARBA know that you have done so.
-
setLabel
public void setLabel(String label)
Sets the label for the data set which appears in the legend and tooltips.- Parameters:
label
- the label for the data set which appears in the legend and tooltips.
-
getLabel
public String getLabel()
Returns the label for the data set which appears in the legend and tooltips.- Returns:
- the label for the data set which appears in the legend and tooltips.
-
setClip
public void setClip(boolean clip)
Sets how to clip relative to the chart area.
Iffalse
allows overflow, otherwisetrue
clips that many pixels inside the chart area.- Parameters:
clip
- Iffalse
allows overflow, otherwisetrue
clips that many pixels inside the chart area.
-
setClip
public void setClip(double clip)
Sets how to clip relative to the chart area.
Positive value allows overflow, negative value clips that many pixels inside the chart area. 0 = clip at the chart area.- Parameters:
clip
- positive value allows overflow, negative value clips that many pixels inside the chart area. 0 = clip at the chart area
-
setClip
public void setClip(Clip clip)
Sets how to clip relative to the chart area, by an object which configures clipping per side.
Positive value allows overflow, negative value clips that many pixels inside the chart area. 0 = clip at the chart area.- Parameters:
clip
- object which configures clipping per side
-
isClip
public boolean isClip()
Returns if clips relative to the chart area.- Returns:
true
if clips relative to the chart area.
-
getClip
public double getClip()
Returns how to clip relative to the chart area.
Positive value allows overflow, negative value clips that many pixels inside the chart area. 0 = clip at the chart area.
If the clip was set by aClip
object or boolean, returnsUndefined.DOUBLE
.- Returns:
- positive value allows overflow, negative value clips that many pixels inside the chart area. 0 = clip at the chart area.
If the clip was set by aClip
object or boolean, returnsUndefined.DOUBLE
-
getClipAsObject
public Clip getClipAsObject()
-
setData
public void setData(double... values)
Sets the data property of a data set for a chart is specified as an array of numbers.
Each point in the data array corresponds to the label at the same index on the x axis.- Parameters:
values
- an array of numbers
-
setData
public void setData(List<Double> values)
Sets the data property of a data set for a chart is specified as a list of numbers.
Each point in the data list corresponds to the label at the same index on the x axis.- Parameters:
values
- list of numbers.
-
getData
public List<Double> getData()
Returns the data property of a data set for a chart is specified as a list of numbers.
Each point in the data list corresponds to the label at the same index on the x axis.- Returns:
- list of numbers or an empty list of numbers if the data type is not
DataType.NUMBERS
.
-
getData
public List<Double> getData(boolean binding)
Returns the data property of a data set for a chart is specified as a list of numbers.
Each point in the data list corresponds to the label at the same index on the x axis.- Parameters:
binding
- iftrue
binds the new array list in the container- Returns:
- list of numbers or an empty list of numbers if the data type is not
DataType.NUMBERS
.
-
getDataset
public Dataset getDataset()
Description copied from interface:HasDataset
Gets the dataset instance.- Specified by:
getDataset
in interfaceHasDataset
- Returns:
- the dataset instance
-
getType
public final Type getType()
Returns the type of data set, based on type of chart.- Returns:
- type of data set.
-
removeOptions
public void removeOptions(String pluginId)
Removes the plugin options.- Parameters:
pluginId
- plugin id.
-
setOptions
public <T extends AbstractPluginOptions> void setOptions(T options)
Sets the plugin options.- Type Parameters:
T
- type of plugin options to store- Parameters:
options
- plugin options used to configure the plugin
-
setOptions
public final <T extends AbstractPluginOptions> void setOptions(String pluginId, T options)
Sets the plugin data set configuration.
If data set configuration options isnull
, the configuration of plugin will be removed.- Type Parameters:
T
- type of plugin options to store- Parameters:
pluginId
- plugin id.options
- options used to configure the plugin.
Passnull
to remove the configuration if exist.
-
hasOptions
public final boolean hasOptions(String pluginId)
Checks if there is any data set configuration for a specific plugin, by its id.- Parameters:
pluginId
- plugin id.- Returns:
true
if there is an options, otherwisefalse
.
-
getOptions
public final <T extends AbstractPluginOptions> T getOptions(String pluginId, AbstractPluginOptionsFactory<T> factory)
Returns the plugin data set configuration, if exist.
It uses a factory instance to create a plugin options.- Type Parameters:
T
- type of plugin options to return- Parameters:
pluginId
- plugin id.factory
- factory instance to create a plugin options.- Returns:
- options instance used to configure the plugin or
null
if factory isnull
.
-
getOptions
public <T extends AbstractPluginOptions> T getOptions(AbstractPluginOptionsFactory<T> factory)
Returns the plugin options, if exist.
It uses a factory instance to create a plugin options.
If factory argument is not consistent,null
is returned.- Type Parameters:
T
- type of plugin options to return- Parameters:
factory
- factory instance to create a plugin options- Returns:
- plugin options used to configure the plugin or an empty object if not exist.
If factory argument is not consistent,null
is returned.
-
invokeColorCallback
protected final Object invokeColorCallback(DatasetContext context, Scriptable<?,DatasetContext> callback, org.pepstock.charba.client.data.Dataset.CanvasObjectKey property, String defaultValue)
Returns a color value of property by a callback, checking all different types of object which can be used as value of the property in color ones.- Parameters:
context
- scriptable contextcallback
- callback to invokeproperty
- property of data set used to store the colordefaultValue
- default value to return in case of chart, callback or result of callback are not consistent.- Returns:
- a value of property as color
-
-