Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multi sourced belief charts (#228)
Multi-sourced beliefs now overlap rather than stack, and chart defaults are refactored to entire field definitions. * Use full string representation for DataSource in JSON * Update default chart to handle showing beliefs from multiple sources * Refactor default field definition titles * Move to setting defaults for entire field definitions, and add test
- Loading branch information
Showing
4 changed files
with
45 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
from flexmeasures.data.models.charts.defaults import TIME_TITLE, TIME_TOOLTIP_TITLE | ||
from flexmeasures.data.models.charts.defaults import FIELD_DEFINITIONS | ||
|
||
|
||
def bar_chart(title: str, quantity: str = "unknown quantity", unit: str = "a.u."): | ||
if not unit: | ||
unit = "a.u." | ||
event_value_field_definition = dict( | ||
title=f"{quantity} ({unit})", | ||
format=".3s", | ||
stack=None, | ||
**FIELD_DEFINITIONS["event_value"], | ||
) | ||
return { | ||
"description": "A simple bar chart.", | ||
"title": title, | ||
"mark": "bar", | ||
"encoding": { | ||
"x": {"field": "event_start", "type": "T", "title": TIME_TITLE}, | ||
"y": { | ||
"field": "event_value", | ||
"type": "quantitative", | ||
"title": quantity + " (" + unit + ")", | ||
}, | ||
"x": FIELD_DEFINITIONS["event_start"], | ||
"y": event_value_field_definition, | ||
"color": FIELD_DEFINITIONS["source"], | ||
"opacity": {"value": 0.7}, | ||
"tooltip": [ | ||
{"field": "full_date", "title": TIME_TOOLTIP_TITLE, "type": "nominal"}, | ||
{ | ||
"field": "event_value", | ||
"title": quantity + " (" + unit + ")", | ||
"type": "quantitative", | ||
}, | ||
FIELD_DEFINITIONS["full_date"], | ||
event_value_field_definition, | ||
FIELD_DEFINITIONS["source"], | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import altair as alt | ||
|
||
from flexmeasures.data.models.charts.defaults import FIELD_DEFINITIONS | ||
|
||
|
||
def test_default_encodings(): | ||
"""Check default encodings for valid vega-lite specifications.""" | ||
for field_name, field_definition in FIELD_DEFINITIONS.items(): | ||
assert alt.StringFieldDefWithCondition(**field_definition) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters