Skip to content

xnano.components.chart

xnano.components.chart

xnano.components.chart


Plot one or more line, scatter, or bar series.

Classes:

  • Series

    Describe one chart series.

  • Chart

    Declarative multi-series chart.

Attributes:

SeriesData module-attribute

SeriesData: TypeAlias = Sequence[Any]

Points for one chart series: (x, y) pairs or bare y values.

ResolvedDataset module-attribute

ResolvedDataset: TypeAlias = tuple[
    str,
    tuple[tuple[float, float], ...],
    Any,
    GraphTypeLike,
    "CanvasMarkerLike | None",
]

Resolved (label, points, color, kind, marker) dataset tuple.

Series dataclass

Series(
    label: str | None = None,
    color: "ColorLike | None" = None,
    kind: "GraphTypeLike | None" = None,
    marker: "CanvasMarkerLike | None" = None,
)

Bases: ComponentDescriptor

Describe one chart series.

Attributes:

  • label (str | None) –

    Legend label; None derives it from the attribute name.

  • color ('ColorLike | None') –

    Series color.

  • kind ('GraphTypeLike | None') –

    Plot representation.

  • marker ('CanvasMarkerLike | None') –

    Glyph set used to paint the series.

Methods:

name class-attribute instance-attribute

name: str = dataclasses.field(default='', init=False)

Attribute name assigned by the component class.

label class-attribute instance-attribute

label: str | None = None

Legend label.

color class-attribute instance-attribute

color: 'ColorLike | None' = None

Series color.

kind class-attribute instance-attribute

kind: 'GraphTypeLike | None' = None

Graph representation.

marker class-attribute instance-attribute

marker: 'CanvasMarkerLike | None' = None

Marker used to paint samples.

resolve_label

resolve_label() -> str

Return the displayed legend label.

Source code in xnano/components/schema.py
def resolve_label(self) -> str:
    """Return the displayed legend label."""
    return self.label if self.label is not None else self.name

Chart dataclass

Chart(
    series: dict[str, SeriesData] = dict(),
    kind: GraphTypeLike = "line",
    colors: Sequence["ColorLike"] | None = None,
    x_bounds: tuple[float, float] | None = None,
    y_bounds: tuple[float, float] | None = None,
    x_label: str | None = None,
    y_label: str | None = None,
    x_labels: Sequence[str] | None = None,
    y_labels: Sequence[str] | None = None,
    legend: bool = True,
    legend_position: LegendPositionLike = "top_right",
    marker: CanvasMarkerLike | None = None,
    hidden_series: Sequence[str] = (),
    *,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = False
)

Bases: Component

Declarative multi-series chart.

Hand it a mapping of series name → points and it derives the datasets, legend, axis bounds, and a cycled color per series. Points may be (x, y) pairs or bare y values (the x-axis becomes the index).

Example

Chart(series={"requests": (3, 5, 4, 8)})

Attributes:

Methods:

  • compose

    Compose Plot content with a native ChartNode paint fallback.

  • component_post_init

    Initialize subclass state after dataclass fields are assigned.

  • 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.

series class-attribute instance-attribute

series: dict[str, SeriesData] = dataclasses.field(
    default_factory=dict
)

Mapping of series name → points.

kind class-attribute instance-attribute

kind: GraphTypeLike = 'line'

Default plot kind for series that do not override it.

colors class-attribute instance-attribute

colors: Sequence['ColorLike'] | None = None

Palette cycled across series; None uses a built-in palette.

x_bounds class-attribute instance-attribute

x_bounds: tuple[float, float] | None = None

x-axis (min, max); None auto-fits to the data.

y_bounds class-attribute instance-attribute

y_bounds: tuple[float, float] | None = None

y-axis (min, max); None auto-fits to the data.

x_label class-attribute instance-attribute

x_label: str | None = None

Optional x-axis title.

y_label class-attribute instance-attribute

y_label: str | None = None

