forked from microsoft/responsible-ai-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
announce highcharts confusion matrix heatmap tooltip aria label for a…
…ccessibility (microsoft#2467)
- Loading branch information
1 parent
5e9b84c
commit 35b5537
Showing
2 changed files
with
115 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
.../src/lib/ModelAssessmentDashboard/Controls/ModelOverview/ConfusionMatrixHeatmapConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { ITheme } from "@fluentui/react"; | ||
import { IHighchartsConfig } from "@responsible-ai/core-ui"; | ||
import { localization } from "@responsible-ai/localization"; | ||
import { Point, PointOptionsObject } from "highcharts"; | ||
|
||
import { wrapText } from "./StatsTableUtils"; | ||
|
||
export function getHeatmapPointDescription( | ||
point: Point, | ||
selectedClasses: string[] | ||
): string { | ||
return localization.formatString( | ||
localization.ModelAssessment.ModelOverview.confusionMatrix | ||
.confusionMatrixHeatmapTooltip, | ||
`<b>${(point as Point & { value: number }).value} </b>`, | ||
`<b>${selectedClasses[point.y ?? 0]}</b>`, | ||
`<b>${selectedClasses[point.x ?? 0]}</b>` | ||
); | ||
} | ||
|
||
export function getHeatmapConfig( | ||
confusionMatrix: PointOptionsObject[], | ||
selectedClasses: string[], | ||
theme: ITheme | ||
): IHighchartsConfig { | ||
const confusionMatrixLocString = | ||
localization.ModelAssessment.ModelOverview.confusionMatrix; | ||
return { | ||
accessibility: { | ||
keyboardNavigation: { | ||
enabled: true | ||
}, | ||
point: { | ||
descriptionFormatter(point: Point): string { | ||
return getHeatmapPointDescription(point, selectedClasses); | ||
} | ||
} | ||
}, | ||
chart: { | ||
height: selectedClasses.length * 40 + 200, | ||
marginBottom: 80, | ||
marginTop: 80, | ||
plotBorderWidth: 1, | ||
type: "heatmap", | ||
width: selectedClasses.length * 100 + 200 | ||
}, | ||
colorAxis: { | ||
maxColor: theme.palette.blue, | ||
min: 0, | ||
minColor: theme.palette.white | ||
}, | ||
custom: { | ||
minHeight: 300 | ||
}, | ||
legend: { | ||
align: "right", | ||
enabled: true, | ||
layout: "vertical", | ||
symbolHeight: selectedClasses.length * 40 + 40, | ||
verticalAlign: "middle" | ||
}, | ||
series: [ | ||
{ | ||
borderWidth: 1, | ||
data: confusionMatrix, | ||
dataLabels: { | ||
color: theme.palette.black, | ||
enabled: true, | ||
style: { | ||
color: theme.semanticColors.bodyText | ||
} | ||
}, | ||
type: "heatmap" | ||
} | ||
], | ||
tooltip: { | ||
formatter(): string | undefined { | ||
return wrapText( | ||
getHeatmapPointDescription(this.point, selectedClasses), | ||
40, | ||
10 | ||
); | ||
} | ||
}, | ||
xAxis: { | ||
categories: selectedClasses, | ||
title: { | ||
style: { | ||
fontWeight: "bold" | ||
}, | ||
text: `${confusionMatrixLocString.confusionMatrixXAxisLabel}` | ||
} | ||
}, | ||
yAxis: { | ||
categories: selectedClasses, | ||
title: { | ||
text: `<b>${confusionMatrixLocString.confusionMatrixYAxisLabel}</b>` | ||
} | ||
} | ||
}; | ||
} |