From 27805debbaff8e6e83007a9c9579cb00846daa3e Mon Sep 17 00:00:00 2001 From: rldhont Date: Thu, 11 Jul 2024 14:15:02 +0200 Subject: [PATCH 1/2] Fix JS Dataviz: When dataviz is not available In embed mode the error is generated because the dataviz elements are not available. ``` TypeError: elem is null isInViewport dataviz.js:23 getPlots dataviz.js:146 uicreated dataviz.js:774 triggerEvent OpenLayers.js:246 init map.js:5034 map.js:5039:28 init map.js:5039 ``` --- lizmap/www/assets/js/dataviz/dataviz.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lizmap/www/assets/js/dataviz/dataviz.js b/lizmap/www/assets/js/dataviz/dataviz.js index 27de70e2f8..d9342dbf87 100644 --- a/lizmap/www/assets/js/dataviz/dataviz.js +++ b/lizmap/www/assets/js/dataviz/dataviz.js @@ -121,8 +121,6 @@ let lizDataviz = function () { // initialize plot info dv.plots[i] = { 'json': null, 'filter': null, 'show_plot': true, 'cache': null, 'data_fetched': false }; if (!(optionToBoolean(dv.config.layers[i]['only_show_child']))) { - let plotContainerId = `dataviz_plot_${i}`; - // Add plot container addPlotContainer(i); } @@ -143,6 +141,10 @@ let lizDataviz = function () { if (!(optionToBoolean(dv.config.layers[i]['only_show_child']))) { // Get the plot data and display it if the container is visible let elem = document.getElementById(plotContainerId); + // skip the element if it does not exist + if (elem === null) { + continue; + } if (isInViewport(elem) || getViewPercentage(elem) > 0) { getPlot(i, null, plotContainerId); } From 5dd897793d418d5d6af468bc5f19e7a54938ff0a Mon Sep 17 00:00:00 2001 From: rldhont Date: Thu, 11 Jul 2024 14:45:51 +0200 Subject: [PATCH 2/2] Tests e2e playwright Embed: Dataviz does not generate error --- tests/end2end/playwright/embed.spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/end2end/playwright/embed.spec.js diff --git a/tests/end2end/playwright/embed.spec.js b/tests/end2end/playwright/embed.spec.js new file mode 100644 index 0000000000..74a5f9776a --- /dev/null +++ b/tests/end2end/playwright/embed.spec.js @@ -0,0 +1,10 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); +const { gotoMap } = require('./globals') + +test.describe('Embed', () => { + test('Dataviz does not generate error', async ({ page }) => { + const url = '/index.php/view/embed/?repository=testsrepository&project=dataviz'; + await gotoMap(url, page); + }) +})