-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Controlled Selection of Legends (#33436)
- Loading branch information
Showing
9 changed files
with
221 additions
and
35 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-charting-6f18a170-09c5-46e5-a97d-e3adfbe863d0.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": "Add support for controlled selction of legends.", | ||
"packageName": "@fluentui/react-charting", | ||
"email": "[email protected]", | ||
"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
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
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
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
64 changes: 64 additions & 0 deletions
64
packages/react-examples/src/react-charting/Legends/Legends.Controlled.Example.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,64 @@ | ||
/* eslint-disable react/jsx-no-bind */ | ||
import * as React from 'react'; | ||
import { Legends, ILegend, DataVizPalette, getColorFromToken } from '@fluentui/react-charting'; | ||
import { DefaultButton, Stack } from '@fluentui/react'; | ||
|
||
const legends: ILegend[] = [ | ||
{ | ||
title: 'Legend 1', | ||
color: getColorFromToken(DataVizPalette.color1), | ||
}, | ||
{ | ||
title: 'Legend 2', | ||
color: getColorFromToken(DataVizPalette.color2), | ||
}, | ||
{ | ||
title: 'Legend 3', | ||
color: getColorFromToken(DataVizPalette.color3), | ||
shape: 'diamond', | ||
}, | ||
{ | ||
title: 'Legend 4', | ||
color: getColorFromToken(DataVizPalette.color4), | ||
shape: 'triangle', | ||
}, | ||
]; | ||
|
||
export const LegendsControlledExample: React.FunctionComponent = () => { | ||
const [selectedLegends, setSelectedLegends] = React.useState<string[]>([]); | ||
|
||
const onChange = (keys: string[]) => { | ||
setSelectedLegends(keys); | ||
}; | ||
|
||
const handleSelect1And3 = () => { | ||
setSelectedLegends(['Legend 1', 'Legend 3']); | ||
}; | ||
|
||
const handleSelect2And4 = () => { | ||
setSelectedLegends(['Legend 2', 'Legend 4']); | ||
}; | ||
|
||
const handleSelectAll = () => { | ||
setSelectedLegends(legends.map(legend => legend.title)); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Stack horizontal tokens={{ childrenGap: 10 }} styles={{ root: { marginBottom: 15 } }}> | ||
<DefaultButton onClick={handleSelect1And3}>Select 1 and 3</DefaultButton> | ||
<DefaultButton onClick={handleSelect2And4}>Select 2 and 4</DefaultButton> | ||
<DefaultButton onClick={handleSelectAll}>Select all</DefaultButton> | ||
</Stack> | ||
<Legends | ||
legends={legends} | ||
canSelectMultipleLegends | ||
selectedLegends={selectedLegends} | ||
// eslint-disable-next-line react/jsx-no-bind | ||
onChange={onChange} | ||
styles={{ root: { marginBottom: 10 } }} | ||
/> | ||
Selected legends: {selectedLegends.join(', ')} | ||
</div> | ||
); | ||
}; |
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
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
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