public abstract class AbstractChart extends HandlerManager implements IsChart, HasAxes
Modifier | Constructor and Description |
---|---|
protected |
AbstractChart(Type type)
Initializes simple panel and canvas which are used by CHART.JS.
It sets also some default behaviors (width in percentage) for resizing |
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addHandler(EventHandler handler,
EventType type)
Adds a event handler.
|
protected void |
applyConfiguration()
Called before any drawing or reconfiguration in order that the chart which implements it can override options
|
void |
checkAxes(Axis... axes)
Checks if axes, requested to be stored, are an acceptable type or amount.
If a axis type or the amount of axes are not consistent for the chart, a IllegalArgumentException will be thrown. |
protected abstract boolean |
checkDataset(Dataset dataset)
Returns
true if the dataset can be managed by a this chart type. |
void |
checkDatasets(Dataset... datasets)
Checks if datasets, requested to be stored, are an acceptable type or amount.
If a dataset type or the amount of datasets are not consistent for the chart, a IllegalArgumentException will be thrown. |
void |
clear()
Will clear the chart canvas.
|
void |
createAndSetTimer(ChartTimerTask task,
int interval)
Creates a
CTimer instance inside chart.It can be created only once during the life cycle of the chart. |
void |
destroy()
Use this to destroy any chart instances that are created.
This will clean up any references stored to the chart object within Chart.js, along with any associated event listeners attached by Chart.js. |
void |
draw()
Draws the chart.
It can be invoked once during the life cycle of the chart. |
List<ActiveDatasetElement> |
getActiveElements()
Returns the active (hovered) elements for the chart.
|
Type |
getBaseType()
Returns the base type of chart that in case of
ChartType is the same of IsChart.getType() otherwise, in case the type of the chart is a
ControllerType is the chart type extension if there is or null . |
Canvas |
getCanvas()
Returns the canvas element used to draw the chart.
|
Div |
getChartElement()
Gets a handle to the object's underlying DOM element.
|
Data |
getData()
Returns the data object with all passed datasets.
|
List<DatasetReference> |
getDatasetAtEvent(BaseNativeEvent event)
Looks for the data sets that matches the event and returns the data set items references as a list.
|
DatasetItem |
getDatasetItem(int index)
Looks for the data set that matches the current index.
|
IsDefaultScaledOptions |
getDefaultChartOptions()
Returns the default options created based on chart type.
|
DatasetReference |
getElementAtEvent(BaseNativeEvent event)
Calling on your chart instance passing an argument of an event, will return the single element at the event position.
If there are multiple items within range, only the first is returned. |
List<DatasetReference> |
getElementsAtEvent(BaseNativeEvent event)
Looks for the element under the event point, then returns all elements at the same data index.
Calling it on your chart instance passing an argument of an event, will return the point elements that are at that the same position of that event. |
String |
getId()
Returns the ID of chart.
It could be considered as chart unique ID. |
CursorType |
getInitialCursor()
Returns the initial cursor of the chart.
|
protected int |
getMaximumAxesCount()
Returns the maximum amount of axes that the chart can manage.
|
protected int |
getMaximumDatasetsCount()
Returns the maximum amount of datasets that the chart can manage.
|
ChartNode |
getNode()
Returns the chart node with runtime data.
|
Plugins |
getPlugins()
Returns the plugins element to manage inline plugins.
|
protected IsChart |
getSource()
Returns a chart instance as source for all events.
|
CTimer |
getTimer()
Returns a
CTimer instance inside chart. |
List<ActiveDatasetElement> |
getTooltipActiveElements()
Returns the active tooltip elements for the chart.
|
Type |
getType()
Returns the type of chart.
|
int |
getVisibleDatasetCount()
Returns the amount of data sets which are visible
|
IsDefaultScaledOptions |
getWholeOptions()
Returns the default options by a chart instance, merging global, chart type global and chart options.
If the options is not consistent, it will returns the getDefaultChartOptions() . |
void |
hide(int datasetIndex)
Sets the visibility for the given data set to false.
Updates the chart and animates the data set with 'hide' mode. This animation can be configured under the hide key in animation options. |
void |
hide(int datasetIndex,
int dataIndex)
Sets the hidden flag of that element index to
true and updates the chart. |
boolean |
isChartAttached()
Returns
true whether this chart is currently attached to the browser's document. |
boolean |
isDatasetVisible(int index)
Looks for the data set if it's visible or not, selected by index.
|
boolean |
isDataVisible(int index)
Returns the stored visibility state of an data index for all data sets.
|
boolean |
isDestroyOnDetach()
Returns
true if the chart is configured to be destroyed on the detach from DIV element, otherwise false . |
boolean |
isDrawOnAttach()
Returns
true if the chart is configured to be drawn on the attach of DIV element, otherwise false . |
boolean |
isInitialized()
Returns
true if CHART.JS chart has been initialized, otherwise false . |
void |
onAttach(MutationItem item)
Invoked by mutation observer when a chart has been attached in the the DOM tree.
|
void |
onDetach(MutationItem item)
Invoked by mutation observer when a chart has been detached from the DOM tree.
|
void |
reconfigure()
Triggers an update of the chart.
This can be safely called after updating the data object. This will update the options, mutating the options property in place. |
void |
reconfigure(TransitionKey mode)
Triggers an update of the chart.
This can be safely called after updating the data object. This will update the options, mutating the options property in place. A animation mode key can be provided for the update process using a specific animation configuration. This is useful when update is manually called inside an event handler and some different animation is desired. |
void |
reconfigure(UpdateConfiguration configuration)
Triggers an update of the chart.
This can be safely called after updating the data object. This will update the options, mutating the options property in place. A configuration object can be provided with additional configuration for the update process. This is useful when update is manually called inside an event handler and some different animation is desired. |
void |
removeCanvasPreventDefault()
Remove the registration of prevent default mouse listener from canvas.
This is necessary when you will add your mouse down listener. |
void |
render()
Triggers a redraw of all chart elements.
Note, this does not update elements for new data. Use .update() in that case. |
void |
reset()
Reset the chart to it's state before the initial animation.
A new animation can then be triggered using update. |
void |
resetActiveElements()
Resets the active (hovered) elements for the chart.
|
void |
resetTooltipActiveElements()
Resets the active tooltip elements for the chart.
|
void |
resize()
Use this to manually resize the canvas element.
This is run each time the canvas container is resized, but can be called this method manually if you change the size of the canvas nodes container element. |
void |
resize(int width,
int height)
Use this to manually resize the canvas element.
This is run each time the canvas container is resized, but can be called this method manually if you change the size of the canvas nodes container element. |
void |
setActiveElements(ActiveDatasetElement... elements)
Sets the active (hovered) elements for the chart.
|
void |
setActiveElements(List<ActiveDatasetElement> elements)
Sets the active (hovered) elements for the chart.
|
void |
setDatasetVisibility(int datasetIndex,
boolean visibility)
Sets the visibility for a given data set.
This can be used to build a chart legend in HTML. During click on one of the HTML items, you can call it to change the appropriate data set. |
void |
setDestroyOnDetach(boolean destroyOnDetach)
Sets
true if the chart is configured to be destroyed on the detach from DIV element, otherwise false . |
void |
setDrawOnAttach(boolean drawOnAttach)
Sets
true if the chart is configured to be draw on the attach of DIV element, otherwise false . |
void |
setTooltipActiveElements(ActiveDatasetElement... elements)
Sets the active tooltip elements for the chart.
|
void |
setTooltipActiveElements(List<ActiveDatasetElement> elements)
Sets the active tooltip elements for the chart.
|
void |
show(int datasetIndex)
Sets the visibility for the given dataset to true.
Updates the chart and animates the dataset with 'show' mode. This animation can be configured under the show key in animation options. |
void |
show(int datasetIndex,
int dataIndex)
Sets the hidden flag of that element index to
false and updates the chart. |
void |
stop()
Use this to stop any current animation loop.
This will pause the chart during any current animation frame. Call .render() to re-animate. |
String |
toBase64Image(ImageMimeType type,
double encoderOptions)
Returns a base 64 encoded string of the chart in it's current state.
|
void |
toggleDataVisibility(int index)
Toggles the visibility of an item in all data sets.
A data set needs to explicitly support this feature for it to have an effect. From internal chart types, doughnut / pie and polar area use this. |
void |
update()
Triggers an update of the chart.
This can be safely called after updating the data object. This will update all scales, legends, and then re-render the chart. |
void |
update(TransitionKey mode)
Triggers an update of the chart.
This can be safely called after updating the data object. This will update all scales, legends, and then re-render the chart. A animation mode key can be provided for the update process using a specific animation configuration. This is useful when update is manually called inside an event handler and some different animation is desired. |
void |
update(UpdateConfiguration configuration)
Triggers an update of the chart.
This can be safely called after updating the data object. This will update all scales, legends, and then re-render the chart. A configuration object can be provided with additional configuration for the update process. This is useful when update is manually called inside an event handler and some different animation is desired. |
fireEvent, getHandlerCount, isEventHandled
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
checkAndGetIfConsistent, checkAndGetIfValid, checkIfConsistent, checkIfValid, fireEvent, getHandlerCount, getOptions, isAbstractChart, isConsistent, isEventHandled, isValid, toBase64Image, toBase64Image, toBase64Image
protected AbstractChart(Type type)
type
- the type of chartprotected final IsChart getSource()
HandlerManager
getSource
in class HandlerManager
public final HandlerRegistration addHandler(EventHandler handler, EventType type)
HandlerManager
addHandler
in interface IsChart
addHandler
in class HandlerManager
handler
- handler instance to addtype
- the event type associated with handlerpublic final Div getChartElement()
IsChart
getChartElement
in interface IsChart
public final Type getType()
IsChart
public final String getId()
public final Type getBaseType()
IsChart
ChartType
is the same of IsChart.getType()
otherwise, in case the type of the chart is a
ControllerType
is the chart type extension if there is or null
.getBaseType
in interface IsChart
public final Canvas getCanvas()
public final void removeCanvasPreventDefault()
removeCanvasPreventDefault
in interface IsChart
public final boolean isChartAttached()
true
whether this chart is currently attached to the browser's document.isChartAttached
in interface IsChart
true
whether this chart is currently attached to the browser's documentpublic final CursorType getInitialCursor()
getInitialCursor
in interface IsChart
public final boolean isInitialized()
true
if CHART.JS chart has been initialized, otherwise false
.isInitialized
in interface IsChart
true
if CHART.JS chart has been initialized, otherwise false
.public final ChartNode getNode()
public final Data getData()
public final Plugins getPlugins()
getPlugins
in interface IsChart
public final IsDefaultScaledOptions getDefaultChartOptions()
getDefaultChartOptions
in interface IsChart
public final IsDefaultScaledOptions getWholeOptions()
getDefaultChartOptions()
.getWholeOptions
in interface IsChart
public void createAndSetTimer(ChartTimerTask task, int interval)
CTimer
instance inside chart.createAndSetTimer
in interface IsChart
task
- the task to be executed repeatedlyinterval
- the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.public final boolean isDrawOnAttach()
true
if the chart is configured to be drawn on the attach of DIV element, otherwise false
.isDrawOnAttach
in interface IsChart
true
if the chart is configured to be drawn on the attach of DIV element, otherwise false
.public final void setDrawOnAttach(boolean drawOnAttach)
true
if the chart is configured to be draw on the attach of DIV element, otherwise false
.setDrawOnAttach
in interface IsChart
drawOnAttach
- the drawOnAttach to setpublic final boolean isDestroyOnDetach()
true
if the chart is configured to be destroyed on the detach from DIV element, otherwise false
.isDestroyOnDetach
in interface IsChart
true
if the chart is configured to be destroyed on the detach from DIV element, otherwise false
.public final void setDestroyOnDetach(boolean destroyOnDetach)
true
if the chart is configured to be destroyed on the detach from DIV element, otherwise false
.setDestroyOnDetach
in interface IsChart
destroyOnDetach
- the destroyOnDetach to setpublic final void onAttach(MutationItem item)
item
- can not be instantiated out of this package to avoid that anyone (apart the observer) will invoke the method.public final void onDetach(MutationItem item)
item
- can not be instantiated out of this package to avoid that anyone (apart the observer) will invoke the method.public final void setActiveElements(List<ActiveDatasetElement> elements)
setActiveElements
in interface IsChart
elements
- list of active elementspublic final void setActiveElements(ActiveDatasetElement... elements)
setActiveElements
in interface IsChart
elements
- array of active elementspublic final void resetActiveElements()
resetActiveElements
in interface IsChart
public final List<ActiveDatasetElement> getActiveElements()
getActiveElements
in interface IsChart
public final void setTooltipActiveElements(List<ActiveDatasetElement> elements)
setTooltipActiveElements
in interface IsChart
elements
- list of active tooltip elementspublic final void setTooltipActiveElements(ActiveDatasetElement... elements)
setTooltipActiveElements
in interface IsChart
elements
- array of active tooltip elementspublic final void resetTooltipActiveElements()
resetTooltipActiveElements
in interface IsChart
public final List<ActiveDatasetElement> getTooltipActiveElements()
getTooltipActiveElements
in interface IsChart
public final void destroy()
public final void stop()
.render()
to re-animate.public final void clear()
public final void reset()
public final String toBase64Image(ImageMimeType type, double encoderOptions)
toBase64Image
in interface IsChart
type
- indicating the image formatencoderOptions
- between 0 and 1 indicating the image quality to use for image formats that use lossy compression.Undefined.STRING
if chart is not initialized.public final void resize()
public final void resize(int width, int height)
public final void update()
public final void update(TransitionKey mode)
public final void update(UpdateConfiguration configuration)
public final void reconfigure()
reconfigure
in interface IsChart
public final void reconfigure(TransitionKey mode)
reconfigure
in interface IsChart
mode
- an animation mode can be provided to indicate what should be updated and what animation configuration should be usedpublic final void reconfigure(UpdateConfiguration configuration)
reconfigure
in interface IsChart
configuration
- a configuration object can be provided with additional configuration for the update processpublic final void render()
.update()
in that case.public final DatasetItem getDatasetItem(int index)
getDatasetItem
in interface IsChart
index
- data set indexnull
if the index is out of range of data sets count.public final List<DatasetReference> getDatasetAtEvent(BaseNativeEvent event)
getDatasetAtEvent
in interface IsChart
event
- event of chart.public final boolean isDatasetVisible(int index)
isDatasetVisible
in interface IsChart
index
- data set indextrue
if data set is visible otherwise false
.public final int getVisibleDatasetCount()
getVisibleDatasetCount
in interface IsChart
Undefined.INTEGER
.public final void setDatasetVisibility(int datasetIndex, boolean visibility)
setDatasetVisibility
in interface IsChart
datasetIndex
- data set indexvisibility
- if true
enables the visibility otherwise false
public final void toggleDataVisibility(int index)
toggleDataVisibility
in interface IsChart
index
- data indexpublic final boolean isDataVisible(int index)
isDataVisible
in interface IsChart
index
- data indextrue
if the data item is visiblepublic final void hide(int datasetIndex)
public final void hide(int datasetIndex, int dataIndex)
true
and updates the chart.public final void show(int datasetIndex)
public final void show(int datasetIndex, int dataIndex)
false
and updates the chart.public final DatasetReference getElementAtEvent(BaseNativeEvent event)
getElementAtEvent
in interface IsChart
event
- event of chart.null
if event is not consistentpublic final List<DatasetReference> getElementsAtEvent(BaseNativeEvent event)
getElementsAtEvent
in interface IsChart
event
- event of chart.public final void draw()
protected void applyConfiguration()
public final void checkDatasets(Dataset... datasets)
IsChart
IllegalArgumentException
will be thrown.checkDatasets
in interface IsChart
datasets
- list of datasets to check.protected abstract boolean checkDataset(Dataset dataset)
true
if the dataset can be managed by a this chart type.dataset
- dataset to checktrue
if the dataset can be managed by a this chart typeprotected int getMaximumDatasetsCount()
public void checkAxes(Axis... axes)
IsChart
IllegalArgumentException
will be thrown.protected int getMaximumAxesCount()