@@ -8,7 +8,6 @@ import HighchartsReact from "highcharts-react-official";
88
99import { getIsRtl , useMergeRefs , useUniqueId } from "@cloudscape-design/component-toolkit/internal" ;
1010import { isDevelopment } from "@cloudscape-design/component-toolkit/internal" ;
11- import { useInternalI18n } from "@cloudscape-design/components/internal/do-not-use/i18n" ;
1211import Spinner from "@cloudscape-design/components/spinner" ;
1312
1413import { getDataAttributes } from "../internal/base-component/get-data-attributes" ;
@@ -25,8 +24,9 @@ import { ChartFooter, ChartHeader } from "./components/core-slots";
2524import { ChartTooltip } from "./components/core-tooltip" ;
2625import { VerticalAxisTitle } from "./components/core-vertical-axis-title" ;
2726import { getFormatter } from "./formatters" ;
27+ import { useChartI18n } from "./i18n-utils" ;
2828import { CoreChartProps } from "./interfaces" ;
29- import { getFormattedPointDescription } from "./utils" ;
29+ import { getPointAccessibleDescription } from "./utils" ;
3030
3131import styles from "./styles.css.js" ;
3232import testClasses from "./test-classes/styles.css.js" ;
@@ -65,18 +65,18 @@ export function InternalCoreChart({
6565 ...rest
6666} : CoreChartProps & InternalBaseComponentProps ) {
6767 const highcharts = rest . highcharts as null | typeof Highcharts ;
68- const i18n = useInternalI18n ( "[charts]" ) ;
69-
70- const settings = {
68+ const labels = useChartI18n ( { ariaLabel, ariaDescription, i18nStrings } ) ;
69+ const context = {
7170 chartId : useUniqueId ( ) ,
7271 noDataEnabled : ! ! noDataOptions ,
7372 legendEnabled : legendOptions ?. enabled !== false ,
7473 tooltipEnabled : tooltipOptions ?. enabled !== false ,
7574 keyboardNavigationEnabled : keyboardNavigation ,
75+ labels,
7676 } ;
7777 const handlers = { onHighlight, onClearHighlight, onVisibleItemsChange } ;
7878 const state = { visibleItems } ;
79- const api = useChartAPI ( settings , handlers , state ) ;
79+ const api = useChartAPI ( context , handlers , state ) ;
8080
8181 const rootClassName = clsx ( testClasses . root , styles . root , fitHeight && styles [ "root-fit-height" ] , className ) ;
8282 const rootRef = useRef < HTMLDivElement > ( null ) ;
@@ -109,15 +109,6 @@ export function InternalCoreChart({
109109 ) ;
110110 }
111111
112- const aria = {
113- chartLabel : ariaLabel ,
114- chartDescription : ariaDescription ,
115- // We reuse existing translations as passing for now, but it is possible to introduce new i18n strings that
116- // are parametrized with axes names, and more.
117- chartContainerLabel : i18n ( "i18nStrings.chartAriaRoleDescription" , i18nStrings ?. chartAccessibleDescription ) ,
118- chartXAxisLabel : i18n ( "i18nStrings.xAxisAriaRoleDescription" , i18nStrings ?. xAxisAccessibleDescription ) ,
119- chartYAxisLabel : i18n ( "i18nStrings.yAxisAriaRoleDescription" , i18nStrings ?. yAxisAccessibleDescription ) ,
120- } ;
121112 const apiOptions = api . getOptions ( ) ;
122113 const inverted = ! ! options . chart ?. inverted ;
123114 const isRtl = ( ) => getIsRtl ( rootRef ?. current ) ;
@@ -182,18 +173,22 @@ export function InternalCoreChart({
182173 accessibility : {
183174 // The default chart title is disabled by default to prevent the default "Chart" in the screen-reader detail.
184175 defaultChartTitle : "" ,
185- chartContainerLabel : aria . chartLabel ,
186- svgContainerLabel : aria . chartContainerLabel ,
176+ chartContainerLabel : labels . chartLabel ,
177+ svgContainerLabel : labels . chartContainerLabel ,
187178 // We used {names[0]} to inject the axis title, see: https://api.highcharts.com/highcharts/lang.accessibility.axis.xAxisDescriptionSingular.
188179 axis : {
189- xAxisDescriptionSingular : aria . chartXAxisLabel ? `${ aria . chartXAxisLabel } , {names[0]}` : undefined ,
190- yAxisDescriptionSingular : aria . chartYAxisLabel ? `${ aria . chartYAxisLabel } , {names[0]}` : undefined ,
180+ xAxisDescriptionSingular : labels . chartXAxisLabel
181+ ? `${ labels . chartXAxisLabel } , {names[0]}`
182+ : undefined ,
183+ yAxisDescriptionSingular : labels . chartYAxisLabel
184+ ? `${ labels . chartYAxisLabel } , {names[0]}`
185+ : undefined ,
191186 } ,
192187 ...options . lang ?. accessibility ,
193188 } ,
194189 } ,
195190 accessibility : {
196- description : aria . chartDescription ,
191+ description : labels . chartDescription ,
197192 screenReaderSection : {
198193 // We use custom before-message to remove detail that are currently not supported with our i18n.
199194 // See: https://api.highcharts.com/highcharts/accessibility.screenReaderSection.beforeChartFormat.
@@ -206,7 +201,7 @@ export function InternalCoreChart({
206201 keyboardNavigation : options . accessibility ?. keyboardNavigation ?? { enabled : ! keyboardNavigation } ,
207202 point : {
208203 // Point description formatter is overridden to respect custom axes value formatters.
209- descriptionFormatter : getFormattedPointDescription ,
204+ descriptionFormatter : ( point ) => getPointAccessibleDescription ( point , labels ) ,
210205 ...options . accessibility ?. point ,
211206 } ,
212207 } ,
@@ -312,7 +307,7 @@ export function InternalCoreChart({
312307 } }
313308 navigator = { navigator }
314309 legend = {
315- settings . legendEnabled ? (
310+ context . legendEnabled ? (
316311 < ChartLegend { ...legendOptions } position = { legendPosition } api = { api } i18nStrings = { i18nStrings } />
317312 ) : null
318313 }
@@ -333,7 +328,7 @@ export function InternalCoreChart({
333328 }
334329 />
335330
336- { settings . tooltipEnabled && (
331+ { context . tooltipEnabled && (
337332 < ChartTooltip
338333 { ...tooltipOptions }
339334 i18nStrings = { i18nStrings }
@@ -342,7 +337,7 @@ export function InternalCoreChart({
342337 />
343338 ) }
344339
345- { settings . noDataEnabled && < ChartNoData { ...noDataOptions } i18nStrings = { i18nStrings } api = { api } /> }
340+ { context . noDataEnabled && < ChartNoData { ...noDataOptions } i18nStrings = { i18nStrings } api = { api } /> }
346341 </ div >
347342 ) ;
348343}
0 commit comments