-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathGaugeChart.SingleSegment.Example.tsx
135 lines (129 loc) · 4.16 KB
/
GaugeChart.SingleSegment.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
import * as React from 'react';
import {
DataVizPalette,
GaugeChart,
GaugeValueFormat,
GaugeChartVariant,
getGradientFromToken,
DataVizGradientPalette,
} from '@fluentui/react-charting';
import { Stack, StackItem } from '@fluentui/react';
import { Toggle } from '@fluentui/react/lib/Toggle';
interface IGCSingleSegmentExampleState {
width: number;
height: number;
chartValue: number;
enableGradient: boolean;
roundedCorners: boolean;
}
export class GaugeChartSingleSegmentExample extends React.Component<{}, IGCSingleSegmentExampleState> {
constructor(props = {}) {
super(props);
this.state = {
width: 252,
height: 173,
chartValue: 50,
enableGradient: false,
roundedCorners: false,
};
}
public render(): React.ReactNode {
return (
<div className="containerDiv">
<Stack horizontal wrap tokens={{ childrenGap: 20 }}>
<StackItem>
<label htmlFor="width-slider">Width:</label>
<input
type="range"
value={this.state.width}
min={0}
max={1000}
id="width-slider"
onChange={this._onWidthChange}
aria-valuetext={`Width: ${this.state.width}`}
/>
<span>{this.state.width}</span>
</StackItem>
<StackItem>
<label htmlFor="height-slider">Height:</label>
<input
type="range"
value={this.state.height}
min={0}
max={1000}
id="height-slider"
onChange={this._onHeightChange}
aria-valuetext={`Height: ${this.state.height}`}
/>
<span>{this.state.height}</span>
</StackItem>
<StackItem>
<label htmlFor="value-slider">Current value:</label>
<input
type="range"
value={this.state.chartValue}
min={0}
max={100}
id="value-slider"
onChange={this._onValueChange}
aria-valuetext={`Current value: ${this.state.chartValue}`}
/>
<span>{this.state.chartValue}</span>
</StackItem>
</Stack>
<div style={{ display: 'flex' }}>
<Toggle
label="Enable Gradient"
onText="ON"
offText="OFF"
checked={this.state.enableGradient}
onChange={this._onToggleGradient}
/>
<Toggle
label="Rounded Corners"
onText="ON"
offText="OFF"
checked={this.state.roundedCorners}
onChange={this._onToggleRoundedCorners}
/>
</div>
<GaugeChart
width={this.state.width}
height={this.state.height}
segments={[
{ size: this.state.chartValue, legend: 'Used' },
{
size: 100 - this.state.chartValue,
color: DataVizPalette.color5,
gradient: getGradientFromToken(DataVizGradientPalette.gradient6),
legend: 'Available',
},
]}
chartValue={this.state.chartValue}
chartTitle="Storage capacity"
sublabel="used"
chartValueFormat={GaugeValueFormat.Fraction}
variant={GaugeChartVariant.SingleSegment}
enableGradient={this.state.enableGradient}
roundCorners={this.state.roundedCorners}
/>
</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 _onValueChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ chartValue: parseInt(e.target.value, 10) });
};
private _onToggleGradient = (e: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ enableGradient: checked });
};
private _onToggleRoundedCorners = (e: React.MouseEvent<HTMLElement>, checked: boolean) => {
this.setState({ roundedCorners: checked });
};
}