# Templater Code for Generating Progress Bars
![[Screenshot from 2023-09-11 16-53-55.png|(Progress Bar Example)]]
In order to generate the above progress bars in my daily notes, I use a two part solution.
>[!NOTE] Credit to Kevin Quinn
> The progress bar function code and template is based on work by [Kevin Quinn](https://kevinquinn.fun/blog/get-started-with-obsidian-periodic-notes-and-templater/) with some small changes to wrap the progress bar in a callout and use subscript and superscript to make it more compact and visually appealing.
The first part is a function which I keep in `_attachments/_functions`, it is what builds the progress bar itself and it also determines the default characters, but these can be changed when the function is called.
```javascript
function makeProgressBar(numerator, denominator, size = 50, filledChar = "▰", unFilledChar = "▱", label="", type="NOTE") {
let percentage = numerator / denominator;
let maxBlocks = size;
let numFilled = Math.floor(percentage*maxBlocks)
return `>[!${type}] <strong>${label}</strong> ${Math.floor(percentage*100)}% ⦗<sup>${numerator}</sup>╱<sub>${denominator}</sub>⦘
> ${filledChar.repeat(numFilled)}${unFilledChar.repeat(maxBlocks-numFilled)}`
}
module.exports = makeProgressBar;
```
The second part is a [Templater](https://silentvoid13.github.io/Templater/) template.
The first section is not displayed, but just sets up a helpful variable for use later. In my template, this is at the very top above even the frontmatter.
```templater
<%*
// use the filename instead of anything else so we can easily create daily notes ex post facto
var fileDate = moment(tp.file.title);
-%>
```
Then there's the actual calls to the progress bar function later in the same template file. First for the year, and then for the month. These also define their own function, so there's no reason they couldn't go into their own function file, but since for me these are only used in this one place and they use the `fileDate` variable defined here, it was cleaner to just put them all in one place.
```templater
<%*
function year() {
let dayNum = fileDate.dayOfYear();
// ignore leapyears
tR += tp.user.makeProgressBar(
dayNum, 365, size=33, filledChar = "▰", unFilledChar = "▱", label="YEAR", type="TODO"
);
}
year();
%>
<%*
function month() {
let fileDateNum = fileDate.date();
let numDays = fileDate.daysInMonth();
// ignore leapyears
tR += tp.user.makeProgressBar(
fileDateNum, numDays, size=numDays, filledChar = "▰", unFilledChar = "▱", label="MONTH", type="EXAMPLE"
);
}
month();
%>
```
# Useful Characters for Progress Bars
I went looking around the internet and the Unicode tables for symbols that I thought might be nice to use for progress bars. In my example above, I went with the first set below, but these are just a few possible options, and you can mix and match using different symbols for different progress bars in the same vault!
```
▰▰▰▰▰▰▰▰▰▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱ 30%
▮▮▮▮▮▮▮▮▮▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯▯ 30%
■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□ 30%
█████████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ 30%
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 30%
⬤⬤⬤⬤⬤⬤⬤⬤⬤◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯◯ 30%
⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪ 30%
```
via [[Unicode Characters]]
# Styling Progress Bars
In addition to the callout style progress bars can also be put into a codeblock and then combined with [[CRT Monitor Styled Codeblocks using CSS]].
# See Also
- https://webcache.googleusercontent.com/search?q=cache:BPJTnTsvrrgJ:https://beingpax.medium.com/how-to-create-a-visual-progress-bar-in-obsidian-3016416dad19&cd=13&hl=en&ct=clnk&gl=us