diff --git a/cypress/integration/options/legend.cy.js b/cypress/integration/options/legend.cy.js index de5d847c67..4559e65a20 100644 --- a/cypress/integration/options/legend.cy.js +++ b/cypress/integration/options/legend.cy.js @@ -9,6 +9,7 @@ import { visTypeDisplayNames, DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS, + AXIS_ID_ROWS, } from '@dhis2/analytics' import { expectChartTitleToBeVisible, @@ -338,6 +339,25 @@ describe('Options - Legend', () => { expectLegendKeyToBeVisible() expectLegedKeyItemAmountToBe(1) }) + it('legend is applied when data is in rows', () => { + // swap data and period + openContextMenu(DIMENSION_ID_PERIOD) + clickContextMenuMove(DIMENSION_ID_PERIOD, AXIS_ID_COLUMNS) + openContextMenu(DIMENSION_ID_DATA) + clickContextMenuMove(DIMENSION_ID_DATA, AXIS_ID_ROWS) + clickMenuBarUpdateButton() + + // expect legend to still be applied + expectVisualizationToBeVisible(VIS_TYPE_PIVOT_TABLE) + expectLegendKeyToBeVisible() + expectLegedKeyItemAmountToBe(1) + cy.getBySel(valueCellEl).each(($el) => { + cy.wrap($el) + .invoke('attr', 'style') + .should('not.contain', 'background-color') + .and('not.contain', EXPECTED_STANDARD_TEXT_COLOR) + }) + }) }) describe('Transferring a legend: Pivot table -> Gauge', () => { const TEST_ITEM = TEST_ITEMS[0] diff --git a/packages/plugin/src/VisualizationPlugin.js b/packages/plugin/src/VisualizationPlugin.js index 7022bf3819..b5cba08f1d 100644 --- a/packages/plugin/src/VisualizationPlugin.js +++ b/packages/plugin/src/VisualizationPlugin.js @@ -8,6 +8,7 @@ import { LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM, isLegendSetType, VIS_TYPE_LINE, + DIMENSION_ID_DATA, } from '@dhis2/analytics' import { useDataEngine } from '@dhis2/app-runtime' import { Button, IconLegend24, Layer } from '@dhis2/ui' @@ -212,8 +213,9 @@ export const VisualizationPlugin = ({ case LEGEND_DISPLAY_STRATEGY_BY_DATA_ITEM: { if ( + fetchResult.visualization.type !== VIS_TYPE_PIVOT_TABLE && !fetchResult.visualization.columns.some( - (item) => item.dimension === 'dx' + (item) => item.dimension === DIMENSION_ID_DATA ) ) { break