Optional y-axis title.

x_labels class-attribute instance-attribute

x_labels: Sequence[str] | None = None

Optional x-axis tick labels.

y_labels class-attribute instance-attribute

y_labels: Sequence[str] | None = None

Optional y-axis tick labels.

legend class-attribute instance-attribute

legend: bool = True

Whether to show the legend (labelled from series names).

legend_position class-attribute instance-attribute

legend_position: LegendPositionLike = 'top_right'

Legend placement when legend is enabled.

marker class-attribute instance-attribute

marker: CanvasMarkerLike | None = None

Default marker glyph set for series that do not override it.

hidden_series class-attribute instance-attribute

hidden_series: Sequence[str] = ()

Series names omitted from paint and bounds.

fit_content class-attribute instance-attribute

fit_content: bool = dataclasses.field(
    default=False, kw_only=True
)

Whether layout should use the plot's natural size.

datasets property

datasets: tuple[ResolvedDataset, ...]

Read-only resolved view of plotted datasets.

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.

focused property

focused: bool

Whether this component currently holds field focus.

compose

compose(ctx: 'ComponentRenderContext')

Compose Plot content with a native ChartNode paint fallback.

Returns:

  • Interface-neutral content for this chart.

Source code in xnano/components/chart.py
def compose(self, ctx: "ComponentRenderContext"):
    """Compose Plot content with a native ChartNode paint fallback.

    Returns:
        Interface-neutral content for this chart.
    """
    return self._compose_plot()

component_post_init

component_post_init() -> None

Initialize subclass state after dataclass fields are assigned.

Override this method instead of __post_init__.

Source code in xnano/components/component.py
def component_post_init(self) -> None:
    """Initialize subclass state after dataclass fields are assigned.

    Override this method instead of ``__post_init__``.
    """
    return None

get_frame

get_frame() -> Any | None

Optional frame/panel chrome around composed content.

Source code in xnano/components/component.py
def get_frame(self) -> Any | None:
    """Optional frame/panel chrome around composed content."""
    return None

get_size

get_size(ctx: ComponentRenderContext[StateT]) -> Size

Return the preferred cell size of this component.

Source code in xnano/components/component.py
def get_size(self, ctx: ComponentRenderContext[StateT]) -> Size:
    """Return the preferred cell size of this component."""
    return Size(width=0, height=0)

before_render

before_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"

Called before rendering; returns the effective render area.

Source code in xnano/components/component.py
def before_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> "Area":
    """Called before rendering; returns the effective render area."""
    return area

after_render

after_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> None

Called after rendering for optional post-paint work.

Source code in xnano/components/component.py
def after_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> None:
    """Called after rendering for optional post-paint work."""
    return 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
@responsive_noop
def compose_extra_small(
    self, 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.
    """
    return None

compose_small

compose_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is small (40–79 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is small (40–79 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_medium

compose_medium(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is medium (80–119 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_medium(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is medium (80–119 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_large

compose_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is large (120–159 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is large (120–159 cols).

    See :meth:`compose_extra_small`.
    """
    return None

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
@responsive_noop
def compose_extra_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra large (>= 160 cols).

    See :meth:`compose_extra_small`.
    """
    return None

handle_keyboard

handle_keyboard(keyboard: 'KeyboardEventData') -> bool

Optional keyboard handler while focused.

Returns:

  • bool

    True when the event was consumed.

Source code in xnano/components/component.py
def handle_keyboard(self, keyboard: "KeyboardEventData") -> bool:
    """Optional keyboard handler while focused.

    Returns:
        ``True`` when the event was consumed.
    """
    return False

handle_paste

handle_paste(text: str) -> bool

Optional paste handler while focused.

Returns:

  • bool

    True when the paste was consumed.

Source code in xnano/components/component.py
def handle_paste(self, text: str) -> bool:
    """Optional paste handler while focused.

    Returns:
        ``True`` when the paste was consumed.
    """
    return False