Skip to content

Commit 910c0f2

Browse files
author
hoang.tran12
committed
add show/hide all btn
1 parent 30bf803 commit 910c0f2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

scripts/_ufs_statistic.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default {
4141
logsPerHour[hour]++;
4242
});
4343

44-
// ======================== Per script name ========================
44+
//#region ======================== Per script name ========================
4545
const scriptNameCount = new Map();
4646
logData.forEach((log) => {
4747
let lastColon = log.lastIndexOf(":");
@@ -95,7 +95,9 @@ export default {
9595
},
9696
});
9797

98-
// ======================== Per script name Per hour ========================
98+
// #endregion
99+
100+
//#region ======================== Per script name Per hour ========================
99101
// Stacked Bar Chart for each script
100102
const scriptNamePerHour_dataset = Array.from(
101103
scriptNameCount.keys()
@@ -111,7 +113,7 @@ export default {
111113
}
112114
});
113115
return {
114-
label: scriptName,
116+
label: scriptName + " (" + scriptNameCount.get(scriptName) + ")",
115117
data,
116118
backgroundColor: randColor(),
117119
stack: "combined",
@@ -144,14 +146,24 @@ export default {
144146
},
145147
});
146148

149+
const toggleBtn = document.createElement("button");
150+
toggleBtn.textContent = "Show/hide all";
151+
toggleBtn.onclick = function () {
152+
scriptNamePerHourChart.data.datasets.forEach(function (ds) {
153+
ds.hidden = !ds.hidden;
154+
});
155+
scriptNamePerHourChart.update();
156+
};
157+
// #endregion
158+
147159
// ======================== Average section ========================
148160
const h1 = document.createElement("h1");
149161
h1.textContent = `${logData.length} logs,
150162
${scriptNameCount.size} scripts used
151163
(~${~~(logData.length / new Date().getHours())} scripts/hour)`;
152164

153165
// ======================== Append Charts ========================
154-
document.body.prepend(h1, canvas, canvas2);
166+
document.body.prepend(h1, toggleBtn, canvas, canvas2);
155167
}
156168
);
157169
})();

0 commit comments

Comments
 (0)