-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_people.js
78 lines (64 loc) · 1.8 KB
/
display_people.js
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
var areasToDefine = 11;
var dotMax = 0;
var dotMin = 0;
var dotAreas = [];
var showActualValue = function() {
var matrixDotElem = $(this);
var val = matrixDotElem.attr('value') || '0';
$('.display-count .count-value').text(val);
};
var hideActualValue = function() {
$('.display-count .count-value').text('-');
};
var addHoverListeners = function() {
$('.matrixdot').hover(showActualValue);
$('.quadrant').mouseleave(hideActualValue);
};
var addMatrixClasses = function() {
$('.matrixdot').each(function() {
var arrIsIterated = false;
var className;
var dotElem = $(this);
var dotElemValue = parseInt(dotElem.attr('value'), 10);
var elemIsBelow = false;
var i = 0;
while(i < dotAreas.length) {
elemIsBelow = dotElemValue < dotAreas[i];
arrIsIterated = i + 1 >= dotAreas.length;
if (elemIsBelow || arrIsIterated) {
className = i > 0 ?
'op-' + i + '0' :
'op-0';
dotElem.addClass(className);
break;
}
i++;
}
});
};
var setDotsValues = function() {
var area = 0;
var i = 0;
var dotsValues = [];
var dotsValuesAvg = 0;
var dotsValuesSum = 0;
$('.matrixdot').each(function() {
var val = parseInt($(this).attr('value'), 10)
dotsValues.push(val);
dotsValuesSum += val;
});
dotsValuesAvg = Math.floor(dotsValuesSum / dotsValues.length * 10) / 10;
$('.display-count .avg-value').text(dotsValuesAvg);
dotMax = Math.max.apply(Math, dotsValues);
while (i++ < areasToDefine) {
area = Math.floor(dotMax / areasToDefine * i);
dotAreas.push(area);
}
};
var displayMaxEntry = function() {
$('.display-count .max-value').text(dotMax);
};
$(document).ready(setDotsValues);
$(document).ready(addHoverListeners);
$(document).ready(addMatrixClasses);
$(document).ready(displayMaxEntry);