forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a11y): add data table for screen readers (sunburst, treemap, ici…
…cle, flame) (opensearch-project#1155) Fixes opensearch-project#1154
- Loading branch information
Showing
17 changed files
with
557 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...osd-charts/src/chart_types/partition_chart/state/selectors/get_screen_reader_data.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Store } from 'redux'; | ||
|
||
import { MockSeriesSpec } from '../../../../mocks/specs/specs'; | ||
import { MockStore } from '../../../../mocks/store'; | ||
import { GlobalChartState } from '../../../../state/chart_state'; | ||
import { PrimitiveValue } from '../../layout/utils/group_by_rollup'; | ||
import { getScreenReaderDataSelector } from './get_screen_reader_data'; | ||
|
||
describe('Get screen reader data', () => { | ||
type TestDatum = [string, string, string, number]; | ||
const spec1 = MockSeriesSpec.sunburst({ | ||
data: [ | ||
['aaa', 'aa', '1', 1], | ||
['aaa', 'aa', '3', 1], | ||
['aaa', 'bb', '4', 1], | ||
], | ||
valueAccessor: (d: TestDatum) => d[3], | ||
layers: [ | ||
{ | ||
groupByRollup: (datum: TestDatum) => datum[0], | ||
nodeLabel: (d: PrimitiveValue) => String(d), | ||
}, | ||
{ | ||
groupByRollup: (datum: TestDatum) => datum[1], | ||
nodeLabel: (d: PrimitiveValue) => String(d), | ||
}, | ||
{ | ||
groupByRollup: (datum: TestDatum) => datum[2], | ||
nodeLabel: (d: PrimitiveValue) => String(d), | ||
}, | ||
], | ||
}); | ||
|
||
const specNoSlice = MockSeriesSpec.sunburst({ | ||
data: [], | ||
valueAccessor: (d: TestDatum) => d[3], | ||
layers: [ | ||
{ | ||
groupByRollup: (datum: TestDatum) => datum[0], | ||
nodeLabel: (d: PrimitiveValue) => String(d), | ||
}, | ||
{ | ||
groupByRollup: (datum: TestDatum) => datum[1], | ||
nodeLabel: (d: PrimitiveValue) => String(d), | ||
}, | ||
{ | ||
groupByRollup: (datum: TestDatum) => datum[2], | ||
nodeLabel: (d: PrimitiveValue) => String(d), | ||
}, | ||
], | ||
}); | ||
let store: Store<GlobalChartState>; | ||
|
||
beforeEach(() => { | ||
store = MockStore.default(); | ||
}); | ||
|
||
it('should test defaults', () => { | ||
MockStore.addSpecs([spec1], store); | ||
const expected = getScreenReaderDataSelector(store.getState()); | ||
expect(expected).toEqual({ | ||
data: [ | ||
{ depth: 1, label: 'aaa', panelTitle: '', parentName: 'none', percentage: '100%', value: 3, valueText: '3' }, | ||
{ depth: 2, label: 'aa', panelTitle: '', parentName: 'aaa', percentage: '67%', value: 2, valueText: '2' }, | ||
{ depth: 3, label: '1', panelTitle: '', parentName: 'aa', percentage: '33%', value: 1, valueText: '1' }, | ||
{ depth: 3, label: '3', panelTitle: '', parentName: 'aa', percentage: '33%', value: 1, valueText: '1' }, | ||
{ depth: 2, label: 'bb', panelTitle: '', parentName: 'aaa', percentage: '33%', value: 1, valueText: '1' }, | ||
{ depth: 3, label: '4', panelTitle: '', parentName: 'bb', percentage: '33%', value: 1, valueText: '1' }, | ||
], | ||
hasMultipleLayers: true, | ||
isSmallMultiple: false, | ||
}); | ||
}); | ||
it('should compute screen reader data for no slices in pie', () => { | ||
MockStore.addSpecs([specNoSlice], store); | ||
const expected = getScreenReaderDataSelector(store.getState()); | ||
expect(expected).toEqual({ | ||
data: [], | ||
hasMultipleLayers: true, | ||
isSmallMultiple: false, | ||
}); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
...ages/osd-charts/src/chart_types/partition_chart/state/selectors/get_screen_reader_data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import createCachedSelector from 're-reselect'; | ||
|
||
import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; | ||
import { ShapeViewModel } from '../../layout/types/viewmodel_types'; | ||
import { STATISTICS_KEY } from '../../layout/utils/group_by_rollup'; | ||
import { PartitionSpec } from '../../specs'; | ||
import { partitionMultiGeometries } from './geometries'; | ||
import { getPartitionSpecs } from './get_partition_specs'; | ||
|
||
/** @internal */ | ||
export interface PartitionSectionData { | ||
panelTitle?: string; | ||
label: string; | ||
parentName: string | undefined; | ||
depth: number; | ||
percentage: string; | ||
value: number; | ||
valueText: string; | ||
} | ||
|
||
/** @internal */ | ||
export interface PartitionData { | ||
hasMultipleLayers: boolean; | ||
isSmallMultiple: boolean; | ||
data: PartitionSectionData[]; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
const getScreenReaderDataForPartitions = ( | ||
[{ valueFormatter }]: PartitionSpec[], | ||
shapeViewModels: ShapeViewModel[], | ||
): PartitionSectionData[] => { | ||
return shapeViewModels.flatMap(({ quadViewModel, layers, panelTitle }) => | ||
quadViewModel.map(({ depth, value, dataName, parent, path }) => { | ||
const label = layers[depth - 1]?.nodeLabel?.(dataName) ?? dataName; | ||
const parentValue = path.length > 1 ? path[path.length - 2].value : undefined; | ||
const parentName = | ||
depth > 1 && parentValue ? layers[depth - 2]?.nodeLabel?.(parentValue) ?? path[path.length - 1].value : 'none'; | ||
|
||
return { | ||
panelTitle, | ||
depth, | ||
label, | ||
parentName, | ||
percentage: `${Math.round((value / parent[STATISTICS_KEY].globalAggregate) * 100)}%`, | ||
value, | ||
valueText: valueFormatter ? valueFormatter(value) : `${value}`, | ||
}; | ||
}), | ||
); | ||
}; | ||
|
||
/** @internal */ | ||
export const getScreenReaderDataSelector = createCachedSelector( | ||
[getPartitionSpecs, partitionMultiGeometries], | ||
(specs, shapeViewModel): PartitionData => { | ||
if (specs.length === 0) { | ||
return { | ||
hasMultipleLayers: false, | ||
isSmallMultiple: false, | ||
data: [], | ||
}; | ||
} | ||
return { | ||
hasMultipleLayers: specs[0].layers.length > 1, | ||
isSmallMultiple: shapeViewModel.length > 1, | ||
data: getScreenReaderDataForPartitions(specs, shapeViewModel), | ||
}; | ||
}, | ||
)(getChartIdSelector); |
Oops, something went wrong.