xnano.components.chart
xnano.components.chart
¶
xnano.components.chart
Plot one or more line, scatter, or bar series.
Classes:
Attributes:
-
SeriesData(TypeAlias) –Points for one chart series:
(x, y)pairs or bareyvalues. -
ResolvedDataset(TypeAlias) –Resolved
(label, points, color, kind, marker)dataset tuple.
SeriesData
module-attribute
¶
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;
Nonederives 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:
-
resolve_label–Return the displayed legend label.
name
class-attribute
instance-attribute
¶
name: str = dataclasses.field(default='', init=False)
Attribute name assigned by the component class.
marker
class-attribute
instance-attribute
¶
Marker used to paint samples.
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:
-
series(dict[str, SeriesData]) –Mapping of series name → points.
-
kind(GraphTypeLike) –Default plot kind for series that do not override it.
-
colors(Sequence['ColorLike'] | None) –Palette cycled across series.
-
x_bounds(tuple[float, float] | None) –Explicit x-axis
(min, max). -
y_bounds(tuple[float, float] | None) –Explicit y-axis
(min, max). -
x_label(str | None) –Optional x-axis title.
-
y_label(str | None) –Optional y-axis title.
-
x_labels(Sequence[str] | None) –Optional x-axis tick labels.
-
y_labels(Sequence[str] | None) –Optional y-axis tick labels.
-
legend(bool) –Whether to show the legend.
-
legend_position(LegendPositionLike) –Legend placement when enabled.
-
marker(CanvasMarkerLike | None) –Default marker glyph set for series.
-
hidden_series(Sequence[str]) –Series names omitted from paint.
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-axis (min, max); None auto-fits to the data.
y_bounds
class-attribute
instance-attribute
¶
y-axis (min, max); None auto-fits to the data.
x_labels
class-attribute
instance-attribute
¶
Optional x-axis tick labels.
y_labels
class-attribute
instance-attribute
¶
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
¶
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.
compose
¶
Compose Plot content with a native ChartNode paint fallback.
Returns:
-
–
Interface-neutral content for this chart.
component_post_init
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
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