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 classDataset.CanvasObjectPropertyName of common properties of native object related to a dataset.protected static classDataset.CommonPropertyName of common properties of native object related to a dataset.
-
Field Summary
Fields Modifier and Type Field Description protected static booleanDEFAULT_HIDDENprotected static booleanDEFAULT_NORMALIZEDprotected static booleanDEFAULT_PARSING
-
Constructor Summary
Constructors Modifier Constructor Description protectedDataset(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 DatasetContextcreateContext(NativeObject context)Creates a data set context for callback.AnimationContainergetAnimationContainer()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.doublegetClip()Returns how to clip relative to the chart area.
Positive value allows overflow, negative value clips that many pixels inside the chart area.ClipgetClipAsObject()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.intgetDataCount()Returns the amount of data.DatasetgetDataset()Gets the dataset instance.DataTypegetDataType()Returns the data type of data sets.protected StringgetDefaultBackgroundColorAsString()Returns the default background color value based on type of chart.protected StringgetDefaultBorderColorAsString()Returns the default border color value based on type of chart.protected intgetDefaultBorderWidth()Returns the default border width value based on type of chart.protected StringgetDefaultHoverBackgroundColorAsString()Returns the default background color value based on type of chart.protected StringgetDefaultHoverBorderColorAsString()Returns the default border color value based on type of chart.protected intgetDefaultHoverBorderWidth()Returns the default border width value based on type of chart.protected IsDefaultOptionsgetDefaultValues()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.intgetId()Returns the unique id of data sets.StringgetLabel()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,nullis returned.StringgetScope()Returns the scope of the data set, which is the options are used for defaults, chart defaults or chart.TypegetType()Returns the type of data set, based on type of chart.protected IsDefaultTypedDatasetgetTypedDataset()Returns the typed data set for the type of the data set.booleanhasOptions(String pluginId)Checks if there is any data set configuration for a specific plugin, by its id.protected ObjectinvokeColorCallback(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.booleanisClip()Returns if clips relative to the chart area.booleanisHidden()Returns if the data set at first drawing will appear or not.booleanisNormalized()Returns if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:trueoption to let CHARBA know that you have done so.booleanisParsing()Returns how to parse the data set.
The parsing can be disabled by specifying parsing:falseat 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.voidremoveOptions(String pluginId)Removes the plugin options.voidsetBackgroundColor(ColorCallback<DatasetContext> backgroundColorCallback)Sets the background color callback.voidsetBackgroundColor(NativeCallback backgroundColorCallback)Sets the background color callback.voidsetBorderColor(ColorCallback<DatasetContext> borderColorCallback)Sets the border color callback.voidsetBorderColor(NativeCallback borderColorCallback)Sets the border color callback.voidsetClip(boolean clip)Sets how to clip relative to the chart area.
Iffalseallows overflow, otherwisetrueclips that many pixels inside the chart area.voidsetClip(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.voidsetClip(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.voidsetData(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.voidsetData(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 voidsetHidden(boolean hidden)Sets if the data set will appear or not.voidsetHoverBackgroundColor(ColorCallback<DatasetContext> hoverBackgroundColorCallback)Sets the hover background color callback.voidsetHoverBackgroundColor(NativeCallback hoverBackgroundColorCallback)Sets the hover background color callback.voidsetHoverBorderColor(ColorCallback<DatasetContext> hoverBorderColorCallback)Sets the hover border color callback.voidsetHoverBorderColor(NativeCallback hoverBorderColorCallback)Sets the hover border color callback.voidsetLabel(String label)Sets the label for the data set which appears in the legend and tooltips.voidsetNormalized(boolean normalized)Sets if you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized:trueoption 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.voidsetParsing(boolean parsing)Sets how to parse the data set.
The parsing can be disabled by specifying parsing:falseat 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
checkAndGetColor, 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:HasAnimationOptionsReturns an animation container instance to use in the default methods of this interface.- Specified by:
getAnimationContainerin 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:
getScopein 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:falseat 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:falseat 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:falseat 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:falseat 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:trueoption 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:trueoption 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:trueoption 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:
trueoption 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.
Iffalseallows overflow, otherwisetrueclips that many pixels inside the chart area.- Parameters:
clip- Iffalseallows overflow, otherwisetrueclips 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:
trueif 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 aClipobject 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 aClipobject 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- iftruebinds 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:HasDatasetGets the dataset instance.- Specified by:
getDatasetin 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.
Passnullto 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:
trueif 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
nullif 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,nullis 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,nullis 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
-
-