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 identifier

  • classes (str or list of str, optional) – CSS class names for styling

  • data (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)

  • bind (bool | str)

Variables:
  • data (list) – Raw data

  • values (list of float) – Extracted numeric values

  • labels (list of str) – Extracted labels

  • width (int) – Display width

  • height (int) – Display height

  • bar_height (int) – Height per bar

  • scroll_manager (ScrollManager) – Manages scrolling

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 identifier

  • classes (str or list of str or set of str, optional) – CSS class names for styling

  • tab_index (int, optional) – Tab order for focus navigation

  • data (list[Any] | None)

  • width (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)

  • bind (bool | 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_intrinsic_size()

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_tab

Whether this element wants the Tab key instead of focus movement.

data

Get the raw data values.

parent_frame

Get the parent Frame if this element is inside a scrollable frame.

scroll_position

Get the current scroll position.

scroll_state_key

Get the state key for vertical scroll position.

scroll_state_key_x

Get the state key for horizontal scroll position.

supports_dynamic_sizing

Whether this element supports dynamic sizing.

property data: list[Any]

Get the raw data values.

Returns:

Raw data values

Return type:

list

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:

int

can_scroll(direction)[source]

Check if scrolling is possible in the given direction.

Parameters:

direction (int) – Negative for up, positive for down

Returns:

True if scrolling is possible

Return type:

bool

get_intrinsic_size()[source]

Get the intrinsic size of the chart.

Returns:

(width, height) in characters

Return type:

tuple of int

handle_key(key)[source]

Handle keyboard input for scrolling.

Parameters:

key (Key) – Key press to handle

Returns:

True if key was handled

Return type:

bool

async handle_mouse(event)[source]

Handle mouse events.

Parameters:

event (MouseEvent) – Mouse event to handle

Returns:

True if event was handled

Return type:

bool

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