-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmk8.js
166 lines (149 loc) · 9.57 KB
/
mk8.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
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
// Generated by CoffeeScript 1.7.1
(function() {
'use strict';
var CSS_bar_toggle, CSScheat, DISPLAY_AMOUNT, L, TEMPLATIZE, boxen, filter_search, halptaxt, results_collected, score, search_string,
__slice = [].slice;
L = function() {
var things;
things = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return console.log.apply(console, things);
};
L(document.querySelector('.cheating'));
boxen = document.querySelectorAll('form input');
halptaxt = document.querySelector('.halptaxt');
CSScheat = document.querySelector('.cheating');
CSS_bar_toggle = {
enable: '.speed-bar.sub-bar,.handling-bar.sub-bar { display: block !important } .speed-bar.bar,.handling-bar.bar { display: none !important }',
disable: '.speed-bar.sub-bar,.handling-bar.sub-bar { display: none !important } .speed-bar.bar,.handling-bar.bar { display: block !important }'
};
filter_search = document.querySelector('#filter-search');
DISPLAY_AMOUNT = 5;
search_string = null;
results_collected = 0;
TEMPLATIZE = function(d, i) {
var c, char_images, space_regex, t, tire_images, v, vehicle_images, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
char_images = [];
vehicle_images = [];
tire_images = [];
space_regex = / /g;
_ref = d.value.Options[0];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
c = _ref[_i];
char_images.push("<div title='" + c + "' alt='" + c + "' class='charopt mk8" + (c.replace(space_regex, '').replace('.', '').toLowerCase()) + "'></div>");
}
_ref1 = d.value.Options[1];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
v = _ref1[_j];
vehicle_images.push("<div title='" + v + "' alt='" + v + "' class='bodyopt mk8" + (v.replace(space_regex, '').replace('.', '').toLowerCase()) + "body'></div>");
}
_ref2 = d.value.Options[2];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
t = _ref2[_k];
tire_images.push("<div title='" + t + "' alt='" + t + "' class='tireopt mk8" + (t.replace(space_regex, '').replace('.', '').toLowerCase()) + "tires'></div>");
}
return "<div class='combo-details'>\n <div class='opts'>\n <div class='opt charopts'>" + (char_images.join("")) + "</div>\n <div class='opt vehicleopts'>" + (vehicle_images.join("")) + "</div>\n <div class='opt wheelsopts'>" + (tire_images.join("")) + "</div>\n </div>\n <div class='chart'>\n <div class='bar bar speed-bar' style='width: " + (d.value["Speed"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar speed-bar' style='width: " + (d.value["SpeedByTerrain"]["Ground"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar speed-bar' style='width: " + (d.value["SpeedByTerrain"]["Water"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar speed-bar' style='width: " + (d.value["SpeedByTerrain"]["Air"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar speed-bar' style='width: " + (d.value["SpeedByTerrain"]["Anti-Gravity"] / 6 * 100 + '%') + "'> </div>\n <div class='bar acceleration-bar' style='width: " + (d.value["Acceleration"] / 6 * 100 + '%') + "'> </div>\n <div class='bar weight-bar' style='width: " + (d.value["Weight"] / 6 * 100 + '%') + "'> </div>\n <div class='bar handling-bar' style='width: " + (d.value["Handling"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar handling-bar' style='width: " + (d.value["HandlingByTerrain"]["Ground"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar handling-bar' style='width: " + (d.value["HandlingByTerrain"]["Water"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar handling-bar' style='width: " + (d.value["HandlingByTerrain"]["Air"] / 6 * 100 + '%') + "'> </div>\n <div class='sub-bar handling-bar' style='width: " + (d.value["HandlingByTerrain"]["Anti-Gravity"] / 6 * 100 + '%') + "'> </div>\n <div class='bar traction-bar' style='width: " + (d.value["Traction"] / 6 * 100 + '%') + "'> </div>\n <div class='bar miniturbo-bar' style='width: " + (d.value["Mini-Turbo"] / 6 * 100 + '%') + "'> </div>\n </div>\n <br class='clear'/>\n</div>\n<div class='details hide'>\n <hr class='clear'/>\n <div class='optnames'>\n <div class='opt charopts'><p>" + (d.value.Options[0].join("</p><p>")) + "</p></div>\n <div class='opt vehicleopts'><p>" + (d.value.Options[1].join("</p><p>")) + "</p></div>\n <div class='opt wheelsopts'><p>" + (d.value.Options[2].join("</p><p>")) + "</p></div>\n <div class='clear'/>\n </div>\n <hr class='clear'/>\n <table class='stat'>\n <thead>\n <tr>\n <th colspan='4'>Speed</th>\n <th>Acceleration</th>\n <th>Weight</th>\n <th colspan='4'>Handling</th>\n <th>Traction</th>\n <th>Mini-Turbo</th>\n </tr>\n <tr>\n <th class='speed-heading'>Ground</th>\n <th class='speed-heading'>Water</th>\n <th class='speed-heading'>Air</th>\n <th class='speed-heading'>Anti-Gravity</th>\n <th class='acceleration-heading'></th>\n <th class='weight-heading'></th>\n <th class='handling-heading'>Ground</th>\n <th class='handling-heading'>Water</th>\n <th class='handling-heading'>Air</th>\n <th class='handling-heading'>Anti-Gravity</th>\n <th class='traction-heading'></th>\n <th class='miniturbo-heading'></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>" + d.value["SpeedByTerrain"]["Ground"] + "</td>\n <td>" + d.value["SpeedByTerrain"]["Water"] + "</td>\n <td>" + d.value["SpeedByTerrain"]["Air"] + "</td>\n <td>" + d.value["SpeedByTerrain"]["Anti-Gravity"] + "</td>\n <td>" + d.value["Acceleration"] + "</td>\n <td>" + d.value["Weight"] + "</td>\n <td>" + d.value["HandlingByTerrain"]["Ground"] + "</td>\n <td>" + d.value["HandlingByTerrain"]["Water"] + "</td>\n <td>" + d.value["HandlingByTerrain"]["Air"] + "</td>\n <td>" + d.value["HandlingByTerrain"]["Anti-Gravity"] + "</td>\n <td>" + d.value["Traction"] + "</td>\n <td>" + d.value["Mini-Turbo"] + "</td>\n </tr>\n </tbody>\n </table>\n</div>\n\n<br class='clear'/>";
};
document.querySelector('.halp').addEventListener('click', function(e) {
if (this.dataset.toggle === 'true') {
this.dataset.toggle = 'false';
return halptaxt.classList.add('hide');
} else {
this.dataset.toggle = 'true';
return halptaxt.classList.remove('hide');
}
});
document.querySelector('.terrain-stats').addEventListener('click', function(e) {
if (this.dataset.toggle === 'true') {
this.dataset.toggle = 'false';
return CSScheat.innerHTML = CSS_bar_toggle.disable;
} else {
this.dataset.toggle = 'true';
return CSScheat.innerHTML = CSS_bar_toggle.enable;
}
});
score = function(combo, keys) {
var avg_of_vals, calculate_deviations, deviation, k, sum, vals, _i, _len;
if (keys.length === 0) {
return 0;
}
vals = [];
sum = 0;
for (_i = 0, _len = keys.length; _i < _len; _i++) {
k = keys[_i];
if (k === "Acceleration") {
sum += Math.floor(combo[k]);
vals.push(Math.floor(combo[k]));
} else {
sum += combo[k];
vals.push(combo[k]);
}
}
if (!(keys.length > 1)) {
return sum;
}
avg_of_vals = (vals.reduce(function(a, b) {
return a + b;
})) / keys.length;
calculate_deviations = function(a, b) {
return a + Math.pow(b - avg_of_vals, 2);
};
deviation = vals.reduce(calculate_deviations, 0);
return (Math.pow(sum, 2)) / (1 + Math.pow(deviation, 2));
};
d3.json('averaged_and_combined.json', function(err, json_data) {
var FILTER_RESULTS, rows;
if (err) {
throw new Error('Error getting data');
}
rows = d3.select('#listing').selectAll('div').data(d3.entries(json_data)).enter().append('div').html(TEMPLATIZE);
rows.classed('row', true).each(function(d, i) {
this.addEventListener('click', function(e) {
if ('true' === this.dataset.toggle) {
this.dataset.toggle = 'false';
return this.querySelector('.details').classList.add('hide');
} else {
this.dataset.toggle = 'true';
return this.querySelector('.details').classList.remove('hide');
}
});
return this.classList.add('hide');
});
FILTER_RESULTS = function(d, i) {
if (search_string === null) {
return i > DISPLAY_AMOUNT;
} else {
if (search_string.test("".concat.apply([].concat.apply([], d.value.Options)))) {
return results_collected++ > DISPLAY_AMOUNT;
} else {
return true;
}
}
};
d3.select('#filter-search').on('input', function() {
if (filter_search.value.length < 2) {
return search_string = null;
}
search_string = new RegExp(filter_search.value, 'i');
rows.classed('hide', FILTER_RESULTS);
return results_collected = 0;
});
return d3.selectAll('form input[type="checkbox"]').on('click', function(c) {
var b, sorting_by, _i, _len;
sorting_by = [];
for (_i = 0, _len = boxen.length; _i < _len; _i++) {
b = boxen[_i];
if (b.checked === true) {
sorting_by.push(b.name);
}
}
if (sorting_by.length === 0) {
return;
}
rows.sort(function(a, b) {
return score(b.value, sorting_by) - score(a.value, sorting_by);
}).classed('hide', FILTER_RESULTS);
return results_collected = 0;
});
});
}).call(this);
//# sourceMappingURL=mk8.map