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:
|
||||
|
||||
Reference in New Issue
Block a user