-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[GVBC] Enabling multiple legend selection for Grouped Vertical Bar Chart #33511
Open
srmukher
wants to merge
2
commits into
master
Choose a base branch
from
users/srmukher/multiLegendGVBC
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−23
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-charting-d99f14e6-dd3a-4f33-a8b3-9e28ea5bcfab.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Enabling multiple legend selection for Grouped Vertical Bar Chart", | ||
"packageName": "@fluentui/react-charting", | ||
"email": "120183316+srmukher@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
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 |
---|---|---|
|
@@ -65,6 +65,7 @@ export interface IGroupedVerticalBarChartState extends IBasestate { | |
dataPointCalloutProps?: IGVBarChartSeriesPoint; | ||
callOutAccessibilityData?: IAccessibilityProps; | ||
calloutLegend: string; | ||
selectedLegends: string[]; | ||
} | ||
|
||
export class GroupedVerticalBarChartBase extends React.Component< | ||
|
@@ -109,7 +110,7 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
dataForHoverCard: 0, | ||
isCalloutVisible: false, | ||
refSelected: null, | ||
selectedLegend: props.legendProps?.selectedLegend ?? '', | ||
selectedLegends: [], | ||
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. 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. done |
||
xCalloutValue: '', | ||
yCalloutValue: '', | ||
YValueHover: [], | ||
|
@@ -307,7 +308,7 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
this.setState({ | ||
refSelected: mouseEvent, | ||
/** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */ | ||
isCalloutVisible: this.state.selectedLegend === '' || this.state.selectedLegend === pointData.legend, | ||
isCalloutVisible: this._noLegendHighlighted() || this._legendHighlighted(pointData.legend), | ||
calloutLegend: pointData.legend, | ||
dataForHoverCard: pointData.data, | ||
color: pointData.color, | ||
|
@@ -343,7 +344,7 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
this.setState({ | ||
refSelected: obj.refElement, | ||
/** Show the callout if highlighted bar is focused and Hide it if unhighlighted bar is focused */ | ||
isCalloutVisible: this.state.selectedLegend === '' || this.state.selectedLegend === pointData.legend, | ||
isCalloutVisible: this._noLegendHighlighted() || this._legendHighlighted(pointData.legend), | ||
calloutLegend: pointData.legend, | ||
dataForHoverCard: pointData.data, | ||
color: pointData.color, | ||
|
@@ -555,18 +556,6 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
}); | ||
}; | ||
|
||
private _onLegendClick(legendTitle: string): void { | ||
if (this.state.selectedLegend === legendTitle) { | ||
this.setState({ | ||
selectedLegend: '', | ||
}); | ||
} else { | ||
this.setState({ | ||
selectedLegend: legendTitle, | ||
}); | ||
} | ||
} | ||
|
||
private _onLegendHover(legendTitle: string): void { | ||
this.setState({ | ||
activeLegend: legendTitle, | ||
|
@@ -598,9 +587,6 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
const legend: ILegend = { | ||
title: point.legend, | ||
color, | ||
action: () => { | ||
this._onLegendClick(point.legend); | ||
}, | ||
hoverAction: () => { | ||
this._handleChartMouseLeave(); | ||
this._onLegendHover(point.legend); | ||
|
@@ -620,10 +606,26 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
enabledWrapLines={this.props.enabledLegendsWrapLines} | ||
focusZonePropsInHoverCard={this.props.focusZonePropsForLegendsInHoverCard} | ||
{...this.props.legendProps} | ||
onChange={this._onLegendSelectionChange.bind(this)} | ||
/> | ||
); | ||
}; | ||
|
||
private _onLegendSelectionChange( | ||
selectedLegends: string[], | ||
event: React.MouseEvent<HTMLButtonElement>, | ||
currentLegend?: ILegend, | ||
): void { | ||
if (this.props.legendProps?.canSelectMultipleLegends) { | ||
this.setState({ selectedLegends }); | ||
} else { | ||
this.setState({ selectedLegends: selectedLegends.slice(-1) }); | ||
} | ||
if (this.props.legendProps?.onChange) { | ||
this.props.legendProps.onChange(selectedLegends, event, currentLegend); | ||
} | ||
} | ||
|
||
private _getAxisData = (yAxisData: IAxisData) => { | ||
if (yAxisData && yAxisData.yAxisDomainValues.length) { | ||
const { yAxisDomainValues: domainValue } = yAxisData; | ||
|
@@ -638,19 +640,24 @@ export class GroupedVerticalBarChartBase extends React.Component< | |
* 2. hovering: if there is no selected legend and the user hovers over it | ||
*/ | ||
private _legendHighlighted = (legendTitle: string) => { | ||
return ( | ||
this.state.selectedLegend === legendTitle || | ||
(this.state.selectedLegend === '' && this.state.activeLegend === legendTitle) | ||
); | ||
return this._getHighlightedLegend().includes(legendTitle!); | ||
}; | ||
|
||
/** | ||
* This function checks if none of the legends is selected or hovered. | ||
*/ | ||
private _noLegendHighlighted = () => { | ||
return this.state.selectedLegend === '' && this.state.activeLegend === ''; | ||
return this._getHighlightedLegend().length === 0; | ||
}; | ||
|
||
private _getHighlightedLegend() { | ||
return this.state.selectedLegends.length > 0 | ||
? this.state.selectedLegends | ||
: this.state.activeLegend | ||
? [this.state.activeLegend] | ||
: []; | ||
} | ||
|
||
private _getAriaLabel = (point: IGVBarChartSeriesPoint, xAxisPoint: string): string => { | ||
const xValue = point.xAxisCalloutData || xAxisPoint; | ||
const legend = point.legend; | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual regressions to review in the fluentuiv8 Visual Regression Report
Callout 4 screenshots