Class ChartContext
- java.lang.Object
-
- org.pepstock.charba.client.commons.NativeObjectContainer
-
- org.pepstock.charba.client.callbacks.ChartContext
-
- Direct Known Subclasses:
AbstractDatasetContext
,AnnotationContext
,MeterContext
,ScaleContext
,SegmentContext
,TooltipContext
,ZoomContext
public class ChartContext extends NativeObjectContainer
Abstract implementation to map the context used as argument on options, data sets, scales and plugins callbacks.
All context implementations have got a property which is a reference to the chart instance.- Author:
- Andrea "Stock" Stocchero
-
-
Constructor Summary
Constructors Constructor Description ChartContext(NativeObject nativeObject)
Creates the object with native object instance to be wrapped.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
checkIfPropertyIsValid(Key property)
Checks if the key passed as argument is a key already used for other context properties.boolean
getAttribute(Key key, boolean defaultValue)
Returns a custom field value from data point.double
getAttribute(Key key, double defaultValue)
Returns a custom field value from data point.int
getAttribute(Key key, int defaultValue)
Returns a custom field value from data point.String
getAttribute(Key key, String defaultValue)
Returns a custom field value from data point.<T extends NativeObjectContainer>
TgetAttributes(NativeObjectContainerFactory<T> factory)
Returns the attributes, if exist.IsChart
getChart()
Returns the CHARBA chart instance.ContextType
getType()
Returns the type of the context.boolean
hasAttributes()
Checks if there is any attribute node.protected boolean
isConsistent()
Returnstrue
if the context is consistent.
Custom context (the plugin ones) should extend it and check if the context is consistent before invoking the callback.void
setAttribute(Key key, boolean value)
Sets a custom field to data point.void
setAttribute(Key key, double value)
Sets a custom field to data point.void
setAttribute(Key key, int value)
Sets a custom field to data point.void
setAttribute(Key key, String value)
Sets a custom field to data point.<T extends NativeObjectContainer>
voidsetAttributes(T attributes)
Sets the additional attributes.-
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, setValue, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, setValueOrArray, toJSON, type
-
-
-
-
Constructor Detail
-
ChartContext
public ChartContext(NativeObject nativeObject)
Creates the object with native object instance to be wrapped.- Parameters:
nativeObject
- native object instance to be wrapped.
-
-
Method Detail
-
getChart
public final IsChart getChart()
Returns the CHARBA chart instance.- Returns:
- the CHARBA chart instance
-
getType
public final ContextType getType()
Returns the type of the context.- Returns:
- the type of the context
-
setAttributes
public final <T extends NativeObjectContainer> void setAttributes(T attributes)
Sets the additional attributes.- Type Parameters:
T
- type of native object container to store- Parameters:
attributes
- additional attributes instance.
-
hasAttributes
public final boolean hasAttributes()
Checks if there is any attribute node.- Returns:
true
if there is an attributes node, otherwisefalse
.
-
getAttributes
public final <T extends NativeObjectContainer> T getAttributes(NativeObjectContainerFactory<T> factory)
Returns the attributes, if exist. It uses a factory instance to create a native object container.- Type Parameters:
T
- type of native object container to return- Parameters:
factory
- factory instance to create a native object container.- Returns:
- java script object used to map the attributes or an empty object if not exist.
-
setAttribute
public final void setAttribute(Key key, double value)
Sets a custom field to data point.- Parameters:
key
- key of java script object to set.value
- value to set.
-
getAttribute
public final double getAttribute(Key key, double defaultValue)
Returns a custom field value from data point.- Parameters:
key
- key of java script object to get.defaultValue
- default value if the property is missing- Returns:
- custom field value from data point.
-
setAttribute
public final void setAttribute(Key key, boolean value)
Sets a custom field to data point.- Parameters:
key
- key of java script object to set.value
- value to set.
-
getAttribute
public final boolean getAttribute(Key key, boolean defaultValue)
Returns a custom field value from data point.- Parameters:
key
- key of java script object to get.defaultValue
- default value if the property is missing- Returns:
- custom field value from data point.
-
setAttribute
public final void setAttribute(Key key, int value)
Sets a custom field to data point.- Parameters:
key
- key of java script object to set.value
- value to set.
-
getAttribute
public final int getAttribute(Key key, int defaultValue)
Returns a custom field value from data point.- Parameters:
key
- key of java script object to get.defaultValue
- default value if the property is missing- Returns:
- custom field value from data point.
-
setAttribute
public final void setAttribute(Key key, String value)
Sets a custom field to data point.- Parameters:
key
- key of java script object to set.value
- value to set.
-
getAttribute
public final String getAttribute(Key key, String defaultValue)
Returns a custom field value from data point.- Parameters:
key
- key of java script object to get.defaultValue
- default value if the property is missing- Returns:
- custom field value from data point.
-
isConsistent
protected boolean isConsistent()
Returnstrue
if the context is consistent.
Custom context (the plugin ones) should extend it and check if the context is consistent before invoking the callback.- Returns:
true
if the context is consistent
-
checkIfPropertyIsValid
protected boolean checkIfPropertyIsValid(Key property)
Checks if the key passed as argument is a key already used for other context properties.- Parameters:
property
- property to use to store a custom attribute- Returns:
true
if the property can be used to store an attribute.
-
-