xnano.components.bar
xnano.components.bar
¶
xnano.components.bar
Render compact trends and distributions with configurable glyphs.
Classes:
-
Bar–Compact inline bar chart for a sequence of samples.
Functions:
-
resolve_bar_glyphs–Resolve a preset name or symbol sequence into ordered glyphs.
Attributes:
-
BarDirection(TypeAlias) –Whether bar samples grow upward or downward.
-
BarGlyphPreset(TypeAlias) –Named glyph ladders for compact bar rendering.
-
BarGlyphs(TypeAlias) –Explicit ordered symbols or a named preset.
BarDirection
module-attribute
¶
Whether bar samples grow upward or downward.
BarGlyphPreset
module-attribute
¶
Named glyph ladders for compact bar rendering.
BarGlyphs
module-attribute
¶
BarGlyphs: TypeAlias = str | Sequence[str] | BarGlyphPreset
Explicit ordered symbols or a named preset.
Bar
dataclass
¶
Bar(
data: Sequence[int | float] = tuple(),
foreground: "ColorLike | None" = None,
colors: Sequence["ColorLike"] | None = None,
background: "ColorLike | None" = None,
max_value: int | float | None = None,
direction: BarDirection = "up",
glyphs: BarGlyphs = "blocks",
absent_color: "ColorLike | None" = None,
absent_glyph: str | None = None,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = False
)
Bases: Component
Compact inline bar chart for a sequence of samples.
Fills its layout slot by default and scales sample heights across the
available vertical area when using the native sparkline path. Supply
colors with one entry per sample to tint individual bars.
Example
Bar(data=(2, 5, 3, 8), color="cyan")
Attributes:
-
data(Sequence[int | float]) –Sequence of sample values.
-
foreground('ColorLike | None') –Default bar foreground color (deprecated alias:
color). -
colors(Sequence['ColorLike'] | None) –Optional per-bar foreground colors.
-
background('ColorLike | None') –Widget background color.
-
max_value(int | float | None) –Explicit y-axis ceiling;
Noneauto-scales. -
direction(BarDirection) –Whether samples grow
"up"or"down". -
glyphs(BarGlyphs) –Ordered fill ladder or a named preset.
-
absent_color('ColorLike | None') –Color applied to zero or absent samples.
-
absent_glyph(str | None) –Glyph drawn for absent samples.
Methods:
-
component_post_init–Resolve and validate the glyph ladder once.
-
compose–Compose sparkline content, with a native/canvas paint path.
-
get_frame–Optional frame/panel chrome around composed content.
-
get_size–Return the preferred cell size of this component.
-
before_render–Called before rendering; returns the effective render area.
-
after_render–Called after rendering for optional post-paint work.
-
compose_extra_small–Compose content when the viewport is extra small (< 40 cols).
-
compose_small–Compose content when the viewport is small (40–79 cols).
-
compose_medium–Compose content when the viewport is medium (80–119 cols).
-
compose_large–Compose content when the viewport is large (120–159 cols).
-
compose_extra_large–Compose content when the viewport is extra large (>= 160 cols).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
data
class-attribute
instance-attribute
¶
Sequence of sample values.
foreground
class-attribute
instance-attribute
¶
Default bar foreground color (deprecated alias: color).
colors
class-attribute
instance-attribute
¶
colors: Sequence['ColorLike'] | None = None
Optional per-bar foreground colors, one per data entry.
background
class-attribute
instance-attribute
¶
Widget background color.
max_value
class-attribute
instance-attribute
¶
Explicit y-axis ceiling; None auto-scales to the dataset max.
direction
class-attribute
instance-attribute
¶
direction: BarDirection = 'up'
Whether samples grow "up" or "down".
glyphs
class-attribute
instance-attribute
¶
glyphs: BarGlyphs = 'blocks'
Ordered fill ladder or a named preset (blocks/braille/ascii).
absent_color
class-attribute
instance-attribute
¶
Color applied to zero or absent samples.
absent_glyph
class-attribute
instance-attribute
¶
absent_glyph: str | None = None
Glyph drawn for absent samples.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=False, kw_only=True
)
Whether layout should use the sparkline's natural width.
resolved_glyphs
property
¶
Resolved ordered glyph ladder used for rendering.
visible
class-attribute
instance-attribute
¶
visible: bool = dataclasses.field(
default=True, kw_only=True
)
Whether this component paints at all.
z
class-attribute
instance-attribute
¶
z: int = dataclasses.field(default=0, kw_only=True)
Stacking order among sibling content.
component_post_init
¶
Resolve and validate the glyph ladder once.
Source code in xnano/components/bar.py
compose
¶
Compose sparkline content, with a native/canvas paint path.
Returns:
-
–
Interface-neutral content for this bar.
Source code in xnano/components/bar.py
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
compose_extra_small
¶
compose_extra_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:compose. When
overridden, it is used instead of compose while the window
is in this size tier. Overriding any compose_* variant opts the
component into breakpoint dispatch; a component that overrides none
pays no per-frame cost.
Source code in xnano/components/component.py
compose_small
¶
compose_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is small (40–79 cols).
See :meth:compose_extra_small.
compose_medium
¶
compose_medium(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is medium (80–119 cols).
See :meth:compose_extra_small.
compose_large
¶
compose_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is large (120–159 cols).
See :meth:compose_extra_small.
compose_extra_large
¶
compose_extra_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is extra large (>= 160 cols).
See :meth:compose_extra_small.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
resolve_bar_glyphs
¶
Resolve a preset name or symbol sequence into ordered glyphs.
Parameters:
-
glyphs(BarGlyphs) –Named preset or ordered symbol sequence.
Returns:
Raises:
-
ValueError–When the glyph set is invalid.