Sparkline.js
9.96 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import React, { Component } from 'react';
import { Col, Row, Alert, Progress, Button, ButtonGroup, Input, InputGroup, InputGroupAddon } from 'reactstrap';
import $ from 'jquery';
/* eslint-disable */
import 'imports-loader?jQuery=jquery,this=>window!jquery-sparkline';
/* eslint-enable */
import Widget from '../../../components/Widget';
class Sparkline extends Component {
state = { isAlertVisible: true }
componentDidMount() {
this.initCharts();
window.addEventListener('resize', this.initCharts);
}
componentWillUnmount() {
window.removeEventListener('resize', this.initCharts);
}
initCharts = () => {
this.initSparkline1();
this.initSparkline2();
this.initSparkline3();
this.initSparkline4();
this.initSparkline5();
this.initSparkline6();
this.initSparkline7();
}
toggleAlert = () => {
this.setState(prevState => ({ isAlertVisible: !prevState.isAlertVisible }));
}
generateRandomArr(length, min, max, isFloat) { // eslint-disable-line
const result = [];
const maxDefault = 100;
const minDefault = -100;
let rand = 0;
min = min === 0 ? 0 : (min || minDefault); // eslint-disable-line
max = max === 0 ? 0 : (max || maxDefault); // eslint-disable-line
for (let i = 0; i < length; i += 1) {
rand = Math.random() * (Math.abs(result[i - 1] / 10) || 1) * [min, max][i % 2];
rand = rand < min ? min : rand;
result.push(isFloat ? rand : Math.round(rand));
}
return result;
}
initSparkline1() {
this.$sparkline1.sparkline(this.generateRandomArr(80, -150), {
type: 'bar',
height: '140px',
width: '100%',
barWidth: 6,
barSpacing: 3,
barColor: '#ffebb2',
negBarColor: '#f59f9f',
});
// Chrome and Safari fix for to set correct width to chart
this.$sparkline1.find('canvas').css({ width: this.$sparkline1.width() });
}
initSparkline2() {
this.$sparkline2.sparkline(this.generateRandomArr(6, 4, 15), {
type: 'pie',
width: '200px',
height: '200px',
sliceColors: ['#ffd7de', '#8fe5d4', '#ace5d1', '#ffebb2', '#fff8e3'],
highlightLighten: 1.05,
});
}
initSparkline3() {
this.$sparkline3.sparkline(this.generateRandomArr(5), {
width: '100%',
fillColor: '#ffebb2',
height: '100px',
lineColor: 'transparent',
spotColor: '#c0d0f0',
minSpotColor: null,
maxSpotColor: null,
highlightSpotColor: '#ddd',
highlightLineColor: '#ddd',
}).sparkline(this.generateRandomArr(7), {
composite: true,
lineColor: 'transparent',
spotColor: '#c0d0f0',
fillColor: '#ace5d1',
minSpotColor: null,
maxSpotColor: null,
highlightSpotColor: '#ddd',
highlightLineColor: '#ddd',
});
}
initSparkline4() {
this.$sparkline4.sparkline(this.generateRandomArr(10, 10, 30), {
type: 'line',
width: '100%',
height: '200px',
lineColor: '#a7beff',
fillColor: '#d1dcff',
lineWidth: 2,
spotColor: '#547fff',
minSpotColor: '#fdf7e6',
maxSpotColor: '#f55d5d',
highlightSpotColor: '#547fff',
highlightLineColor: '#ffffff',
spotRadius: 1,
chartRangeMin: 5,
chartRangeMax: 7,
normalRangeColor: '#547fff',
drawNormalOnTop: true,
});
}
initSparkline5() {
this.$sparkline5.sparkline(this.generateRandomArr(2, 8, 15), {
type: 'pie',
width: '100px',
height: '100px',
sliceColors: ['#f59f9f', '#ffd7de'],
highlightLighten: 1.1,
});
}
initSparkline6() {
this.$sparkline6.sparkline(this.generateRandomArr(102, -1, 1), {
type: 'tristate',
height: '100px',
width: '100%',
posBarColor: '#ffebb2',
negBarColor: '#b7b3ff',
zeroBarColor: '#d6dee5',
barWidth: 5,
barSpacing: 3,
zeroAxis: true,
});
// Chrome and Safari fix for to set correct width to chart
this.$sparkline6.find('canvas').css({ width: this.$sparkline6.width() });
}
initSparkline7() {
this.$sparkline7.sparkline(this.generateRandomArr(15, 10, 100, true), {
width: '100%',
height: '200px',
lineColor: '#547fff',
fillColor: false,
});
}
render() {
return (
<div>
<Row>
<Col xs={12} lg={6} xl={5}>
<Widget
title={<h5>Sparkline <span className="fw-semi-bold">Bar Chart</span></h5>}
close collapse
>
<p className="fs-mini text-muted">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="chart-overflow-bottom" ref={(r) => { this.$sparkline1 = $(r); }} />
<div className="stats-row text-muted mt-xlg">
<div className="stat-item">
<h6 className="name">ARR ($)</h6>
<p className="value">4 375 800</p>
</div>
<div className="stat-item">
<h6 className="name">MRR ($)</h6>
<p className="value">863 425</p>
</div>
<div className="stat-item">
<h6 className="name">TTN ($)</h6>
<p className="value">5 634 100</p>
</div>
<div className="stat-item">
<h6 className="name">MRR / ARR </h6>
<p className="value">0.1634</p>
</div>
</div>
<hr />
<div className="d-flex justify-content-between">
<small>
<span className="badge badge-warning">Profit</span> Legend Item Emulation
</small>
<small>
<span className="badge badge-danger">Loss</span> Legend Item Emulation
</small>
</div>
</Widget>
</Col>
<Col xs={12} lg={6} xl={4}>
<Widget
title={<h5>Sparkline <span className="fw-semi-bold">Pie Chart</span></h5>}
close collapse
>
<p className="fs-mini text-muted">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="text-center" ref={(r) => { this.$sparkline2 = $(r); }} />
<Alert className="text-muted" color="white" isOpen={this.state.isAlertVisible} toggle={this.toggleAlert}>
<h5>Sales Report</h5>
<Progress className="progress-xs" color="secondary" value="16" />
<p className="text-muted"><small>Prev year quota achievement 16%. Should work harder!</small></p>
</Alert>
</Widget>
</Col>
<Col xs={12} lg={6} xl={3}>
<Widget
title={<h5>Area <span className="fw-semi-bold">Sparkline</span></h5>}
close collapse
>
<p className="fs-mini text-muted">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="stats-row text-muted mt">
<div className="stat-item">
<h6 className="name">Overall Growth</h6>
<p className="value">43.75%</p>
</div>
<div className="stat-item">
<h6 className="name">Montly</h6>
<p className="value">86.34%</p>
</div>
</div>
<p className="text-muted fs-mini">
<span className="fw-semi-bold">17% higher</span> than last month
</p>
<div className="chart-overflow-bottom" ref={(r) => { this.$sparkline3 = $(r); }} />
</Widget>
</Col>
</Row>
<Row>
<Col xs={12} lg={7} xl={9}>
<Widget
title={<h5>Sparkline <span className="fw-semi-bold">Line Chart</span></h5>}
close collapse
>
<p className="fs-mini text-muted">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="chart-overflow-bottom" ref={(r) => { this.$sparkline4 = $(r); }} />
</Widget>
</Col>
<Col xs={12} lg={5} xl={3}>
<Widget
title={<h5>Sparkline <span className="fw-semi-bold">Pie Chart</span></h5>}
close collapse
>
<p className="fs-mini text-muted">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="text-center" ref={(r) => { this.$sparkline5 = $(r); }} />
<p className="mt">Possible actions:</p>
<ButtonGroup>
<Button color="light">Yoga</Button>
<Button color="light">Coffee</Button>
<Button color="light">Dancing</Button>
</ButtonGroup>
</Widget>
</Col>
<Col xs={12} lg={6}>
<Widget
title={<h5>Sparkline <span className="fw-semi-bold">Pie Chart</span></h5>}
close collapse
>
<InputGroup>
<Input type="text" size={16} placeholder="Filter By Period: MM/DD/YYY" />
<InputGroupAddon><i className="fa fa-search text-gray" /></InputGroupAddon>
</InputGroup>
<p className="fs-mini text-muted mt">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="chart-overflow-bottom" ref={(r) => { this.$sparkline6 = $(r); }} />
</Widget>
</Col>
<Col xs={12} lg={6}>
<Widget
title={<h5>Sparkline <span className="fw-semi-bold">Line Chart</span></h5>}
close collapse
>
<p className="fs-mini text-muted">Each example displayed below takes just 1 line of HTML or javascript to generate.</p>
<div className="chart-overflow-bottom" ref={(r) => { this.$sparkline7 = $(r); }} />
</Widget>
</Col>
</Row>
</div>
);
}
}
export default Sparkline;