Merge pull request #781 from aemi-dev/hackathon-2021

Hackathon 2021 - Timeline - Minor Edits & Comments
pull/1/head
ansuz 3 years ago committed by GitHub
commit ed8c2f4319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1922,18 +1922,19 @@ define([
}; };
var makeTimeline = APP.makeTimeline = function (answers) { var makeTimeline = APP.makeTimeline = function (answers) {
// Here for mockup purpose
// Randomly changing date of answers to get a more realistic example of timeline
Object.keys(answers).forEach(function (k) { // XXX Object.keys(answers).forEach(function (k) { // XXX
//console.log(answers[k].time);
answers[k].time += Math.floor(Math.random() * 10 - 5) * 24 * 3600 * 1000; answers[k].time += Math.floor(Math.random() * 10 - 5) * 24 * 3600 * 1000;
//console.log(answers[k].time);
}); });
var answersByTime = {}; var answersByTime = {};
Object.keys(answers).forEach(function (curve) { Object.keys(answers).forEach(function (curve) {
var obj = answers[curve]; var obj = answers[curve];
// Used to get rid of the milliseconds and get unique date to map counts
var key = new Date(obj.time).toLocaleDateString(); var key = new Date(obj.time).toLocaleDateString();
if (!answersByTime[key]) { if (!answersByTime[key]) {
// Original time kept to ensure a good sort order later
answersByTime[key] = {date: obj.time, count: 1}; answersByTime[key] = {date: obj.time, count: 1};
} else { } else {
answersByTime[key].count++; answersByTime[key].count++;
@ -1956,14 +1957,12 @@ define([
Object.keys(answersByTime).forEach(function (date) { Object.keys(answersByTime).forEach(function (date) {
var answer = answersByTime[date]; var answer = answersByTime[date];
answer.percent = answer.count / maxCount; answer.percent = answer.count / maxCount;
// Chose an empty string rather than 0 to avoid in the next dev step
// to provide the correspondant chart bar with an unecessary tooltip
answer.count = answer.count || ""; // 0 ? answer.count = answer.count || ""; // 0 ?
}); });
/*
console.log(answersByTime);
console.log(dates);
console.log('done'); // TODO: Populate the date list with dates which have no answers to get every day between to dates which have ones
*/
return Charts.table(h('tbody',dates.map(function (date) { return Charts.table(h('tbody',dates.map(function (date) {
var count = answersByTime[date].count; var count = answersByTime[date].count;

Loading…
Cancel
Save