forked from 8values/8values.github.io
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
results.html
334 lines (321 loc) · 14.5 KB
/
results.html
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<head>
<link href='style.css' rel='stylesheet' type='text/css'>
<title data-i18n="title_results">8values Results</title>
<link rel="icon" type="x-icon" href="icon.png">
<link rel="shortcut icon" type="x-icon" href="icon.png">
<meta charset="utf-8">
<link rel="manifest" href="manifest.json" />
</head>
<body>
<button class="lang_button small_button" onclick="i18next.changeLanguage('pl'); location.reload();">Polski</button>
<button class="lang_button small_button" onclick="i18next.changeLanguage('en'); location.reload();">English</button>
<button data-i18n="switch_theme" class="theme_button small_button" onclick="switchTheme();"></button>
<h1>8values</h1>
<hr>
<h1 data-i18n="results"></h1>
<h2><span data-i18n="economic_axis"></span><span class="weight-300" id="economic-label"></span></h2>
<div class="axis">
<figure>
<img id="img-equality" src="value_images/equality.svg" width="128pt" />
<figcaption id="cap-equality" data-i18n="equality" data-ns="values" class="small"></figcaption>
</figure>
<div class="bar equality" id="bar-equality">
<div class="text-wrapper" id="equality"></div>
</div>
<div class="bar wealth" id="bar-wealth">
<div class="text-wrapper" id="wealth"></div>
</div>
<figure>
<img id="img-wealth" src="value_images/wealth.svg" width="128pt" />
<figcaption id="cap-wealth" data-i18n="wealth" data-ns="values" class="small"></figcaption>
</figure>
</div>
<h2><span data-i18n="diplomatic_axis"></span><span class="weight-300" id="diplomatic-label"></span></h2>
<div class="axis">
<figure>
<img id="img-might" src="value_images/might.svg" width="128pt" />
<figcaption id="cap-might" data-i18n="might" data-ns="values" class="small"></figcaption>
</figure>
<div class="bar might" id="bar-might">
<div class="text-wrapper" id="might"></div>
</div>
<div class="bar peace" id="bar-peace">
<div class="text-wrapper" id="peace"></div>
</div>
<figure>
<img id="img-peace" src="value_images/peace.svg" width="128pt" />
<figcaption id="cap-peace" data-i18n="peace" data-ns="values" class="small"></figcaption>
</figure>
</div>
<h2><span data-i18n="civic_axis"></span><span class="weight-300" id="state-label"></span></h2>
<div class="axis">
<figure>
<img id="img-liberty" src="value_images/liberty.svg" width="128pt" />
<figcaption id="cap-liberty" data-i18n="liberty" data-ns="values" class="small"></figcaption>
</figure>
<div class="bar liberty" id="bar-liberty">
<div class="text-wrapper" id="liberty"></div>
</div>
<div class="bar authority" id="bar-authority">
<div class="text-wrapper" id="authority"></div>
</div>
<figure>
<img id="img-authority" src="value_images/authority.svg" width="128pt" />
<figcaption id="cap-authority" data-i18n="authority" data-ns="values" class="small"></figcaption>
</figure>
</div>
<h2><span data-i18n="societal_axis"></span><span class="weight-300" id="society-label"></span></h2>
<div class="axis">
<figure>
<img id="img-tradition" src="value_images/tradition.svg" width="128pt" />
<figcaption id="cap-tradition" data-i18n="tradition" data-ns="values" class="small"></figcaption>
</figure>
<div class="bar tradition" id="bar-tradition">
<div class="text-wrapper" id="tradition"></div>
</div>
<div class="bar progress" id="bar-progress">
<div class="text-wrapper" id="progress"></div>
</div>
<figure>
<img id="img-progress" src="value_images/progress.svg" width="128pt" />
<figcaption id="cap-progress" data-i18n="progress" data-ns="values" class="small"></figcaption>
</figure>
</div>
<h2><span data-i18n="closest_match"></span><span class="weight-300" id="ideology-label"></span></h2>
<p data-i18n="match_desc"></p>
<hr/>
<button data-i18n="download" class="small_button" style="display: initial" onclick="downloadCanvas()"></button>
<canvas id="banner" width=800 height=650 style="font-family:Montserrat"></canvas>
<h2><span data-i18n="you_here"></span></h2>
<p data-i18n="you_here_desc"></p><br/>
<button data-i18n="back" class="button" onclick="localStorage.removeItem('state'); location.href='index.html';" style="background-color: #2196f3;"></button> <br>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:400,700" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/i18next.min.js"></script>
<script src="https://unpkg.com/[email protected]/i18nextBrowserLanguageDetector.min.js"></script>
<script src="https://unpkg.com/[email protected]/i18nextXHRBackend.min.js"></script>
<script type="application/javascript" src="ideologies.js"></script>
<script type="application/javascript" src="i18n.js"></script>
<script type="application/javascript" src="themeswitcher.js"></script>
<script type="text/javascript">
themeLoad()
</script>
<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1)
var vars = query.split("&")
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=")
if (pair[0] == variable) {
return pair[1]
}
}
return (NaN);
}
function setBarValue(name, value) {
innerel = document.getElementById(name)
outerel = document.getElementById("bar-" + name)
outerel.style.width = (value + "%")
innerel.innerHTML = (value + "%")
if (innerel.offsetWidth + 20 > outerel.offsetWidth) {
innerel.style.visibility = "hidden"
}
}
function setLabel(val, prefix) {
if (val > 100) {
return ""
} else
if (val > 90) {
return mat_t(prefix + ".0")
} else
if (val > 75) {
return mat_t(prefix + ".1")
} else
if (val > 60) {
return mat_t(prefix + ".2")
} else
if (val >= 40) {
return mat_t(prefix + ".3")
} else
if (val >= 25) {
return mat_t(prefix + ".4")
} else
if (val >= 10) {
return mat_t(prefix + ".5")
} else
if (val >= 0) {
return mat_t(prefix + ".6")
} else {
return ""
}
}
equality = getQueryVariable("e")
peace = getQueryVariable("d")
liberty = getQueryVariable("g")
progress = getQueryVariable("s")
wealth = (100 - equality).toFixed(1)
might = (100 - peace).toFixed(1)
authority = (100 - liberty).toFixed(1)
tradition = (100 - progress).toFixed(1)
setBarValue("equality", equality)
setBarValue("wealth", wealth)
setBarValue("peace", peace)
setBarValue("might", might)
setBarValue("liberty", liberty)
setBarValue("authority", authority)
setBarValue("progress", progress)
setBarValue("tradition", tradition)
ideology = ""
ideodist = Infinity
for (i in ideologies) {
dist = 0
dist += Math.pow(Math.abs(ideologies[i].econ - equality), 2)
dist += Math.pow(Math.abs(ideologies[i].govt - liberty), 2)
dist += Math.pow(Math.abs(ideologies[i].dipl - peace), 1.73856063)
dist += Math.pow(Math.abs(ideologies[i].scty - progress), 1.73856063)
if (dist < ideodist) {
ideology = i
ideodist = dist
}
}
function createImage(src, x, y, w, h) {
img = new Image()
img.src = src
img.onLoad = function() {
ctx.drawImage(img, x, y, w, h)
}
}
window.onload = function() {
i18n_load_ns(["ideologies", "matches", "translation", "values"], ready)
}
function ready() {
if (localStorage.getItem('dark-theme') == 'true') {
var background = "#111";
var text = "#EEE";
}
else {
var background = "#EEE";
var text = "#222";
}
var label = "#EEE";
ideo_t = i18next.getFixedT(null, "ideologies")
mat_t = i18next.getFixedT(null, "matches")
// console.log(ideologies)
document.getElementById("ideology-label").innerHTML = ideo_t(ideology)
document.getElementById("economic-label").innerHTML = setLabel(equality, "econ")
document.getElementById("diplomatic-label").innerHTML = setLabel(peace, "dipl")
document.getElementById("state-label").innerHTML = setLabel(liberty, "govt")
document.getElementById("society-label").innerHTML = setLabel(progress, "scty")
var c = document.getElementById("banner")
var ctx = c.getContext("2d")
ctx.fillStyle = background
ctx.fillRect(0, 0, 800, 650)
ctx.fillStyle = "#EEE"
ctx.font = "14px Montserrat"
ctx.textAlign = "center"
img = document.getElementById("img-equality")
ctx.drawImage(img, 20, 170, 100, 100);
cap = document.getElementById("cap-equality").innerText
ctx.fillText(cap, 70, 260)
img = document.getElementById("img-wealth")
ctx.drawImage(img, 680, 170, 100, 100)
cap = document.getElementById("cap-wealth").innerText
ctx.fillText(cap, 730, 260)
img = document.getElementById("img-might")
ctx.drawImage(img, 20, 290, 100, 100)
cap = document.getElementById("cap-might").innerText
ctx.fillText(cap, 70, 380)
img = document.getElementById("img-peace")
ctx.drawImage(img, 680, 290, 100, 100)
cap = document.getElementById("cap-peace").innerText
ctx.fillText(cap, 730, 380)
img = document.getElementById("img-liberty")
ctx.drawImage(img, 20, 410, 100, 100)
cap = document.getElementById("cap-liberty").innerText
ctx.fillText(cap, 70, 500)
img = document.getElementById("img-authority")
ctx.drawImage(img, 680, 410, 100, 100)
cap = document.getElementById("cap-authority").innerText
ctx.fillText(cap, 730, 500)
img = document.getElementById("img-tradition")
ctx.drawImage(img, 20, 530, 100, 100)
cap = document.getElementById("cap-tradition").innerText
ctx.fillText(cap, 70, 620)
img = document.getElementById("img-progress")
ctx.drawImage(img, 680, 530, 100, 100)
cap = document.getElementById("cap-progress").innerText
ctx.fillText(cap, 730, 620)
ctx.fillStyle = "#222"
ctx.fillRect(120, 180, 560, 80)
ctx.fillRect(120, 300, 560, 80)
ctx.fillRect(120, 420, 560, 80)
ctx.fillRect(120, 540, 560, 80)
ctx.fillStyle = "#f44336"
ctx.fillRect(120, 184, 5.6 * equality - 2, 72)
ctx.fillStyle = "#00897b"
ctx.fillRect(682 - 5.6 * wealth, 184, 5.6 * wealth - 2, 72)
ctx.fillStyle = "#ff9800"
ctx.fillRect(120, 304, 5.6 * might - 2, 72)
ctx.fillStyle = "#03a9f4"
ctx.fillRect(682 - 5.6 * peace, 304, 5.6 * peace - 2, 72)
ctx.fillStyle = "#ffeb3b"
ctx.fillRect(120, 424, 5.6 * liberty - 2, 72)
ctx.fillStyle = "#3f51b5"
ctx.fillRect(682 - 5.6 * authority, 424, 5.6 * authority - 2, 72)
ctx.fillStyle = "#8bc34a"
ctx.fillRect(120, 544, 5.6 * tradition - 2, 72)
ctx.fillStyle = "#9c27b0"
ctx.fillRect(682 - 5.6 * progress, 544, 5.6 * progress - 2, 72)
ctx.fillStyle = text
ctx.font = "700 80px Montserrat"
ctx.textAlign = "left"
ctx.fillText("8values", 20, 90)
ctx.font = "40px Montserrat"
ctx.textAlign = "right"
ctx.fillText(ideo_t(ideology), 780, 87.5)
ctx.font = "50px Montserrat"
ctx.textAlign = "left"
ctx.fillStyle = "#222"
if (equality > 30) {
ctx.fillText(equality + "%", 130, 237.5)
}
if (might > 30) {
ctx.fillText(might + "%", 130, 357.5)
}
if (liberty > 30) {
ctx.fillText(liberty + "%", 130, 477.5)
}
if (tradition > 30) {
ctx.fillText(tradition + "%", 130, 597.5)
}
ctx.textAlign = "right"
if (wealth > 30) {
ctx.fillText(wealth + "%", 670, 237.5)
}
if (peace > 30) {
ctx.fillText(peace + "%", 670, 357.5)
}
if (authority > 30) {
ctx.fillText(authority + "%", 670, 477.5)
}
if (progress > 30) {
ctx.fillText(progress + "%", 670, 597.5)
}
ctx.font = "300 30px Montserrat"
ctx.fillStyle = text
ctx.fillText("8values.mkljczk.pl", 780, 60)
ctx.textAlign = "center"
ctx.fillText(i18next.t("economic_axis") + document.getElementById("economic-label").innerHTML, 400, 175)
ctx.fillText(i18next.t("diplomatic_axis") + document.getElementById("diplomatic-label").innerHTML, 400, 295)
ctx.fillText(i18next.t("civic_axis") + document.getElementById("state-label").innerHTML, 400, 415)
ctx.fillText(i18next.t("societal_axis") + document.getElementById("society-label").innerHTML, 400, 535)
}
function downloadCanvas() {
var downloader = document.createElement("a")
downloader.href = document.getElementById("banner").toDataURL("image/png").replace("image/png", "image/octet-stream")
downloader.download = "results.png"
document.body.appendChild(downloader)
downloader.click()
document.body.removeChild(downloader)
}
</script>
</body>