-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathHorizontalBarChartWithAxis.Basic.Example.tsx
210 lines (195 loc) · 6.89 KB
/
HorizontalBarChartWithAxis.Basic.Example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import * as React from 'react';
import {
HorizontalBarChartWithAxis,
IHorizontalBarChartWithAxisProps,
IHorizontalBarChartWithAxisDataPoint,
getColorFromToken,
DataVizPalette,
} from '@fluentui/react-charting';
import { IRenderFunction } from '@fluentui/react/lib/Utilities';
import { ChoiceGroup, IChoiceGroupOption } from '@fluentui/react/lib/ChoiceGroup';
import { Checkbox } from '@fluentui/react/lib/Checkbox';
import { Toggle } from '@fluentui/react/lib/Toggle';
interface IHorizontalBarChartWithAxisState {
width: number;
height: number;
isCalloutselected: boolean;
useSingleColor: boolean;
enableGradient: boolean;
roundCorners: boolean;
selectMultipleLegends: boolean;
}
const options: IChoiceGroupOption[] = [
{ key: 'basicExample', text: 'Basic Example' },
{ key: 'calloutExample', text: 'Custom Callout Example' },
];
export class HorizontalBarChartWithAxisBasicExample extends React.Component<
IHorizontalBarChartWithAxisProps,
IHorizontalBarChartWithAxisState
> {
constructor(props: IHorizontalBarChartWithAxisProps) {
super(props);
this.state = {
width: 650,
height: 350,
isCalloutselected: false,
useSingleColor: false,
enableGradient: false,
roundCorners: false,
selectMultipleLegends: false,
};
}
public componentDidMount(): void {
const style = document.createElement('style');
const focusStylingCSS = `
.containerDiv [contentEditable=true]:focus,
.containerDiv [tabindex]:focus,
.containerDiv area[href]:focus,
.containerDiv button:focus,
.containerDiv iframe:focus,
.containerDiv input:focus,
.containerDiv select:focus,
.containerDiv textarea:focus {
outline: -webkit-focus-ring-color auto 5px;
}
`;
style.appendChild(document.createTextNode(focusStylingCSS));
document.head.appendChild(style);
}
public render(): JSX.Element {
return <div>{this._basicExample()}</div>;
}
private _onWidthChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ width: parseInt(e.target.value, 10) });
};
private _onHeightChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ height: parseInt(e.target.value, 10) });
};
private _onChange = (ev: React.FormEvent<HTMLInputElement>, option: IChoiceGroupOption): void => {
if (this.state.isCalloutselected) {
this.setState({ isCalloutselected: false });
} else {
this.setState({ isCalloutselected: true });
}
};
private _onCheckChange = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ useSingleColor: checked });
};
private _onToggleGradient = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ enableGradient: checked });
};
private _onToggleRoundCorners = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ roundCorners: checked });
};
private _onToggleRoundMultipleLegendSelection = (ev: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ selectMultipleLegends: checked });
};
private _basicExample(): JSX.Element {
const points: IHorizontalBarChartWithAxisDataPoint[] = [
{
x: 10000,
y: 5000,
legend: 'Oranges',
color: getColorFromToken(DataVizPalette.color1),
// gradient: getGradientFromToken(DataVizGradientPalette.gradient1),
yAxisCalloutData: '2020/04/30',
xAxisCalloutData: '10%',
},
{
x: 20000,
y: 50000,
legend: 'Dogs',
color: getColorFromToken(DataVizPalette.color2),
// gradient: getGradientFromToken(DataVizGradientPalette.gradient2),
yAxisCalloutData: '2020/04/30',
xAxisCalloutData: '20%',
},
{
x: 25000,
y: 30000,
legend: 'Apples',
color: getColorFromToken(DataVizPalette.color3),
// gradient: getGradientFromToken(DataVizGradientPalette.gradient3),
yAxisCalloutData: '2020/04/30',
xAxisCalloutData: '37%',
},
{
x: 40000,
y: 13000,
legend: 'Bananas',
color: getColorFromToken(DataVizPalette.color4),
// gradient: getGradientFromToken(DataVizGradientPalette.gradient4),
yAxisCalloutData: '2020/04/30',
xAxisCalloutData: '88%',
},
];
//const lineOptions: ILineChartLineOptions = { lineBorderWidth: '2' };
const rootStyle = { width: `${this.state.width}px`, height: `${this.state.height}px` };
return (
<div className="containerDiv">
<label htmlFor="changeWidth">Change Width:</label>
<input
type="range"
value={this.state.width}
min={200}
max={1000}
onChange={this._onWidthChange}
id="changeWidth"
aria-valuetext={`ChangeWidthSlider${this.state.width}`}
/>
<label htmlFor="changeHeight">Change Height:</label>
<input
type="range"
value={this.state.height}
min={200}
max={1000}
id="changeHeight"
onChange={this._onHeightChange}
aria-valuetext={`ChangeHeightslider${this.state.height}`}
/>
<ChoiceGroup options={options} defaultSelectedKey="basicExample" onChange={this._onChange} label="Pick one" />
<Checkbox
label="use single color(This will have only one color)"
checked={this.state.useSingleColor}
onChange={this._onCheckChange}
styles={{ root: { marginTop: '20px' } }}
/>
<div style={{ display: 'flex' }}>
<Toggle label="Enable Gradient" onText="ON" offText="OFF" onChange={this._onToggleGradient} />
<Toggle label="Rounded Corners" onText="ON" offText="OFF" onChange={this._onToggleRoundCorners} />
<Toggle
label="Select multiple legends"
onText="ON"
offText="OFF"
onChange={this._onToggleRoundMultipleLegendSelection}
/>
</div>
<br />
<div style={rootStyle}>
<HorizontalBarChartWithAxis
culture={window.navigator.language}
chartTitle="Horizontal bar chart basic example "
data={points}
width={this.state.width}
useSingleColor={this.state.useSingleColor}
height={this.state.height}
{...(this.state.isCalloutselected && {
onRenderCalloutPerDataPoint: (
props: IHorizontalBarChartWithAxisDataPoint,
defaultRender: IRenderFunction<IHorizontalBarChartWithAxisDataPoint>,
) => (props ? defaultRender(props) : null),
})}
enableReflow={true}
enableGradient={this.state.enableGradient}
roundCorners={this.state.roundCorners}
legendProps={{
canSelectMultipleLegends: this.state.selectMultipleLegends,
}}
/>
</div>
</div>
);
}
}