Components
Components make up the visual parts of a chart and typically include axis, grid-lines and data points encoded in various ways.
Using components in a chart
Each component has a type property which identifies the type of component to create.
To use components, add them in the components array:
picasso.chart({ settings: { components: [{ type: 'point', data: { /* ... */ }, settings: { /* ... */ } }, { type: 'axis', layout: { dock: 'bottom' } scale: 'x' }] }});Some properties are general and can be used on all components:
showboolean. True if component should be rendered.layoutobject. Layout settingslayout.dockstring. Dock setting. Any oftop|right|bottom|leftlayout.displayOrdernumber. The order in which components are rendered (similar to CSS z-index).layout.prioOrdernumber. The order in which components are docked from the center area,layout.minimumLayoutModestring. The threshold for which components should appear,dataobject. See data section.settingsobject.createdfunction. Lifecycle hook.beforeMountfunction. Lifecycle hook.mountedfunction. Lifecycle hook.beforeRenderfunction. Lifecycle hook.beforeUpdatefunction. Lifecycle hook.updatedfunction. Lifecycle hook.beforeDestroyfunction. Lifecycle hook.destroyedfunction. Lifecycle hook.
settings
Most components use a settings object that is specific to the component itself.
Registering a custom component
A custom component can be registered using the picasso.component registry:
picasso.component(name, definition)
namestring. Name of the component to register.definitionobjectcreatedfunction (optional). Lifecycle hook.beforeMountfunction (optional). Lifecycle hook.mountedfunction (optional). Lifecycle hook.beforeRenderfunction (optional). Lifecycle hook.renderfunction (optional). Lifecycle hook.beforeUpdatefunction (optional). Lifecycle hook.updatedfunction (optional). Lifecycle hook.beforeDestroyfunction (optional). Lifecycle hook.destroyedfunction (optional). Lifecycle hook.
A draw line component
To make a component that draws a red line across its entire display area:
picasso.component('drawLine', { render() { return [ { type: 'line', stroke: 'red', strokeWidth: 4, x1: this.rect.x, y1: this.rect.y, x2: this.rect.width, y2: this.rect.height, }, ]; },});It can then be used like any other component:
picasso.chart({ element, settings: { components: [ { type: 'drawLine', }, ], },});Visibility of a component
It is possible to get the visibility of a component when it is mounted/unmounted. This can be done in the following example.
Assume a custom component of type foo:
const foo = { type: 'foo', key: 'myComponent',};
const chart = picasso.chart({ element, settings: { components: [foo], },});
chart.component('myComponent').isVisible(); // returns a boolean determining if the component is visible or notComponent lifecycle hooks
For more information, see the API reference.