Skip to content

Commit 5737045

Browse files
authored
27286 Add alt text to image in high contrast mode [Update Enhanced Scatter to support high contrast mode] (#30)
1 parent 5eacfc8 commit 5737045

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/visual.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ module powerbi.extensibility.visual {
794794
return !!(dataView && dataView.metadata);
795795
}
796796

797-
private parseSettings(dataView, colorHelper: ColorHelper): Settings {
797+
private parseSettings(dataView: DataView, colorHelper: ColorHelper): Settings {
798798
const settings: Settings = Settings.parse(dataView) as Settings;
799799

800800
settings.dataPoint.defaultColor = colorHelper.getHighContrastColor(
@@ -811,6 +811,8 @@ module powerbi.extensibility.visual {
811811
settings.legend.labelColor
812812
);
813813

814+
settings.categoryLabels.show = settings.categoryLabels.show || colorHelper.isHighContrast;
815+
814816
settings.categoryLabels.color = colorHelper.getHighContrastColor(
815817
"foreground",
816818
settings.categoryLabels.color
@@ -832,6 +834,8 @@ module powerbi.extensibility.visual {
832834
this.parseAxisSettings(settings.categoryAxis, colorHelper);
833835
this.parseAxisSettings(settings.valueAxis, colorHelper);
834836

837+
settings.backdrop.show = settings.backdrop.show && !colorHelper.isHighContrast;
838+
835839
return settings;
836840
}
837841

@@ -2678,7 +2682,12 @@ module powerbi.extensibility.visual {
26782682
}
26792683

26802684
return this.svgDefaultImage;
2681-
}
2685+
},
2686+
"title": (dataPoint: EnhancedScatterChartDataPoint) => {
2687+
return dataPoint.formattedCategory
2688+
? dataPoint.formattedCategory()
2689+
: null;
2690+
},
26822691
})
26832692
.each(function (dataPoint: EnhancedScatterChartDataPoint): void {
26842693
const bubbleRadius: number = EnhancedScatterChart.getBubbleRadius(

test/visualBuilder.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module powerbi.extensibility.visual.test {
9898
.children(".labels");
9999
}
100100

101-
public get dataLabelsText(): JQuery<HTMLElement> {
101+
public get dataLabelsText(): JQuery {
102102
return this.dataLabels
103103
.children("text.data-labels");
104104
}
@@ -116,6 +116,13 @@ module powerbi.extensibility.visual.test {
116116
.children("path.dot");
117117
}
118118

119+
public get images(): JQuery {
120+
return this.mainGraphicsContext
121+
.children("svg")
122+
.children("g.ScatterMarkers")
123+
.children("image.img");
124+
}
125+
119126
public get legendGroup(): JQuery {
120127
return this.element
121128
.children(".legend")

test/visualTest.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,29 @@ module powerbi.extensibility.visual.test {
949949
});
950950

951951
describe("Accessibility", () => {
952+
it("title attribute should be filled for all of images for screen readers", (done) => {
953+
const dataView: DataView = defaultDataViewBuilder.getDataView([
954+
EnhancedScatterChartData.ColumnCategory,
955+
EnhancedScatterChartData.ColumnSeries,
956+
EnhancedScatterChartData.ColumnX,
957+
EnhancedScatterChartData.ColumnY,
958+
EnhancedScatterChartData.ColumnSize,
959+
EnhancedScatterChartData.ColumnImage,
960+
]);
961+
962+
visualBuilder.updateRenderTimeout(dataView, () => {
963+
const images: JQuery[] = visualBuilder.images.toArray().map($);
964+
965+
images.forEach((image: JQuery) => {
966+
const altText: string = image.attr("title");
967+
968+
expect(altText).toBeDefined();
969+
});
970+
971+
done();
972+
});
973+
});
974+
952975
describe("High contrast mode", () => {
953976
const backgroundColor: string = "#000000";
954977
const foregroundColor: string = "#ffff00";

0 commit comments

Comments
 (0)