From aeb078eb769064e8645477f69b860207bfb8a75d Mon Sep 17 00:00:00 2001 From: semla Date: Thu, 1 Aug 2024 12:33:12 +0200 Subject: [PATCH 1/2] feat(aria): allows excluding data in aria-label --- src/util/types.ts | 3 +- src/visual/aria.ts | 4 +- .../spec/series/aria-columns-exclude.test.ts | 97 +++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 test/ut/spec/series/aria-columns-exclude.test.ts diff --git a/src/util/types.ts b/src/util/types.ts index 653b687d91..c29d158747 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1733,7 +1733,8 @@ export interface AriaLabelOption { separator?: { middle?: string; end?: string; - } + }, + excludeDataId?: number[] } } diff --git a/src/visual/aria.ts b/src/visual/aria.ts index a184776274..d44aa6e4bb 100644 --- a/src/visual/aria.ts +++ b/src/visual/aria.ts @@ -218,11 +218,13 @@ export default function ariaVisual(ecModel: GlobalModel, api: ExtensionAPI) { const middleSeparator = labelModel.get(['data', 'separator', 'middle']); const endSeparator = labelModel.get(['data', 'separator', 'end']); + const excludeDataId = labelModel.get(['data', 'excludeDataId']); 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 = !excludeDataId ? data.getValues(i) + : zrUtil.filter(data.getValues(i), (v, j) => zrUtil.indexOf(excludeDataId, 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..2c91bb5771 --- /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': { + 'excludeDataId': [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]); + }); + +}); From b1a237448b11bcb326c3a61339c369c9ccded5ed Mon Sep 17 00:00:00 2001 From: semla Date: Fri, 2 Aug 2024 09:08:53 +0200 Subject: [PATCH 2/2] refactor(aria): rename property to exclude --- src/util/types.ts | 2 +- src/visual/aria.ts | 7 ++++--- test/ut/spec/series/aria-columns-exclude.test.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/types.ts b/src/util/types.ts index c29d158747..1d085c198f 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1734,7 +1734,7 @@ export interface AriaLabelOption { middle?: string; end?: string; }, - excludeDataId?: number[] + excludeDimensionId?: number[] } } diff --git a/src/visual/aria.ts b/src/visual/aria.ts index d44aa6e4bb..33187c4f9d 100644 --- a/src/visual/aria.ts +++ b/src/visual/aria.ts @@ -218,13 +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 excludeDataId = labelModel.get(['data', 'excludeDataId']); + 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 = !excludeDataId ? data.getValues(i) - : zrUtil.filter(data.getValues(i), (v, j) => zrUtil.indexOf(excludeDataId, j) === -1); + 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 index 2c91bb5771..08df08f50d 100644 --- a/test/ut/spec/series/aria-columns-exclude.test.ts +++ b/test/ut/spec/series/aria-columns-exclude.test.ts @@ -26,7 +26,7 @@ describe('aria, omit data', function () { 'aria': { 'enabled': true, 'data': { - 'excludeDataId': [0, 1, 2] + 'excludeDimensionId': [0, 1, 2] }, }, 'dataset': [