Skip to content

Commit 60ae215

Browse files
authored
fix: <svg> elements with an img role must have an alternative text (#646)
1 parent ccdf4c9 commit 60ae215

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed

packages/vega-spec-builder/src/line/linePointUtils.test.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ import {
2121
} from '@spectrum-charts/constants';
2222

2323
import {
24+
getHighlightPoint,
2425
getHighlightPointFill,
2526
getHighlightPointSize,
2627
getHighlightPointStroke,
2728
getHighlightPointStrokeOpacity,
2829
getHighlightPointStrokeWidth,
30+
getSecondaryHighlightPoint,
31+
getSelectionPoint,
2932
} from './linePointUtils';
3033
import { defaultLineMarkOptions } from './lineTestUtils';
3134

@@ -121,3 +124,127 @@ describe('getHighlightPointStrokeWidth()', () => {
121124
expect(rules[0]).toHaveProperty(`test`, `datum.${staticPoint} && datum.${staticPoint} === true`);
122125
});
123126
});
127+
128+
describe('getHighlightPoint()', () => {
129+
test('should return symbol mark with correct name and description', () => {
130+
const mark = getHighlightPoint(defaultLineMarkOptions);
131+
expect(mark.name).toBe('line0_point_highlight');
132+
expect(mark.description).toBe('line0_point_highlight');
133+
});
134+
135+
test('should return symbol mark with correct properties', () => {
136+
const mark = getHighlightPoint(defaultLineMarkOptions);
137+
expect(mark.type).toBe('symbol');
138+
expect(mark.interactive).toBe(false);
139+
expect(mark.from).toEqual({ data: 'line0_highlightedData' });
140+
});
141+
142+
test('should have correct encode structure', () => {
143+
const mark = getHighlightPoint(defaultLineMarkOptions);
144+
expect(mark.encode).toBeDefined();
145+
expect(mark.encode?.enter).toBeDefined();
146+
expect(mark.encode?.update).toBeDefined();
147+
expect(mark.encode?.enter?.y).toEqual({ field: 'value', scale: 'yLinear' });
148+
expect(mark.encode?.enter?.stroke).toEqual({ field: DEFAULT_COLOR, scale: COLOR_SCALE });
149+
});
150+
151+
test('should use custom name in mark name and description', () => {
152+
const customOptions = { ...defaultLineMarkOptions, name: 'customLine' };
153+
const mark = getHighlightPoint(customOptions);
154+
expect(mark.name).toBe('customLine_point_highlight');
155+
expect(mark.description).toBe('customLine_point_highlight');
156+
expect(mark.from).toEqual({ data: 'customLine_highlightedData' });
157+
});
158+
});
159+
160+
describe('getSelectionPoint()', () => {
161+
test('should return symbol mark with correct name and description', () => {
162+
const mark = getSelectionPoint(defaultLineMarkOptions);
163+
expect(mark.name).toBe('line0_point_select');
164+
expect(mark.description).toBe('line0_point_select');
165+
});
166+
167+
test('should return symbol mark with correct properties', () => {
168+
const mark = getSelectionPoint(defaultLineMarkOptions);
169+
expect(mark.type).toBe('symbol');
170+
expect(mark.interactive).toBe(false);
171+
expect(mark.from).toEqual({ data: 'line0_selectedData' });
172+
});
173+
174+
test('should have correct encode structure', () => {
175+
const mark = getSelectionPoint(defaultLineMarkOptions);
176+
expect(mark.encode).toBeDefined();
177+
expect(mark.encode?.enter).toBeDefined();
178+
expect(mark.encode?.update).toBeDefined();
179+
expect(mark.encode?.enter?.y).toEqual({ field: 'value', scale: 'yLinear' });
180+
expect(mark.encode?.enter?.stroke).toEqual({ field: DEFAULT_COLOR, scale: COLOR_SCALE });
181+
});
182+
183+
test('should use custom name in mark name and description', () => {
184+
const customOptions = { ...defaultLineMarkOptions, name: 'customLine' };
185+
const mark = getSelectionPoint(customOptions);
186+
expect(mark.name).toBe('customLine_point_select');
187+
expect(mark.description).toBe('customLine_point_select');
188+
expect(mark.from).toEqual({ data: 'customLine_selectedData' });
189+
});
190+
191+
test('should use selectedData instead of highlightedData', () => {
192+
const highlightMark = getHighlightPoint(defaultLineMarkOptions);
193+
const selectionMark = getSelectionPoint(defaultLineMarkOptions);
194+
expect(highlightMark.from).toEqual({ data: 'line0_highlightedData' });
195+
expect(selectionMark.from).toEqual({ data: 'line0_selectedData' });
196+
expect(highlightMark.name).toContain('highlight');
197+
expect(selectionMark.name).toContain('select');
198+
});
199+
});
200+
201+
describe('getSecondaryHighlightPoint()', () => {
202+
const secondaryMetric = 'trendlineValue';
203+
204+
test('should return symbol mark with correct name and description', () => {
205+
const mark = getSecondaryHighlightPoint(defaultLineMarkOptions, secondaryMetric);
206+
expect(mark.name).toBe('line0_secondaryPoint');
207+
expect(mark.description).toBe('line0_secondaryPoint');
208+
});
209+
210+
test('should return symbol mark with correct properties', () => {
211+
const mark = getSecondaryHighlightPoint(defaultLineMarkOptions, secondaryMetric);
212+
expect(mark.type).toBe('symbol');
213+
expect(mark.interactive).toBe(false);
214+
expect(mark.from).toEqual({ data: 'line0_highlightedData' });
215+
});
216+
217+
test('should have correct encode structure with secondary metric', () => {
218+
const mark = getSecondaryHighlightPoint(defaultLineMarkOptions, secondaryMetric);
219+
expect(mark.encode).toBeDefined();
220+
expect(mark.encode?.enter).toBeDefined();
221+
expect(mark.encode?.update).toBeDefined();
222+
expect(mark.encode?.enter?.y).toEqual({ field: secondaryMetric, scale: 'yLinear' });
223+
expect(mark.encode?.enter?.fill).toEqual({ signal: BACKGROUND_COLOR });
224+
expect(mark.encode?.enter?.stroke).toEqual({ field: DEFAULT_COLOR, scale: COLOR_SCALE });
225+
});
226+
227+
test('should use custom name in mark name and description', () => {
228+
const customOptions = { ...defaultLineMarkOptions, name: 'customLine' };
229+
const mark = getSecondaryHighlightPoint(customOptions, secondaryMetric);
230+
expect(mark.name).toBe('customLine_secondaryPoint');
231+
expect(mark.description).toBe('customLine_secondaryPoint');
232+
expect(mark.from).toEqual({ data: 'customLine_highlightedData' });
233+
});
234+
235+
test('should use the secondary metric for y-axis encoding', () => {
236+
const metric1 = 'metric1';
237+
const metric2 = 'metric2';
238+
const mark1 = getSecondaryHighlightPoint(defaultLineMarkOptions, metric1);
239+
const mark2 = getSecondaryHighlightPoint(defaultLineMarkOptions, metric2);
240+
expect(mark1.encode?.enter?.y).toEqual({ field: metric1, scale: 'yLinear' });
241+
expect(mark2.encode?.enter?.y).toEqual({ field: metric2, scale: 'yLinear' });
242+
});
243+
244+
test('should use highlightedData like the primary highlight point', () => {
245+
const mark = getSecondaryHighlightPoint(defaultLineMarkOptions, secondaryMetric);
246+
const highlightMark = getHighlightPoint(defaultLineMarkOptions);
247+
expect(mark.from).toEqual(highlightMark.from);
248+
expect(mark.from).toEqual({ data: 'line0_highlightedData' });
249+
});
250+
});

packages/vega-spec-builder/src/line/linePointUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const getHighlightOrSelectionPoint = (lineOptions: LineMarkOptions, useHighlight
103103
const { color, colorScheme, dimension, metric, metricAxis, name, scaleType } = lineOptions;
104104
return {
105105
name: `${name}_point_${useHighlightedData ? 'highlight' : 'select'}`,
106+
description: `${name}_point_${useHighlightedData ? 'highlight' : 'select'}`,
106107
type: 'symbol',
107108
from: { data: `${name}${useHighlightedData ? '_highlightedData' : '_selectedData'}` },
108109
interactive: false,
@@ -154,6 +155,7 @@ export const getSecondaryHighlightPoint = (
154155
const { color, colorScheme, dimension, metricAxis, name, scaleType } = lineOptions;
155156
return {
156157
name: `${name}_secondaryPoint`,
158+
description: `${name}_secondaryPoint`,
157159
type: 'symbol',
158160
from: { data: `${name}_highlightedData` },
159161
interactive: false,

0 commit comments

Comments
 (0)