From d08ea62932b3c107ff0137b24d9cca07afd10662 Mon Sep 17 00:00:00 2001 From: Shefali Joshi Date: Tue, 11 Jul 2023 16:16:46 -0700 Subject: [PATCH] Toggle between showing aggregate stacked plot legend or per-plot legend (#6758) * New option to show/hide stacked plot aggregate legend - defaulted to not show. Use the Plot component in the StackedPlotItem component for simplicity and show/hide sub-legends as needed. * Fix position and expanded classes when children are showing their legends * Fix broken tests and ensure gridlines and cursorguides work. * Adds e2e test for new legend configuration for stacked plot * Address review comments - Remove commented out code, optimize property lookup, fix bug with staleness * Remove the isStale icon in the legend when a plot is inside a stacked plot. --------- Co-authored-by: Jamie V --- .../plugins/plot/stackedPlot.e2e.spec.js | 47 ++++++++++- src/plugins/plot/MctPlot.vue | 3 +- src/plugins/plot/Plot.vue | 82 +++++++++++++++++-- src/plugins/plot/chart/MctChart.vue | 4 +- src/plugins/plot/configuration/LegendModel.js | 3 +- .../plot/inspector/PlotOptionsBrowse.vue | 8 ++ .../plot/inspector/PlotOptionsEdit.vue | 6 +- .../plot/inspector/forms/LegendForm.vue | 27 +++++- .../plot/legend/PlotLegendItemCollapsed.vue | 11 ++- src/plugins/plot/stackedPlot/StackedPlot.vue | 37 +++++++-- .../plot/stackedPlot/StackedPlotItem.vue | 64 +++++++-------- src/plugins/plot/stackedPlot/pluginSpec.js | 15 ++-- src/styles/_legacy-plots.scss | 4 - 13 files changed, 243 insertions(+), 68 deletions(-) diff --git a/e2e/tests/functional/plugins/plot/stackedPlot.e2e.spec.js b/e2e/tests/functional/plugins/plot/stackedPlot.e2e.spec.js index c2e46566d4d..8d83e62c39c 100644 --- a/e2e/tests/functional/plugins/plot/stackedPlot.e2e.spec.js +++ b/e2e/tests/functional/plugins/plot/stackedPlot.e2e.spec.js @@ -26,7 +26,11 @@ necessarily be used for reference when writing new tests in this area. */ const { test, expect } = require('../../../../pluginFixtures'); -const { createDomainObjectWithDefaults, selectInspectorTab } = require('../../../../appActions'); +const { + createDomainObjectWithDefaults, + selectInspectorTab, + waitForPlotsToRender +} = require('../../../../appActions'); test.describe('Stacked Plot', () => { let stackedPlot; @@ -227,4 +231,45 @@ test.describe('Stacked Plot', () => { page.locator('[aria-label="Plot Series Properties"] .c-object-label') ).toContainText(swgC.name); }); + + test('the legend toggles between aggregate and per child', async ({ page }) => { + await page.goto(stackedPlot.url); + + // Go into edit mode + await page.click('button[title="Edit"]'); + + await selectInspectorTab(page, 'Config'); + + let legendProperties = await page.locator('[aria-label="Legend Properties"]'); + await legendProperties.locator('[title="Display legends per sub plot."]~div input').uncheck(); + + await assertAggregateLegendIsVisible(page); + + // Save (exit edit mode) + await page.locator('button[title="Save"]').click(); + await page.locator('li[title="Save and Finish Editing"]').click(); + + await assertAggregateLegendIsVisible(page); + + await page.reload(); + + await assertAggregateLegendIsVisible(page); + }); }); + +/** + * Asserts that aggregate stacked plot legend is visible + * @param {import('@playwright/test').Page} page + */ +async function assertAggregateLegendIsVisible(page) { + // Wait for plot series data to load + await waitForPlotsToRender(page); + // Wait for plot legend to be shown + await page.waitForSelector('.js-stacked-plot-legend', { state: 'attached' }); + // There should be 3 legend items + expect( + await page + .locator('.js-stacked-plot-legend .c-plot-legend__wrapper div.plot-legend-item') + .count() + ).toBe(3); +} diff --git a/src/plugins/plot/MctPlot.vue b/src/plugins/plot/MctPlot.vue index 899af22c72b..cb23e0c505d 100644 --- a/src/plugins/plot/MctPlot.vue +++ b/src/plugins/plot/MctPlot.vue @@ -77,6 +77,7 @@

    Legend

    +
  • +
    + Show legend per plot +
    +
    {{ showLegendsForChildren ? 'Yes' : 'No' }}
    +
  • -
      +

        Legend

      diff --git a/src/plugins/plot/inspector/forms/LegendForm.vue b/src/plugins/plot/inspector/forms/LegendForm.vue index 5c72b1a382e..d30a5018320 100644 --- a/src/plugins/plot/inspector/forms/LegendForm.vue +++ b/src/plugins/plot/inspector/forms/LegendForm.vue @@ -21,6 +21,16 @@ -->