-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.jsx
145 lines (139 loc) · 4.53 KB
/
index.jsx
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
import { color } from 'd3-color';
import { interpolateRgb } from 'd3-interpolate';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import LiquidFillGauge from '../src';
const Gauge = ({ radius = 200, value = 0, ...props }) => {
const startColor = '#6495ed'; // cornflowerblue
const endColor = '#dc143c'; // crimson
const interpolate = interpolateRgb(startColor, endColor);
const fillColor = interpolate(value / 100);
const gradientStops = [
{
key: '0%',
stopColor: color(fillColor).darker(0.5).toString(),
stopOpacity: 1,
offset: '0%'
},
{
key: '50%',
stopColor: fillColor,
stopOpacity: 0.75,
offset: '50%'
},
{
key: '100%',
stopColor: color(fillColor).brighter(0.5).toString(),
stopOpacity: 0.5,
offset: '100%'
}
];
return (
<LiquidFillGauge
{...props}
width={radius * 2}
height={radius * 2}
value={value}
percent="%"
textSize={1}
textOffsetX={0}
textOffsetY={0}
textRenderer={({ value, width, height, textSize, percent }) => {
value = Math.round(value);
const radius = Math.min(height / 2, width / 2);
const textPixels = (textSize * radius / 2);
const valueStyle = {
fontSize: textPixels
};
const percentStyle = {
fontSize: textPixels * 0.6
};
return (
<tspan>
<tspan className="value" style={valueStyle}>{value}</tspan>
<tspan style={percentStyle}>{percent}</tspan>
</tspan>
);
}}
riseAnimation
waveAnimation
waveFrequency={2}
waveAmplitude={1}
gradient
gradientStops={gradientStops}
circleStyle={{
fill: fillColor
}}
waveStyle={{
fill: fillColor
}}
textStyle={{
fill: color('#444').toString(),
fontFamily: 'Arial'
}}
waveTextStyle={{
fill: color('#fff').toString(),
fontFamily: 'Arial'
}}
/>
);
};
class App extends Component {
state = {
value1: Math.random() * 100,
value2: Math.random() * 100
};
render() {
return (
<div className="container-fluid">
<div className="row">
<div className="col-md-6 col-sm-12">
<Gauge
style={{ margin: '0 auto 20px auto' }}
radius={200}
value={this.state.value1}
onClick={() => {
this.setState({ value1: Math.random() * 100 });
}}
/>
</div>
<div className="col-md-6 col-sm-12">
<Gauge
style={{ margin: '0 auto 20px auto' }}
radius={200}
value={this.state.value2}
onClick={() => {
this.setState({ value2: Math.random() * 100 });
}}
/>
</div>
</div>
<div className="row">
<div
style={{
margin: '20px auto',
width: 120
}}
>
<button
type="button"
className="btn btn-default btn-block"
onClick={() => {
this.setState({
value1: Math.random() * 100,
value2: Math.random() * 100
});
}}
>
Refresh
</button>
</div>
</div>
</div>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('container')
);