Skip to content

Commit

Permalink
fix: manual cherry-pick of #2753
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Nov 3, 2023
1 parent a242449 commit 41537ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cypress/integration/options/legend.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
visTypeDisplayNames,
DIMENSION_ID_PERIOD,
AXIS_ID_COLUMNS,
AXIS_ID_ROWS,
} from '@dhis2/analytics'
import {
expectChartTitleToBeVisible,
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin/src/VisualizationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 41537ff

Please sign in to comment.