This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (48 loc) · 1.59 KB
/
app.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
'use strict';
/**
* Generate an html interval graph from a data array.
*
* EcmaScript 6 version using string literals.
*
* @param graph
* @returns {string}
*/
function intvg(graph) {
let html = "<div class='intvg'>";
graph.forEach(function (bar, index) {
if (bar.length === 6) { // Interval
html += `<div class='bar bar-intv bar${index} ${bar[2]}' `
+ `style='left: ${bar[0]}%; right: ${bar[1]}%' `
+ `data-title='${bar[3]} ➔ ${bar[4]}${bar[5] != null ? ' :' + bar[5] : ''}'></div>`;
}
if (bar.length === 2) { // Single date
html += `<div class='bar bar-date bar${index}' `
+ `style='left: ${bar[0]}%;' data-title='${bar[1]}'></div>`;
}
});
return html;
}
/**
* Generate an html interval graph from a data array.
*
* Boring old EcmaScript 5.1 version.
*
* @param graph
* @returns {string}
*/
function intvgES5(graph) {
var html = "<div class='intvg'>";
graph.forEach(function (bar, index) {
if (bar.length === 6) { // Interval
html += "<div class='bar bar-intv bar" + index
+ "' style='left: " + bar[0] + "%; right: " + bar[1]
+ "%; background-color: " + bar[2] + "' data-title='" + bar[3] + " ➔ "
+ bar[4] + (bar[5] != null ? ' : ' + bar[5] : '') + "'></div>";
}
if (bar.length === 2) { // Single date
html += "<div class='bar bar-date bar${index}' style='left: "
+ bar[0] + "%;' data-title='" + bar[1] + "'></div>";
}
});
return html;
}