charts-sparkline.js
4.97 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
$( document ).ready(function() {
var DrawSparkline = function() {
$('#sparkline1').sparkline([0, 23, 43, 35, 44, 45, 56, 37, 40], {
type: 'line',
width: $('#sparkline1').width(),
height: '165',
chartRangeMax: 50,
lineColor: '#ebcc3a',
fillColor: 'rgba(235,204,58,0.3)',
highlightLineColor: 'rgba(0,0,0,.1)',
highlightSpotColor: 'rgba(0,0,0,.2)',
});
$('#sparkline1').sparkline([25, 23, 26, 24, 25, 32, 30, 24, 19], {
type: 'line',
width: $('#sparkline1').width(),
height: '165',
chartRangeMax: 40,
lineColor: '#EB3737',
fillColor: 'rgba(242,86,86,0.3)',
composite: true,
highlightLineColor: 'rgba(0,0,0,.1)',
highlightSpotColor: 'rgba(0,0,0,.2)',
});
$('#sparkline2').sparkline([3, 6, 7, 8, 6, 4, 7, 10, 12, 7, 4, 9, 12, 13, 11, 12], {
type: 'bar',
height: '165',
barWidth: '10',
barSpacing: '3',
barColor: '#7A6FBE'
});
$('#sparkline3').sparkline([20, 40, 30, 10], {
type: 'pie',
width: '165',
height: '165',
sliceColors: ['#7a6fbe', '#61c5e3', '#343F47', '#f6d433']
});
$('#sparkline4').sparkline([0, 23, 43, 35, 44, 45, 56, 37, 40], {
type: 'line',
width: $('#sparkline1').width(),
height: '165',
chartRangeMax: 50,
lineColor: '#ebcc3a',
fillColor: 'transparent',
highlightLineColor: 'rgba(0,0,0,.1)',
highlightSpotColor: 'rgba(0,0,0,.2)'
});
$('#sparkline4').sparkline([25, 23, 26, 24, 25, 32, 30, 24, 19], {
type: 'line',
width: $('#sparkline1').width(),
height: '165',
chartRangeMax: 40,
lineColor: '#EB3737',
fillColor: 'transparent',
composite: true,
highlightLineColor: 'rgba(0,0,0,.1)',
highlightSpotColor: 'rgba(0,0,0,.2)'
});
$('#sparkline6').sparkline([3, 6, 7, 8, 6, 4, 7, 10, 12, 7, 4, 9, 12, 13, 11, 12], {
type: 'bar',
height: '165',
barWidth: '10',
barSpacing: '3',
barColor: '#8DDFF6'
});
$('#sparkline6').sparkline([3, 6, 7, 8, 6, 4, 7, 10, 12, 7, 4, 9, 12, 13, 11, 12], {
type: 'line',
width: $('#sparkline1').width(),
height: '165',
lineColor: '#F25656',
fillColor: 'transparent',
composite: true,
highlightLineColor: 'rgba(0,0,0,.1)',
highlightSpotColor: 'rgba(0,0,0,.2)'
});
},
DrawMouseSpeed = function () {
var mrefreshinterval = 500; // update display every 500ms
var lastmousex=-1;
var lastmousey=-1;
var lastmousetime;
var mousetravel = 0;
var mpoints = [];
var mpoints_max = 30;
$('html').mousemove(function(e) {
var mousex = e.pageX;
var mousey = e.pageY;
if (lastmousex > -1) {
mousetravel += Math.max( Math.abs(mousex-lastmousex), Math.abs(mousey-lastmousey) );
}
lastmousex = mousex;
lastmousey = mousey;
});
var mdraw = function() {
var md = new Date();
var timenow = md.getTime();
if (lastmousetime && lastmousetime!=timenow) {
var pps = Math.round(mousetravel / (timenow - lastmousetime) * 1000);
mpoints.push(pps);
if (mpoints.length > mpoints_max)
mpoints.splice(0,1);
mousetravel = 0;
$('#sparkline5').sparkline(mpoints, {
tooltipSuffix: ' pixels per second',
type: 'line',
width: $('#sparkline1').width(),
height: '165',
chartRangeMax: 50,
lineColor: '#22BAA0',
fillColor: 'rgba(34,186,160,0.3)',
highlightLineColor: 'rgba(24,147,126,.1)',
highlightSpotColor: 'rgba(24,147,126,.2)',
});
}
lastmousetime = timenow;
setTimeout(mdraw, mrefreshinterval);
}
// We could use setInterval instead, but I prefer to do it this way
setTimeout(mdraw, mrefreshinterval);
};
DrawSparkline();
DrawMouseSpeed();
var resizeChart;
$(window).resize(function(e) {
clearTimeout(resizeChart);
resizeChart = setTimeout(function() {
DrawSparkline();
DrawMouseSpeed();
}, 300);
});
});