v1.0: First production version
This first version allows login of pre-existing users, creation and update of truths by admins, vote on the truths by users, their display as well as a simple graph for the vote results. Everything persisting in a SQLite database.
This commit is contained in:
commit
9911895b5b
22 changed files with 4790 additions and 0 deletions
85
static_files/vote_chart.js
Normal file
85
static_files/vote_chart.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
|
||||
// const names = ["Bystus", "Dory", "Fen", "Lucky", "Nico", "Peran", "trot"]
|
||||
//
|
||||
//
|
||||
// let data = [];
|
||||
// for (let i = 0; i < 7; i++) {
|
||||
// data.push({
|
||||
// parsing: true,
|
||||
// label: names[i],
|
||||
// data: Array.from(keys, () => Math.round(Math.random()*1.33))})
|
||||
// }
|
||||
async function main() {
|
||||
const vote_response = await fetch(document.URL+"/votes");
|
||||
if (!vote_response.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
const keys = ["Vérité 1", "Vérité 2", "Vérité 3", "Vérité 4", "Vérité 5", "Vérité 6", "Vérité 7"]
|
||||
let datasets = []
|
||||
|
||||
try {
|
||||
const vote_data = (await vote_response.json()).votes;
|
||||
for (let player in vote_data) {
|
||||
datasets.push({
|
||||
parsing: true,
|
||||
label: player,
|
||||
data: vote_data[player],
|
||||
})
|
||||
}
|
||||
console.log(datasets)
|
||||
} catch (error) {
|
||||
console.error("Failed to parse vote data : \n\t" + error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const chart_canvas = document.getElementById("vote_chart")
|
||||
let chart
|
||||
function create_chart(keys, data) {
|
||||
let main_axis;
|
||||
let aspect_ratio;
|
||||
if (window.innerWidth > window.innerHeight) {
|
||||
main_axis = 'x'
|
||||
aspect_ratio = 2
|
||||
} else {
|
||||
main_axis = 'y'
|
||||
aspect_ratio = 0.5
|
||||
}
|
||||
|
||||
if ( chart ) {
|
||||
chart.destroy()
|
||||
}
|
||||
|
||||
chart = new Chart(chart_canvas, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: keys,
|
||||
datasets: data,
|
||||
},
|
||||
options: {
|
||||
aspectRatio: aspect_ratio,
|
||||
indexAxis: main_axis,
|
||||
grouped: true,
|
||||
scales: {
|
||||
x: {
|
||||
stacked: true
|
||||
},
|
||||
y: {
|
||||
stacked: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function update_chart_ratio(_) {
|
||||
create_chart(keys, datasets)
|
||||
}
|
||||
|
||||
const orientation_query = matchMedia("screen and (orientation:portrait)");
|
||||
orientation_query.onchange = update_chart_ratio
|
||||
|
||||
create_chart(keys, datasets)
|
||||
}
|
||||
|
||||
main().then()
|
Loading…
Add table
Add a link
Reference in a new issue