Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(a11y): allow user to add optional semantic meaning to goal/gauge charts #1218

Merged
merged 24 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
91bb738
feat: initial commit
rshen91 May 27, 2021
c63b88b
test: update snapshot
rshen91 Jun 10, 2021
a105604
fix: merge changes
rshen91 Jun 22, 2021
6245b05
feat: add goal chart data and labels
rshen91 Jun 22, 2021
0dc89a6
test: add test
rshen91 Jun 22, 2021
ebd8af7
fix: remove min max target value from not goal types
rshen91 Jun 22, 2021
9c90b45
feat: add semantic meaning to goal/gauge charts
rshen91 Jun 23, 2021
37acc83
fix: chart api
rshen91 Jun 23, 2021
503cb9d
fix: api chart extract
rshen91 Jun 23, 2021
91f126b
test: add story snapshot
rshen91 Jun 23, 2021
f63c09c
feat: clean up semantic representation in goals rendering
rshen91 Jun 23, 2021
5620c16
refactor: add goal semantic description component
rshen91 Jun 23, 2021
aba9bae
test: add tests
rshen91 Jun 23, 2021
7c4e432
style: clean up code per code review
rshen91 Jun 23, 2021
0c77eec
Merge remote-tracking branch 'upstream/master' into goal-semantics
rshen91 Jun 30, 2021
3f0681b
style: fix test
rshen91 Jun 30, 2021
250ab2c
fix: update per code review
rshen91 Jun 30, 2021
b5a1364
refactor: change name of prop and data type
rshen91 Jul 1, 2021
4045a9c
fix: update chart api
rshen91 Jul 1, 2021
416e18d
refactor: refactor so bands includes text
rshen91 Jul 1, 2021
50b2991
Merge remote-tracking branch 'upstream/master' into goal-semantics
rshen91 Jul 6, 2021
22ef1a6
fix: update the description so correct band label shown
rshen91 Jul 6, 2021
0bfdec4
refactor: code review
rshen91 Jul 7, 2021
3702ecf
fix: pull lowest value
rshen91 Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add tests
  • Loading branch information
rshen91 committed Jun 23, 2021
commit aba9bae2388166097c5fa5fef0b3e05fbf1db8c7
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,80 @@ describe('Accessibility', () => {
/>
</Chart>,
);

const bandsWithSemanticsAscending = [
[200, 'freezing'],
[250, 'chilly'],
[300, 'brisk'],
];

const ascendingSemanticValuesGoalChart = mount(
<Chart className="story-chart">
<Goal
id="spec_1"
subtype={GoalSubtype.Goal}
base={0}
target={260}
actual={170}
// doesn't mess with canvas_renderers.ts
// @ts-ignore
bands={bandsWithSemanticsAscending.flat().filter((val) => typeof val === 'number')}
ticks={[0, 50, 100, 150, 200, 250, 300]}
// tickValueFormatter={({ value }: BandFillColorAccessorInput) => String(value)}
// bandFillColor={({ value }: BandFillColorAccessorInput) => semanticBandFillColor(value)}
labelMajor="Revenue 2020 YTD "
labelMinor="(thousand USD) "
centralMajor="170"
centralMinor=""
config={{ angleStart: Math.PI, angleEnd: 0 }}
semanticValues={bandsWithSemanticsAscending}
/>
</Chart>,
);

const bandsWithSemanticsDescending = [
[300, 'brisk'],
[250, 'chilly'],
[200, 'freezing'],
];

const descendingSemanticValuesGoalChart = mount(
<Chart className="story-chart">
<Goal
id="spec_1"
subtype={GoalSubtype.Goal}
base={300}
target={260}
actual={170}
// doesn't mess with canvas_renderers.ts
// @ts-ignore
bands={bandsWithSemanticsDescending.flat().filter((val) => typeof val === 'number')}
ticks={[300, 250, 200, 150, 100, 50, 0]}
// tickValueFormatter={({ value }: BandFillColorAccessorInput) => String(value)}
// bandFillColor={({ value }: BandFillColorAccessorInput) => semanticBandFillColor(value)}
labelMajor="Revenue 2020 YTD "
labelMinor="(thousand USD) "
centralMajor="170"
centralMinor=""
config={{ angleStart: Math.PI, angleEnd: 0 }}
semanticValues={bandsWithSemanticsDescending}
/>
</Chart>,
);
it('should test defaults for goal charts', () => {
expect(goalChartWrapper.find('.echScreenReaderOnly').first().text()).toBe(
'Goal chart label: Revenue 2020 YTD (thousand USD) Chart type:goal chartMinimum: 0Maximum: 300Target: 260Value: 170',
);
});
it('should correctly render ascending semantic values', () => {
expect(ascendingSemanticValuesGoalChart.find('.echGoalDescription').first().text()).toBe(
'values 200 - 250: freezingvalues 250 - 300: chillyvalues above 300: brisk',
);
});
it('should correctly render descending semantic values', () => {
expect(descendingSemanticValuesGoalChart.find('.echGoalDescription').first().text()).toBe(
'values 300 - 250: briskvalues 250 - 200: chillyvalues below 200: freezing',
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ interface GoalSemanticDescriptionProps {
/** @internal */
export const GoalSemanticDescription = ({ semanticValues }: GoalSemanticDescriptionProps) => {
return (
<div className="echScreenReaderOnly">
<div className="echScreenReaderOnly echGoalDescription">
{semanticValues.map(([value, semantic], index) => {
const nextValue = semanticValues[index + 1];
const prevValue = semanticValues[index - 1];
return nextValue !== undefined ? (
nextValue[0] > value ? (
<dd key={index}>{`values ${value} - ${nextValue[0]}: ${semantic}`}</dd>
) : (
<dd key={index}>{`values ${nextValue[0]} - ${value}: ${semantic}`}</dd>
)
<dd key={index}>{`values ${value} - ${nextValue[0]}: ${semantic}`}</dd>
) : prevValue[0] < value ? (
<dd key={index}>{`values above ${value}: ${semantic}`}</dd>
) : (
Expand Down