Skip to content

Commit

Permalink
Make sure vega view is embedded in page before attempting to change i…
Browse files Browse the repository at this point in the history
…ts dataset (#472)

Asynchronous reloading of a chart's dataset relies on that chart already having been embedded. This fix makes sure the vegaView variable is set up before any of the data fetching promises's then blocks try to load the view with data.


* Make sure vega view is embedded in page before attempting to change its dataset

Signed-off-by: F.N. Claessen <felix@seita.nl>

* changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Aug 9, 2022
1 parent 7874bd7 commit 97484c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -18,6 +18,7 @@ New features
Bugfixes
-----------
* Do not fail asset page if entity addresses cannot be built [see `PR #457 <http://www.github.com/FlexMeasures/flexmeasures/pull/457>`_]
* Asynchronous reloading of a chart's dataset relies on that chart already having been embedded [see `PR #472 <http://www.github.com/FlexMeasures/flexmeasures/pull/472>`_]
* Time scale axes in sensor data charts now match the requested date range, rather than stopping at the edge of the available data [see `PR #449 <http://www.github.com/FlexMeasures/flexmeasures/pull/449>`_]
* The docker-based tutorial now works with UI on all platforms (port 5000 did not expose on MacOS) [see `PR #465 <http://www.github.com/FlexMeasures/flexmeasures/pull/465>`_]
* Fix interpretation of scheduling results in toy tutorial [see `PR #466 <http://www.github.com/FlexMeasures/flexmeasures/pull/466>`_]
Expand Down
5 changes: 3 additions & 2 deletions flexmeasures/ui/templates/crud/asset.html
Expand Up @@ -229,7 +229,6 @@ <h3>All sensors for {{ asset.name }}</h3>
signal = controller.signal

$("#spinner").show();
embedAndLoad(chartSpecsPath + 'event_starts_after=' + queryStartDate + '&event_ends_before=' + queryEndDate + '&', elementId, datasetName, previousResult, startDate, endDate);
Promise.all([
// Fetch time series data
fetch(assetPath + '/chart_data/?event_starts_after=' + queryStartDate + '&event_ends_before=' + queryEndDate, {
Expand All @@ -246,8 +245,10 @@ <h3>All sensors for {{ asset.name }}</h3>
headers: {"Content-Type": "application/json"},
signal: signal,
})
.then(function(response) { return response.json(); })
.then(function(response) { return response.json(); }),
*/

embedAndLoad(chartSpecsPath + 'event_starts_after=' + queryStartDate + '&event_ends_before=' + queryEndDate + '&', elementId, datasetName, previousResult, startDate, endDate),
]).then(function(result) {
$("#spinner").hide();
vegaView.change(datasetName, vega.changeset().remove(vega.truthy).insert(result[0])).resize().run();
Expand Down
6 changes: 4 additions & 2 deletions flexmeasures/ui/templates/views/sensors.html
Expand Up @@ -110,7 +110,6 @@
signal = controller.signal

$("#spinner").show();
embedAndLoad(chartSpecsPath + 'event_starts_after=' + queryStartDate + '&event_ends_before=' + queryEndDate + '&', elementId, datasetName, previousResult, startDate, endDate);
Promise.all([
// Fetch time series data
fetch(sensorPath + '/chart_data/?event_starts_after=' + queryStartDate + '&event_ends_before=' + queryEndDate, {
Expand All @@ -124,7 +123,10 @@
method: "GET",
headers: {"Content-Type": "application/json"},
})
.then(function(response) { return response.json(); })
.then(function(response) { return response.json(); }),

// Embed chart
embedAndLoad(chartSpecsPath + 'event_starts_after=' + queryStartDate + '&event_ends_before=' + queryEndDate + '&', elementId, datasetName, previousResult, startDate, endDate),
]).then(function(result) {
$("#spinner").hide();
vegaView.change(datasetName, vega.changeset().remove(vega.truthy).insert(result[0])).resize().run();
Expand Down

0 comments on commit 97484c0

Please sign in to comment.