diff --git a/src/util/types.ts b/src/util/types.ts index 653b687d91..1d085c198f 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1733,7 +1733,8 @@ export interface AriaLabelOption { separator?: { middle?: string; end?: string; - } + }, + excludeDimensionId?: number[] } } diff --git a/src/visual/aria.ts b/src/visual/aria.ts index a184776274..33187c4f9d 100644 --- a/src/visual/aria.ts +++ b/src/visual/aria.ts @@ -218,11 +218,14 @@ export default function ariaVisual(ecModel: GlobalModel, api: ExtensionAPI) { const middleSeparator = labelModel.get(['data', 'separator', 'middle']); const endSeparator = labelModel.get(['data', 'separator', 'end']); + const excludeDimensionId = labelModel.get(['data', 'excludeDimensionId']); const dataLabels = []; for (let i = 0; i < data.count(); i++) { if (i < maxDataCnt) { const name = data.getName(i); - const value = data.getValues(i); + const value = !excludeDimensionId ? data.getValues(i) + : zrUtil.filter(data.getValues(i), (v, j) => + zrUtil.indexOf(excludeDimensionId, j) === -1); const dataLabel = labelModel.get(['data', name ? 'withName' : 'withoutName']); dataLabels.push( replace(dataLabel, { diff --git a/test/ut/spec/series/aria-columns-exclude.test.ts b/test/ut/spec/series/aria-columns-exclude.test.ts new file mode 100644 index 0000000000..08df08f50d --- /dev/null +++ b/test/ut/spec/series/aria-columns-exclude.test.ts @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 { EChartsType } from '@/src/echarts'; +import { createChart, getECModel } from '../../core/utHelper'; + +describe('aria, omit data', function () { + let chart: EChartsType; + const option = { + 'aria': { + 'enabled': true, + 'data': { + 'excludeDimensionId': [0, 1, 2] + }, + }, + 'dataset': [ + { + 'dimensions': [ + 'lng', + 'lat', + 'name', + 'value', + 'capacity', + ], + 'source': [ + [ + 1.58285827, + 42.099784969, + 'Llosa del Cavall (Navès)', + 17.945, + 80, + ], + [ + 0.960270444, + 41.134931354, + 'Riudecanyes', + 0.401, + 5.32, + ], + ] + + } + ], + 'series': [ + { + 'coordinateSystem': 'geo', + 'encode': { + 'itemName': 'name' + }, + 'type': 'scatter', + } + ], + }; + beforeEach(function () { + chart = createChart(); + }); + + afterEach(function () { + chart.dispose(); + }); + + it('specified columns should be omitted from Aria (geolocation and name)', () => { + chart.setOption(option); + const el = chart.getDom(); + const ariaValue = el.getAttribute('aria-label'); + expect(ariaValue).toContain('Llosa del Cavall (Navès) is 17.945, 80'); + expect(ariaValue).toContain('Riudecanyes is 0.401, 5.32'); + expect(ariaValue).not.toContain(1.58285827); + expect(ariaValue).not.toContain(42.099784969); + expect(ariaValue).not.toContain(0.960270444); + expect(ariaValue).not.toContain(41.134931354); + }); + + it('should not modify the data of the chart', async () => { + chart.setOption(option); + const listData = getECModel(chart).getSeries()[0].getData(); + expect(listData.getValues(0)).toEqual([1.58285827, 42.099784969, 'Llosa del Cavall (Navès)', 17.945, 80]); + expect(listData.getValues(1)).toEqual([0.960270444, 41.134931354, 'Riudecanyes', 0.401, 5.32]); + }); + +});