diff --git a/change/@fluentui-react-charting-1216d12c-7b19-41b7-bbde-99ed3b330d78.json b/change/@fluentui-react-charting-1216d12c-7b19-41b7-bbde-99ed3b330d78.json new file mode 100644 index 00000000000000..a5358d1785a622 --- /dev/null +++ b/change/@fluentui-react-charting-1216d12c-7b19-41b7-bbde-99ed3b330d78.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Fix wrong narration when legend selected", + "packageName": "@fluentui/react-charting", + "email": "kumarkshitij@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap b/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap index 0e2e1a6b19f50b..d935277729521c 100644 --- a/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap +++ b/packages/react-charting/src/components/AreaChart/__snapshots__/AreaChart.test.tsx.snap @@ -376,6 +376,7 @@ exports[`AreaChart - mouse events Should render callout correctly on mouseover 1 border: 0px; } data-is-focusable={true} + hidden={false} id="toolTipundefined" style={ Object { @@ -907,6 +908,7 @@ exports[`AreaChart - mouse events Should render customized callout on mouseover border: 0px; } data-is-focusable={true} + hidden={false} id="toolTipundefined" style={ Object { @@ -1335,6 +1337,7 @@ exports[`AreaChart - mouse events Should render customized callout per stack on border: 0px; } data-is-focusable={true} + hidden={false} id="toolTipundefined" style={ Object { @@ -1725,6 +1728,9 @@ exports[`AreaChart snapShot testing renders Areachart correctly 1`] = ` + `; @@ -2046,6 +2052,9 @@ exports[`AreaChart snapShot testing renders enabledLegendsWrapLines correctly 1` + `; @@ -2228,6 +2237,9 @@ exports[`AreaChart snapShot testing renders hideLegend hhh correctly 1`] = ` + `; @@ -2569,6 +2581,9 @@ exports[`AreaChart snapShot testing renders hideTooltip correctly 1`] = ` + `; @@ -2910,6 +2925,9 @@ exports[`AreaChart snapShot testing renders showXAxisLablesTooltip correctly 1`] + `; @@ -3251,6 +3269,9 @@ exports[`AreaChart snapShot testing renders wrapXAxisLables correctly 1`] = ` + `; @@ -3592,5 +3613,8 @@ exports[`AreaChart snapShot testing renders yAxisTickFormat correctly 1`] = ` + `; diff --git a/packages/react-charting/src/components/CommonComponents/CartesianChart.base.tsx b/packages/react-charting/src/components/CommonComponents/CartesianChart.base.tsx index ef04080c0c4a36..cb47c0b1161094 100644 --- a/packages/react-charting/src/components/CommonComponents/CartesianChart.base.tsx +++ b/packages/react-charting/src/components/CommonComponents/CartesianChart.base.tsx @@ -318,25 +318,29 @@ export class CartesianChartBase extends React.Component )} - {!this.props.hideTooltip && calloutProps!.isCalloutVisible && ( - - {/** Given custom callout, then it will render */} - {this.props.customizedCallout && this.props.customizedCallout} - {/** single x point its corresponding y points of all the bars/lines in chart will render in callout */} - {!this.props.customizedCallout && this.props.isCalloutForStack && this._multiValueCallout(calloutProps)} - {/** single x point its corresponding y point of single line/bar in the chart will render in callout */} - {!this.props.customizedCallout && !this.props.isCalloutForStack && ( - - )} - - )} + {/** The callout is used for narration, so keep it mounted on the DOM */} + ); } diff --git a/packages/react-charting/src/components/DonutChart/Arc/Arc.styles.ts b/packages/react-charting/src/components/DonutChart/Arc/Arc.styles.ts index 6711f517b60340..ffd932bb78a698 100644 --- a/packages/react-charting/src/components/DonutChart/Arc/Arc.styles.ts +++ b/packages/react-charting/src/components/DonutChart/Arc/Arc.styles.ts @@ -18,6 +18,7 @@ export const getStyles = (props: IArcProps): IArcStyles => { focusRing: { stroke: theme.semanticColors.focusBorder, strokeWidth: 4, + fill: 'transparent', }, insideDonutString: { fontSize: FontSizes.large, diff --git a/packages/react-charting/src/components/DonutChart/Arc/Arc.tsx b/packages/react-charting/src/components/DonutChart/Arc/Arc.tsx index 5e15cd26b7dc15..d267f9483dbf18 100644 --- a/packages/react-charting/src/components/DonutChart/Arc/Arc.tsx +++ b/packages/react-charting/src/components/DonutChart/Arc/Arc.tsx @@ -86,9 +86,7 @@ export class Arc extends React.Component { private _hoverOn(data: IChartDataPoint, mouseEvent: React.MouseEvent): void { mouseEvent.persist(); - if (this.props.activeArc === this.props.data!.data.legend || this.props.activeArc === '') { - this.props.hoverOnCallback!(data, mouseEvent); - } + this.props.hoverOnCallback!(data, mouseEvent); } private _hoverOff = (): void => { diff --git a/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx b/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx index e19ac9ea195c83..77834f31c56b1c 100644 --- a/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx +++ b/packages/react-charting/src/components/DonutChart/DonutChart.base.tsx @@ -144,6 +144,8 @@ export class DonutChartBase extends React.Component @@ -237,12 +239,11 @@ export class DonutChartBase extends React.Component { this._currentHoverElement = element; this.setState({ - showHover: true, + /** Show the callout if highlighted arc is focused and Hide it if unhighlighted arc is focused */ + showHover: this.state.activeLegend === data.legend || this.state.activeLegend === '', value: data.data!.toString(), legend: data.legend, - activeLegend: data.legend, color: data.color!, - selectedLegend: data.legend!, xCalloutValue: data.xAxisCalloutData!, yCalloutValue: data.yAxisCalloutData!, focusedArcId: id, @@ -256,25 +257,24 @@ export class DonutChartBase extends React.Component { - this.setState({ showHover: false, focusedArcId: '', activeLegend: '', selectedLegend: 'none' }); + this.setState({ focusedArcId: '' }); }; private _hoverLeave(): void { - this.setState({ activeLegend: '', selectedLegend: 'none', focusedArcId: '' }); + /**/ } private _handleChartMouseLeave = () => { diff --git a/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap b/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap index 0ae06e0d48fee6..1e9cfcff7395bc 100644 --- a/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap +++ b/packages/react-charting/src/components/DonutChart/__snapshots__/DonutChart.test.tsx.snap @@ -106,7 +106,7 @@ exports[`DonutChart - mouse events Should render callout correctly on mouseover onMouseLeave={[Function]} onMouseMove={[Function]} onMouseOver={[Function]} - opacity={0.1} + opacity={1} role="text" /> , ): void => { mouseEvent.persist(); - if ( - (this.state.isLegendSelected === false || - (this.state.isLegendSelected && this.state.titleForHoverCard === pointData.legend)) && - this._calloutAnchorPoint !== pointData - ) { + if (this._calloutAnchorPoint !== pointData) { this._calloutAnchorPoint = pointData; this.setState({ refSelected: mouseEvent, - isCalloutVisible: true, - titleForHoverCard: pointData.legend, + /** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */ + isCalloutVisible: + this.state.isLegendSelected === false || + (this.state.isLegendSelected === true && this.state.titleForHoverCard === pointData.legend), + calloutLegend: pointData.legend, dataForHoverCard: pointData.data, color: pointData.color, xCalloutValue: pointData.xAxisCalloutData, @@ -266,30 +267,28 @@ export class GroupedVerticalBarChartBase extends React.Component< groupData: any, refArrayIndexNumber: number, ): void => { - if ( - this.state.isLegendSelected === false || - (this.state.isLegendSelected && this.state.titleForHoverCard === pointData.legend) - ) { - this._refArray.forEach((obj: IRefArrayData, index: number) => { - if (obj.index === pointData.legend && refArrayIndexNumber === index) { - this.setState({ - refSelected: obj.refElement, - isCalloutVisible: true, - titleForHoverCard: pointData.legend, - dataForHoverCard: pointData.data, - color: pointData.color, - xCalloutValue: pointData.xAxisCalloutData, - yCalloutValue: pointData.yAxisCalloutData, - dataPointCalloutProps: pointData, - callOutAccessibilityData: this.props.isCalloutForStack - ? groupData.stackCallOutAccessibilityData - : pointData.callOutAccessibilityData, - YValueHover: groupData.groupSeries, - hoverXValue: pointData.xAxisCalloutData, - }); - } - }); - } + this._refArray.forEach((obj: IRefArrayData, index: number) => { + if (obj.index === pointData.legend && refArrayIndexNumber === index) { + this.setState({ + refSelected: obj.refElement, + /** Show the callout if highlighted bar is focused and Hide it if unhighlighted bar is focused */ + isCalloutVisible: + this.state.isLegendSelected === false || + (this.state.isLegendSelected === true && this.state.titleForHoverCard === pointData.legend), + calloutLegend: pointData.legend, + dataForHoverCard: pointData.data, + color: pointData.color, + xCalloutValue: pointData.xAxisCalloutData, + yCalloutValue: pointData.yAxisCalloutData, + dataPointCalloutProps: pointData, + callOutAccessibilityData: this.props.isCalloutForStack + ? groupData.stackCallOutAccessibilityData + : pointData.callOutAccessibilityData, + YValueHover: groupData.groupSeries, + hoverXValue: pointData.xAxisCalloutData, + }); + } + }); }; private _redirectToUrl = (href: string | undefined): void => { diff --git a/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap b/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap index fb4896075789d7..3f700f17197207 100644 --- a/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap +++ b/packages/react-charting/src/components/GroupedVerticalBarChart/__snapshots__/GroupedVerticalBarChart.test.tsx.snap @@ -618,6 +618,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render callout correctly border: 0px; } data-is-focusable={false} + hidden={false} id="toolTipcallout0" style={ Object { @@ -1365,6 +1366,7 @@ exports[`GroupedVerticalBarChart - mouse events Should render customized callout border: 0px; } data-is-focusable={false} + hidden={false} id="toolTipcallout0" style={ Object { @@ -1988,6 +1990,9 @@ exports[`GroupedVerticalBarChart snapShot testing renders GroupedVerticalBarChar + `; @@ -2545,6 +2550,9 @@ exports[`GroupedVerticalBarChart snapShot testing renders enabledLegendsWrapLine + `; @@ -2783,6 +2791,9 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideLegend correctly 1 + `; @@ -3360,6 +3371,9 @@ exports[`GroupedVerticalBarChart snapShot testing renders hideTooltip correctly + `; @@ -3937,6 +3951,9 @@ exports[`GroupedVerticalBarChart snapShot testing renders showXAxisLablesTooltip + `; @@ -4514,6 +4531,9 @@ exports[`GroupedVerticalBarChart snapShot testing renders wrapXAxisLables correc + `; @@ -5091,5 +5111,8 @@ exports[`GroupedVerticalBarChart snapShot testing renders yAxisTickFormat correc + `; diff --git a/packages/react-charting/src/components/HeatMapChart/HeatMapChart.base.tsx b/packages/react-charting/src/components/HeatMapChart/HeatMapChart.base.tsx index 2cfb39e29e6a53..1de69743d1f6d1 100644 --- a/packages/react-charting/src/components/HeatMapChart/HeatMapChart.base.tsx +++ b/packages/react-charting/src/components/HeatMapChart/HeatMapChart.base.tsx @@ -257,7 +257,10 @@ export class HeatMapChartBase extends React.Component { this.setState({ target: this._rectRefArray[id].refElement, - isCalloutVisible: true, + /** Show the callout if highlighted rectangle is focused and Hide it if unhighlighted rectangle is focused */ + isCalloutVisible: + this.state.isLegendSelected === false || + (this.state.isLegendSelected === true && this.state.activeLegend === data.legend), calloutYValue: `${data.rectText}`, calloutTextColor: this._colorScale(data.value), calloutLegend: data.legend, @@ -274,7 +277,10 @@ export class HeatMapChartBase extends React.Component