-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathprogress-bars-bindings.js
38 lines (37 loc) · 1.14 KB
/
progress-bars-bindings.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
// ProgressBars bindings
Shiny.addCustomMessageHandler("update-progressBar-shinyWidgets", function(
data
) {
var id = data.id;
var el = document.getElementById(id);
var elVal = document.getElementById(id + "-value");
var elTot = document.getElementById(id + "-total");
var elTitle = document.getElementById(id + "-title");
var total = data.total;
var value = Math.round(data.value);
var pct;
if (total > 0) {
pct = Math.round((value / total) * 100);
if (elVal !== null)
elVal.innerText = data.commas ? value.toLocaleString("en-US") : value;
if (elTot !== null)
elTot.innerText = data.commas ? total.toLocaleString("en-US") : total;
value = Math.round((value / total) * 100);
} else {
pct = data.percent > 0 ? data.percent : value;
}
el.style.width = pct + "%";
var txt = el.innerText;
if (txt !== "") {
//value.display_pct !== undefined
el.innerText = value + data.unit_mark;
}
if (data.status !== null) {
el.className = "";
el.classList.add("progress-bar");
el.classList.add("progress-bar-" + data.status);
}
if (data.title !== null) {
elTitle.innerText = data.title;
}
});