Skip to content

Commit

Permalink
Dataviz - Respect the new option trigger_filter to avoid filtering th…
Browse files Browse the repository at this point in the history
…e plot on layer filter
  • Loading branch information
mdouchin committed Nov 3, 2023
1 parent 6475c8c commit 78c42f0
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 24 deletions.
22 changes: 21 additions & 1 deletion assets/src/modules/config/Dataviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ const requiredProperties = {
'title': {type: 'string'},
'popup_display_child_plot': {type: 'boolean'},
'only_show_child': {type: 'boolean'},
'trigger_filter': {type: 'boolean'},
};

const optionalProperties = {
'abstract': {type: 'string', default: ''},
'title_popup': {type: 'string', default: ''},
};

/**
Expand Down Expand Up @@ -283,7 +285,16 @@ export class DatavizElementConfig extends BaseObjectConfig {
}

/**
* The title
* The title in popup
*
* @type {String}
**/
get titlePopup() {
return this._title_popup;
}

/**
* The abstract
*
* @type {String}
**/
Expand Down Expand Up @@ -317,6 +328,15 @@ export class DatavizElementConfig extends BaseObjectConfig {
get onlyShowChild() {
return this._only_show_child;
}

/**
* The trigger filter
*
* @type {Boolean}
**/
get triggerFilter() {
return this._trigger_filter;
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions lizmap/modules/lizmap/lib/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,11 @@ public function parseDatavizPlotConfig($config)
if (property_exists($config, 'only_show_child')) {
$plotConfig['only_show_child'] = $config->only_show_child;
}
// Since LWC 3.7
$plotConfig['trigger_filter'] = true;
if (property_exists($config, 'trigger_filter')) {
$plotConfig['trigger_filter'] = $config->trigger_filter;
}

$abstract = $layer->abstract;
if (property_exists($config, 'description')) {
Expand Down
6 changes: 6 additions & 0 deletions lizmap/www/assets/js/dataviz/dataviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ let lizDataviz = function () {
let layerId = lizMap.config.layers[featureType].id;
// Do it only if the plot layer ID corresponds to the filtered layer
if (layerId == dvLayerId) {
// LWC 3.7 - Do it only if the new option trigger_filter is true
let trigger_filter = dv.config.layers[i]['trigger_filter'];
if (!trigger_filter) {
continue;
}

// Reset the status of data_fetched
dv.plots[i]['data_fetched'] = false;

Expand Down
15 changes: 11 additions & 4 deletions tests/end2end/cypress/integration/dataviz-ghaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ describe('Dataviz tests', function () {
cy.get('#dataviz > #dataviz-container > #dataviz-content > div.tab-content > ul > li:nth-child(2) > a')
.click()

// Wait for graphics displayed 4 plots are displayed
cy.wait(['@getPlot', '@getPlot', '@getPlot', '@getPlot'])
// Wait for graphics displayed 5 plots are displayed
cy.wait(['@getPlot', '@getPlot', '@getPlot', '@getPlot', '@getPlot'])

// Test first plot - Municipalities
cy.get('#dataviz_plot_0_container > h3:nth-child(1) > span:nth-child(1) > span:nth-child(2)')
Expand Down Expand Up @@ -114,6 +114,10 @@ describe('Dataviz tests', function () {
cy.get('#dataviz_plot_3 div.svg-container svg.main-svg g.cartesianlayer g.plot g.trace.bars g.points g.point')
.should('have.length', 10)

// Never filtered plot
cy.get('#dataviz_plot_4 div.svg-container svg.main-svg g.cartesianlayer g.plot g.trace.bars g.points g.point')
.should('have.length', 10)

// Click back to the first tab
cy.get('#dataviz > #dataviz-container > #dataviz-content > div.tab-content > ul > li:nth-child(1) > a')
.click()
Expand All @@ -133,14 +137,17 @@ describe('Dataviz tests', function () {
cy.get('#dataviz_plot_1 div.svg-container svg.main-svg g.cartesianlayer g.plot g.trace.bars g.points g.point')
.should('have.length', 1)

// Activate the Second tab dock to update one graphic
// Activate the Second tab dock to update one graphic only (the other one has the trigger_filter: false
cy.get('#dataviz > #dataviz-container > #dataviz-content > div.tab-content > ul > li:nth-child(2) > a')
.click()

cy.wait(['@getPlot'])

// This plot is filtered
cy.get('#dataviz_plot_3 div.svg-container svg.main-svg g.cartesianlayer g.plot g.trace.bars g.points g.point')
.should('have.length', 1)
// This plot must not have been refreshed
cy.get('#dataviz_plot_4 div.svg-container svg.main-svg g.cartesianlayer g.plot g.trace.bars g.points g.point')
.should('have.length', 10)

// Go back to the first tab
cy.get('#dataviz > #dataviz-container > #dataviz-content > div.tab-content > ul > li:nth-child(1) > a')
Expand Down
9 changes: 6 additions & 3 deletions tests/js-units/data/montpellier-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,8 @@
},
"popup_display_child_plot": "True",
"only_show_child": "False",
"abstract": ""
"abstract": "",
"trigger_filter": true
},
{
"plot_id": 1,
Expand Down Expand Up @@ -1175,7 +1176,8 @@
},
"popup_display_child_plot": "False",
"only_show_child": "False",
"abstract": ""
"abstract": "",
"trigger_filter": true
},
{
"plot_id": 2,
Expand All @@ -1198,7 +1200,8 @@
},
"popup_display_child_plot": "False",
"only_show_child": "False",
"abstract": ""
"abstract": "",
"trigger_filter": true
}
],
"dataviz": {
Expand Down
15 changes: 15 additions & 0 deletions tests/js-units/node/config/dataviz.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('DatavizElementConfig', function () {
"plot_id": 1,
"layer_id": "bakeries_1dbdac14_931c_4568_ad56_3a947a77d810",
"title": "Bar Bakeries by municipalities",
"title_popup": "Bar Bakeries for this municipalities",
"abstract": "",
"plot":{
"type": "bar",
Expand All @@ -174,10 +175,12 @@ describe('DatavizElementConfig', function () {
},
"popup_display_child_plot": "False",
"only_show_child": "False",
"trigger_filter": true
})
expect(element.plotId).to.be.eq(1)
expect(element.layerId).to.be.eq('bakeries_1dbdac14_931c_4568_ad56_3a947a77d810')
expect(element.title).to.be.eq('Bar Bakeries by municipalities')
expect(element.titlePopup).to.be.eq('Bar Bakeries for this municipalities')
expect(element.abstract).to.be.eq('')

expect(element.plot).to.not.be.eq(undefined)
Expand All @@ -200,6 +203,7 @@ describe('DatavizElementConfig', function () {

expect(element.popupDisplayChildPlot).to.be.eq(false)
expect(element.onlyShowChild).to.be.eq(false)
expect(element.triggerFilter).to.be.eq(true)
})

it('ValidationError', function () {
Expand All @@ -219,6 +223,7 @@ describe('DatavizElementConfig', function () {
"abstract": "",
"popup_display_child_plot": "False",
"only_show_child": "False",
"trigger_filter": "False"
})
} catch (error) {
expect(error.name).to.be.eq('ValidationError')
Expand Down Expand Up @@ -255,6 +260,7 @@ describe('DatavizLayersConfig', function () {
},
"popup_display_child_plot": "False",
"only_show_child": "False",
"trigger_filter": true
},
"1": {
"plot_id": 1,
Expand All @@ -279,6 +285,7 @@ describe('DatavizLayersConfig', function () {
},
"only_show_child": "False",
"popup_display_child_plot": "False",
"trigger_filter": true
},
"2": {
"plot_id": 2,
Expand All @@ -303,6 +310,7 @@ describe('DatavizLayersConfig', function () {
},
"only_show_child": "False",
"popup_display_child_plot": "False",
"trigger_filter": true
}
})

Expand Down Expand Up @@ -342,6 +350,7 @@ describe('DatavizLayersConfig', function () {

expect(element.popupDisplayChildPlot).to.be.eq(false)
expect(element.onlyShowChild).to.be.eq(false)
expect(element.triggerFilter).to.be.eq(true)

const bakeriesElements = config.getElementConfigsByLayerId('bakeries_1dbdac14_931c_4568_ad56_3a947a77d810')
expect(bakeriesElements.length).to.be.eq(2)
Expand Down Expand Up @@ -377,6 +386,7 @@ describe('DatavizLayersConfig', function () {
},
"popup_display_child_plot": "False",
"only_show_child": "False",
"trigger_filter": true
},{
"plot_id": 2,
"layer_id": "bakeries_1dbdac14_931c_4568_ad56_3a947a77d810",
Expand All @@ -400,6 +410,7 @@ describe('DatavizLayersConfig', function () {
},
"only_show_child": "False",
"popup_display_child_plot": "False",
"trigger_filter": true
},{
"plot_id": 1,
"layer_id": "bakeries_1dbdac14_931c_4568_ad56_3a947a77d810",
Expand All @@ -423,6 +434,7 @@ describe('DatavizLayersConfig', function () {
},
"only_show_child": "False",
"popup_display_child_plot": "False",
"trigger_filter": true
}
])

Expand Down Expand Up @@ -464,6 +476,7 @@ describe('DatavizLayersConfig', function () {
},
"popup_display_child_plot": "False",
"only_show_child": "False",
"trigger_filter": true
},{
"plot_id": 2,
"layer_id": "bakeries_1dbdac14_931c_4568_ad56_3a947a77d810",
Expand All @@ -487,6 +500,7 @@ describe('DatavizLayersConfig', function () {
},
"only_show_child": "False",
"popup_display_child_plot": "False",
"trigger_filter": true
},{
"plot_id": 1,
"layer_id": "bakeries_1dbdac14_931c_4568_ad56_3a947a77d810",
Expand All @@ -510,6 +524,7 @@ describe('DatavizLayersConfig', function () {
},
"only_show_child": "False",
"popup_display_child_plot": "False",
"trigger_filter": true
}
])

Expand Down
Loading

0 comments on commit 78c42f0

Please sign in to comment.