Skip to content

ChartWidget

A leaf widget that renders a numeric series as a multi-row bar chart, filling whatever height and width it is assigned at render time.

This is what makes the dashboard’s throughput/latency panels genuinely tall (not the single glyph row Spark’s original design produced) and responsive to terminal resizes: render() reads $context->getRows()/ getColumns() fresh on every frame and re-resamples/re-draws to fit.

Implements VerticallyExpandableInterface directly on a leaf widget (symfony/tui only ships this on ContainerWidget/EditorWidget, but the interface itself has no such restriction) so a plain ContainerWidget ancestor’s isVerticallyExpanded() — “true if explicitly set, or if any * child needs to expand” — picks this widget up automatically and the “give the chart whatever space is left over” behavior propagates up through the widget tree with no manual expandVertically() calls needed on any wrapping container.

final class ChartWidget extends AbstractWidget implements VerticallyExpandableInterface

ExtendsAbstractWidget
ImplementsVerticallyExpandableInterface
SourceChartWidget.php

public function __construct(array<float> $values = []): mixed

ParameterTypeDescription
$valuesarray``<``float``>

Returns mixed

MethodDescription
expandVertically(bool $expand): staticSets whether the chart claims the leftover vertical space of its container, invalidating the widget so the next frame re-lays it out.
isVerticallyExpanded(): boolWhether the chart currently claims leftover vertical space; ancestor containers consult this to propagate expansion up the widget tree.
render(RenderContext $context): arrayDraws the current values as a bar chart filling the assigned area.
setValues(array<float> $values): static

public function expandVertically(bool $expand): static

Sets whether the chart claims the leftover vertical space of its container, invalidating the widget so the next frame re-lays it out.

Enabled by default.

ParameterTypeDescription
$expandbool

Returns static

public function isVerticallyExpanded(): bool

Whether the chart currently claims leftover vertical space; ancestor containers consult this to propagate expansion up the widget tree.

Returns bool

public function render(RenderContext $context): array

Draws the current values as a bar chart filling the assigned area.

Reads the row and column counts from $context on every frame — each floored at 1 — and resamples the series to that width before drawing, so a terminal resize is picked up without any explicit reconfiguration.

ParameterTypeDescription
$contextRenderContext

Returns array

public function setValues(array<float> $values): static

@return $this

ParameterTypeDescription
$valuesarray``<``float``>@return $this

Returns static

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
addStyleClass()AbstractWidget
beforeRender()AbstractWidgetLifecycle hook: override to sync state before rendering.
collectTerminalCleanupSequence()AbstractWidgetCollect and return an escape sequence the terminal must process when this widget is removed from the tree, and reset the associated state.
findById()AbstractWidgetFind a descendant widget by ID (depth-first search).
getContext()AbstractWidget
getId()AbstractWidget
getLabel()AbstractWidget
getParent()AbstractWidget
getRenderRevision()AbstractWidget
getStateFlags()AbstractWidget
getStyle()AbstractWidget
getStyleClasses()AbstractWidget
hasListeners()AbstractWidgetCheck if this widget has any local listeners for the given event type.
invalidate()AbstractWidget
on()AbstractWidgetRegister a listener for a specific event type on this widget.
removeStyleClass()AbstractWidget
setId()AbstractWidget
setLabel()AbstractWidgetSet an optional human-readable label for the widget.
setStyle()AbstractWidget
setStyleClasses()AbstractWidget