-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix legends selection bugs #24563
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
Fix legends selection bugs #24563
Changes from all commits
f8a9ff0
09ecaca
17a566b
704d230
802802d
25c9686
208c8c1
1a88853
c7ec0d3
3625b77
605f547
9807339
376a49e
1b75d31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Fix legends selection bugs", | ||
| "packageName": "@fluentui/react-charting", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,11 +101,10 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt | |
| super(props); | ||
| this._createSet = memoizeFunction((data: IChartProps) => this._createDataSet(data.lineChartData!)); | ||
| this.state = { | ||
| selectedLegend: '', | ||
| activeLegend: '', | ||
| hoverXValue: '', | ||
| isCalloutVisible: false, | ||
| isLegendSelected: false, | ||
| isLegendHovered: false, | ||
| refSelected: null, | ||
| YValueHover: [], | ||
| lineXValue: 0, | ||
|
|
@@ -430,42 +429,28 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt | |
| this._chart = this._drawGraph(containerHeight, xAxis, yAxis, xElement!); | ||
| }; | ||
|
|
||
| private _onLegendClick(customMessage: string): void { | ||
| if (this.state.isLegendSelected) { | ||
| if (this.state.activeLegend === customMessage) { | ||
| this.setState({ | ||
| isLegendSelected: false, | ||
| activeLegend: '', | ||
| }); | ||
| } else { | ||
| this.setState({ | ||
| activeLegend: customMessage, | ||
| }); | ||
| } | ||
| private _onLegendClick(legend: string): void { | ||
| if (this.state.selectedLegend === legend) { | ||
| this.setState({ | ||
| selectedLegend: '', | ||
| }); | ||
| } else { | ||
| this.setState({ | ||
| activeLegend: customMessage, | ||
| selectedLegend: legend, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private _onLegendHover(customMessage: string): void { | ||
| if (this.state.isLegendSelected === false) { | ||
| this.setState({ | ||
| activeLegend: customMessage, | ||
| isLegendHovered: true, | ||
| }); | ||
| } | ||
| private _onLegendHover(legend: string): void { | ||
| this.setState({ | ||
| activeLegend: legend, | ||
| }); | ||
| } | ||
|
|
||
| private _onLegendLeave(isLegendFocused?: boolean): void { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to keep track of isLegendFocused flag.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it is not needed in the new logic |
||
| if (!!isLegendFocused || this.state.isLegendSelected === false) { | ||
| this.setState({ | ||
| activeLegend: '', | ||
| isLegendHovered: false, | ||
| isLegendSelected: isLegendFocused ? false : this.state.isLegendSelected, | ||
| }); | ||
| } | ||
| private _onLegendLeave(): void { | ||
| this.setState({ | ||
| activeLegend: '', | ||
| }); | ||
| } | ||
|
|
||
| private _getLegendData = (palette: IPalette, points: ILineChartPoints[]): JSX.Element => { | ||
|
|
@@ -493,8 +478,8 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt | |
| hoverAction: () => { | ||
| this._onLegendHover(singleChartData.legend); | ||
| }, | ||
| onMouseOutAction: (isLegendSelected?: boolean) => { | ||
| this._onLegendLeave(isLegendSelected); | ||
| onMouseOutAction: () => { | ||
| this._onLegendLeave(); | ||
| }, | ||
| }; | ||
|
|
||
|
|
@@ -518,14 +503,11 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt | |
| this.setState({ isCircleClicked: true }); | ||
| }; | ||
|
|
||
| private _getOpacity = (selectedArea: string): number => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is _getOpacity applicable for legends
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it is only applicable for elements inside the chart |
||
| private _getOpacity = (legend: string): number => { | ||
| if (!this._isMultiStackChart) { | ||
| return 0.7; | ||
| } else { | ||
| let opacity = 0.7; | ||
| if (this.state.isLegendHovered || this.state.isLegendSelected) { | ||
| opacity = this.state.activeLegend === selectedArea ? 0.7 : 0.1; | ||
| } | ||
| const opacity = this._legendHighlighted(legend) || this._noLegendHighlighted() ? 0.7 : 0.1; | ||
| return opacity; | ||
| } | ||
| }; | ||
|
|
@@ -538,8 +520,8 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt | |
| if (this.state.isCalloutVisible) { | ||
| opacity = 1; | ||
| } | ||
| if (this.state.isLegendHovered || this.state.isLegendSelected) { | ||
| opacity = this.state.activeLegend === legend ? 0 : 0.1; | ||
| if (!this._noLegendHighlighted()) { | ||
| opacity = this._legendHighlighted(legend) ? 0 : 0.1; | ||
| } | ||
| return opacity; | ||
| } | ||
|
|
@@ -701,4 +683,23 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt | |
| isCalloutVisible: false, | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * This function checks if the given legend is highlighted or not. | ||
| * A legend can be highlighted in 2 ways: | ||
| * 1. selection: if the user clicks on it | ||
| * 2. hovering: if there is no selected legend and the user hovers over it | ||
| */ | ||
| private _legendHighlighted = (legend: string) => { | ||
| return ( | ||
| this.state.selectedLegend === legend || (this.state.selectedLegend === '' && this.state.activeLegend === legend) | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * This function checks if none of the legends is selected or hovered. | ||
| */ | ||
| private _noLegendHighlighted = () => { | ||
| return this.state.selectedLegend === '' && this.state.activeLegend === ''; | ||
| }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.