Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```dataviewjs
- // - sum of all evergreen notes
- const qrySum = await dv.query(`
- TABLE WITHOUT ID
- length(rows.file.link) as L
- FROM #evergreen
- FLATTEN L
- GROUP BY true
- `)
- const sum = qrySum.value.values;
- // - get sum of evergreen notes by topic
- const qryList = await dv.query(`
- TABLE length(rows.file.link) as Count
- FROM #evergreen
- GROUP BY topic as Topic
- SORT topic
- `)
- // - calculate percentage for each topic
- // headers
- qryList.value.headers.push("Percentage")
- qryList.value.headers.push("Graphical")
- for (let r of qryList.value.values) {
- // Percentage
- let percentOfQty = Math.round(r[1] * 100 / sum * 10) / 10
- percentOfQty = percentOfQty.toFixed(1)
- r.push(percentOfQty);
- // Progress
- let progressBar = '<progress value="' + percentOfQty + '" max="100"></progress>'
- r.push(progressBar);
- };
- removeColumn('Count');
- removeColumn('Percentage')
- dv.table(qryList.value.headers, qryList.value.values)
- /* -------------------------------------- */
- function removeColumn(col) {
- const index = qryList.value.headers.indexOf(col);
- if (index > -1) {
- qryList.value.headers.splice(index, 1);
- for (let r of qryList.value.values) {
- r.splice(index, 1)
- }
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement