Skip to content

Commit d821360

Browse files
Flix6xclaude
andcommitted
Say that a chart type's layout must hold every sensor its builder draws
Chart data is loaded for the layout's sensors only, so a graph a plugin's builder draws outside its layout comes up empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
1 parent 4977b25 commit d821360

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎documentation/plugin/customisation.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ A plugin can add its own chart type by registering it when the plugin is set up,
510510
511511
Prefix the name with your plugin's name, so it does not clash with chart types FlexMeasures may add later; a name that is already taken is refused.
512512

513+
The layout must hold every sensor the builder draws: the chart's data (``chart_data``) is loaded for the layout's sensors only, so a graph the builder draws outside the layout comes up empty.
514+
513515
A sensor's data can likewise be drawn as different chart types, which the sensor page offers in a picker, and which the sensor chart endpoint (``/api/ui/sensor/<id>/chart``) takes as ``chart-type``.
514516
The built-in ones are ``bar-chart``, ``histogram``, ``daily-heatmap`` and ``weekly-heatmap``.
515517
A plugin registers its own sensor chart type in the same way:

‎flexmeasures/data/models/charts/chart_types.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class AssetChartType(ChartType):
135135
:param applies_to: whether the chart type is meant for this asset.
136136
:param layout: the graphs the chart draws, given the asset's validated ``sensors_to_show``.
137137
:param builder: the function that builds the chart's Vega-Lite specs from the asset's validated ``sensors_to_show``.
138+
The layout must hold every sensor the builder draws: the chart's data (``chart_data``) is loaded for the layout's sensors only,
139+
so a graph the builder draws outside the layout comes up empty.
138140
:param legacy_name: the name of the builder, which the chart endpoint took before the chart types had public names.
139141
"""
140142

‎flexmeasures/data/tests/test_chart_types.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,10 @@ def test_registering_a_sensor_chart_type_refuses_a_name_already_taken(
211211
# Nothing was registered.
212212
assert SENSOR_CHART_TYPES == registry
213213
assert LEGACY_SENSOR_CHART_TYPE_NAMES == legacy_names
214+
215+
216+
def test_the_asset_chart_type_says_its_layout_must_hold_every_sensor_its_builder_draws():
217+
"""Chart data is loaded for the layout's sensors only, so a plugin's chart type should know to put every sensor its builder draws in its layout."""
218+
docstring = " ".join(AssetChartType.__doc__.split())
219+
assert "The layout must hold every sensor the builder draws" in docstring
220+
assert "a graph the builder draws outside the layout comes up empty" in docstring

0 commit comments

Comments
 (0)