wijjit.elements.display.barchart.BarChart
- class wijjit.elements.display.barchart.BarChart(id=None, classes=None, data=None, width=40, height=10, bar_height=1, show_labels=True, show_values=True, label_width=None, value_width=6, color_mode='default', color_scale='green', show_scrollbar=True, border_style='single', tab_index=None, bind=True)[source]
BarChart element for horizontal bar visualization.
This element displays data as horizontal bars with support for: - Labels on the left side - Values on the right side - Single color, gradient, or threshold-based coloring - Scrolling for large datasets - Mouse and keyboard interaction
- Parameters:
id (
str, optional) – Element identifierclasses (
strorlistofstr, optional) – CSS class names for stylingdata (
list, optional) – Data as numbers, tuples (label, value), or dicts (default: [])width (
int, optional) – Display width in columns (default: 40)height (
int, optional) – Display height in rows (default: 10)bar_height (
int, optional) – Height of each bar in rows (default: 1)show_labels (
bool, optional) – Show labels on left side (default: True)show_values (
bool, optional) – Show values on right side (default: True)label_width (
int, optional) – Width reserved for labels (default: auto)value_width (
int, optional) – Width reserved for values (default: 6)color_mode (
str, optional) – Color mode: “default”, “gradient”, “threshold” (default: “default”)color_scale (
str, optional) – Color scale for gradient mode (default: “green”)show_scrollbar (
bool, optional) – Show scrollbar when content overflows (default: True)border_style (
str, optional) – Border style: “single”, “double”, “rounded”, or “none” (default: “single”)tab_index (int | None)
- Variables:
Examples
Simple bar chart:
>>> barchart = BarChart(data=[10, 20, 30, 40])
With labels:
>>> barchart = BarChart(data=[ ... {"label": "Sales", "value": 100}, ... {"label": "Revenue", "value": 150}, ... ])
Gradient coloring:
>>> barchart = BarChart(data=[10, 50, 90], color_mode="gradient")
- __init__(id=None, classes=None, data=None, width=40, height=10, bar_height=1, show_labels=True, show_values=True, label_width=None, value_width=6, color_mode='default', color_scale='green', show_scrollbar=True, border_style='single', tab_index=None, bind=True)[source]
Initialize scrollable element.
- Parameters:
id (
str, optional) – Element identifierclasses (
strorlistofstrorsetofstr, optional) – CSS class names for stylingtab_index (
int, optional) – Tab order for focus navigationwidth (int)
height (int)
bar_height (int)
show_labels (bool)
show_values (bool)
label_width (int | None)
value_width (int)
color_mode (Literal['default', 'gradient', 'threshold'])
color_scale (str)
show_scrollbar (bool)
border_style (str)
- Return type:
None
Methods
__init__([id, classes, data, width, height, ...])Initialize scrollable element.
add_class(class_name)Add a CSS class to this element.
apply_props(props)Apply props from a VNode, skipping ephemeral props.
can_scroll(direction)Check if scrolling is possible in the given direction.
get_ephemeral_state()Get ephemeral state that should survive reconciliation.
get_hardware_cursor_position()Absolute screen cell where the hardware terminal cursor should park.
get_height_for_width(width)Return the height this element needs when laid out at
width.Get the intrinsic size of the chart.
handle_key(key)Handle keyboard input for scrolling.
handle_mouse(event)Handle mouse events.
has_class(class_name)Check if element has a CSS class.
on_blur()Called when element loses focus.
on_focus()Called when element gains focus.
on_hover_enter()Called when mouse enters element.
on_hover_exit()Called when mouse exits element.
on_mount()Called when element is first added to the element tree.
on_unmount()Called when element is removed from the element tree.
on_update(changed_props)Called when element props are updated during reconciliation.
remove_class(class_name)Remove a CSS class from this element.
render_signature()Hashable/comparable capture of everything
render_to()reads.render_to(ctx)Render the bar chart using cell-based rendering.
restore_ephemeral_state(state)Restore ephemeral state after reconciliation.
set_bounds(bounds)Set the element's screen bounds.
set_data(data)Update chart data.
toggle_class(class_name)Toggle a CSS class on this element.
Attributes
captures_tabWhether this element wants the Tab key instead of focus movement.
Get the raw data values.
parent_frameGet the parent Frame if this element is inside a scrollable frame.
Get the current scroll position.
scroll_state_keyGet the state key for vertical scroll position.
scroll_state_key_xGet the state key for horizontal scroll position.
supports_dynamic_sizingWhether this element supports dynamic sizing.
- set_data(data)[source]
Update chart data.
- Parameters:
data (
list) – New data values- Return type:
None
- property scroll_position: int
Get the current scroll position.
- Returns:
Current scroll offset
- Return type:
- handle_key(key)[source]
Handle keyboard input for scrolling.
- Parameters:
key (
Key) – Key press to handle- Returns:
True if key was handled
- Return type:
- async handle_mouse(event)[source]
Handle mouse events.
- Parameters:
event (
MouseEvent) – Mouse event to handle- Returns:
True if event was handled
- Return type:
- render_to(ctx)[source]
Render the bar chart using cell-based rendering.
- Parameters:
ctx (
PaintContext) – Paint context with buffer, style resolver, and bounds- Return type:
None
Notes
Theme styles:
This element uses the following theme style classes: -
barchart: Base bar chart style -barchart:focus: When chart has focus -barchart.label: Label text style -barchart.value: Value text style -barchart.bar: Bar fill style -barchart.bar.empty: Empty bar portion style -barchart.border: Border style