Components API
The Chartlets component API is used by both application contributors and providers:
- Application contributors use the concrete component classes to create a contribution's user interface and to output updated components or parts of it from their callback implementations.
- Application providers use the abstract base classes
Component
andContainer
to implement new specific components.
Specific Components
chartlets.components.Box
dataclass
Bases: Container
The Box component is a generic container for grouping other components.
It's a fundamental building block. Think of it as an HTML <div>
element.
Use the style
attribute to layout the box and its child components.
component: str | None = None
class-attribute
instance-attribute
The component to be used, e.g., div
or span
.
chartlets.components.Button
dataclass
Bases: Component
Buttons allow users to take actions, and make choices, with a single tap.
text: str | None = None
class-attribute
instance-attribute
The button text.
chartlets.components.Checkbox
dataclass
Bases: Component
Checkboxes allow the user to select one or more items from a set. They can be used to turn an option on or off.
label: str = ''
class-attribute
instance-attribute
The checkbox label.
value: bool | None = None
class-attribute
instance-attribute
The checkbox value.
chartlets.components.Dropdown
dataclass
Bases: Component
Dropdown components are used for collecting user provided information from a list of options.
options: list[tuple[str, str | int | float]] = field(default_factory=list)
class-attribute
instance-attribute
The options given as a list of (label, value) pairs.
chartlets.components.Plot
dataclass
Bases: Component
The plot component is a container for a Vega Altair chart.
chart: alt.Chart | None = None
class-attribute
instance-attribute
The Vega Altair chart object.
chartlets.components.Typography
dataclass
Bases: Component
Use typography to present your design and content as clearly and efficiently as possible.
color: str | None = None
class-attribute
instance-attribute
The color of the component.
text: str | None = None
class-attribute
instance-attribute
Text to be displayed. Optional
variant: str | None = None
class-attribute
instance-attribute
Applies the theme typography styles.
Base classes
chartlets.Component
dataclass
Bases: ABC
Base class for components. Provides the common attributes that apply to all components.
children: list[Component] | None = None
class-attribute
instance-attribute
Children used by many specific components. Optional
id: str | None = None
class-attribute
instance-attribute
HTML id
property. Required for referring to this component.
label: str | None = None
class-attribute
instance-attribute
Label used by many specific components. Optional
name: str | None = None
class-attribute
instance-attribute
HTML name
property. Optional.
style: dict[str, Any] | None = None
class-attribute
instance-attribute
HTML style
property. Optional.
value: bool | int | float | str | None = None
class-attribute
instance-attribute
HTML value
property. Required for specific components.
chartlets.Container
dataclass
Bases: Component
, ABC
Base class for components that require child components to be useful.
children: list[Component] = field(default_factory=list)
class-attribute
instance-attribute
The child components.
add(component)
Add a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component |
Component
|
the child component. |
required |