A querying chart offers its own windows: an optional ranges list of {label, range_s, interval_s}, up to 8 and checked by the server, where range_s 0 asks for the whole history; the editor lists and picks them, and the refresh is capped at what a timer can hold
This commit is contained in:
@@ -64,6 +64,10 @@ BAR_ROWS = 8
|
||||
#: client (``ui/core/counter.ts``, ``MAX_COUNTERS``).
|
||||
COUNTERS = 3
|
||||
|
||||
#: How many windows one querying chart offers, stacked down the tile's edge.
|
||||
#: Mirrored in the client (``ChartWidget.tsx``, ``MAX_RANGES``).
|
||||
CHART_RANGES = 8
|
||||
|
||||
#: Resolved out here on purpose: the store has a ``list`` method, which
|
||||
#: shadows the builtin for any annotation written inside the class.
|
||||
Bindings = list[dict[str, Any]]
|
||||
@@ -259,10 +263,15 @@ class WidgetDef(BaseModel):
|
||||
A chart comes in two kinds. The default reads what the engine kept for a
|
||||
message. One with ``source: "query"`` asks instead, and its config is
|
||||
``{source, request, request_dtype: "record", message, dtype: "series",
|
||||
refresh_s, range_s}``: it publishes ``{range_s, interval_s}`` to
|
||||
refresh_s, range_s, ranges}``: it publishes ``{range_s, interval_s}`` to
|
||||
``request`` exactly as a slider publishes a value, and draws the ``series``
|
||||
a flow answers with on ``message``.
|
||||
|
||||
``ranges`` lists the windows its rail offers, up to ``CHART_RANGES`` of
|
||||
``{label, range_s, interval_s}``, and ``range_s`` names the one it opens on.
|
||||
Without them it offers 1h, 6h, 24h and 7d. ``range_s: 0`` asks for the
|
||||
whole history, and the flow answering decides how far back that reaches.
|
||||
|
||||
A colour widget picks what it publishes with ``format``, because fixtures
|
||||
differ and a change node per tile is not the answer:
|
||||
|
||||
@@ -448,6 +457,28 @@ class WidgetDef(BaseModel):
|
||||
raise ValueError(
|
||||
f"a querying chart's {key} must be '{want}', not '{bound}'"
|
||||
)
|
||||
ranges = self.config.get("ranges") or []
|
||||
if not isinstance(ranges, list) or len(ranges) > CHART_RANGES:
|
||||
raise ValueError(
|
||||
f"a querying chart offers a list of at most {CHART_RANGES} ranges"
|
||||
)
|
||||
for entry in ranges:
|
||||
window = entry if isinstance(entry, dict) else {}
|
||||
label = window.get("label")
|
||||
span, step = window.get("range_s"), window.get("interval_s")
|
||||
# `type() is int`, because a bool is an int to isinstance.
|
||||
if not (
|
||||
isinstance(label, str)
|
||||
and label.strip()
|
||||
and type(span) is int
|
||||
and span >= 0
|
||||
and type(step) is int
|
||||
and step > 0
|
||||
):
|
||||
raise ValueError(
|
||||
"a querying chart's range needs a label, a whole range_s "
|
||||
f"of 0 or more and a whole interval_s above 0, not {entry!r}"
|
||||
)
|
||||
return self
|
||||
|
||||
if self.type == "bar" and len(self.bar_rows) > BAR_ROWS:
|
||||
|
||||
@@ -5,6 +5,7 @@ from datetime import UTC, datetime
|
||||
import pytest
|
||||
|
||||
from fluksio.flow.dashboards import (
|
||||
CHART_RANGES,
|
||||
DashboardDef,
|
||||
DashboardNotFound,
|
||||
DashboardStore,
|
||||
@@ -354,6 +355,26 @@ def test_a_querying_chart_asks_with_a_record_and_draws_a_series():
|
||||
WidgetDef(id="c", type="chart", config=query_chart(request_dtype="json"))
|
||||
|
||||
|
||||
def test_a_querying_chart_offers_its_own_ranges():
|
||||
"""A few labelled windows, where ``range_s: 0`` is the whole history."""
|
||||
daily = [
|
||||
{"label": "1M", "range_s": 30 * 86400, "interval_s": 86400},
|
||||
{"label": "All", "range_s": 0, "interval_s": 86400},
|
||||
]
|
||||
WidgetDef(id="c", type="chart", config=query_chart(ranges=daily))
|
||||
|
||||
for bad in (
|
||||
[{"label": "", "range_s": 3600, "interval_s": 60}],
|
||||
[{"label": "1h", "range_s": -1, "interval_s": 60}],
|
||||
[{"label": "1h", "range_s": 3600, "interval_s": 0}],
|
||||
[{"label": "1h", "range_s": 3600.5, "interval_s": 60}],
|
||||
daily * CHART_RANGES,
|
||||
"1M",
|
||||
):
|
||||
with pytest.raises(ValueError, match="range"):
|
||||
WidgetDef(id="c", type="chart", config=query_chart(ranges=bad))
|
||||
|
||||
|
||||
def test_a_colour_widget_publishes_the_shape_its_format_names():
|
||||
"""The format picks the payload, so the binding is held to that one."""
|
||||
wheel = WidgetDef(
|
||||
|
||||
Reference in New Issue
Block a user