Where We Left Off
Last time, we created this chunk of code for % value, which returns the number of habits checked times 20.
((prop("Daily Workout") ? 1 : 0) + (prop("Read By 11:30 PM") ? 1 : 0) + (prop("Wake Up 9 AM") ? 1 : 0) + (prop("Finish Daily Tracker") ? 1 : 0) + (prop("Complete All Tasks") ? 1 : 0)) * 20
Finishing the Progress Bar
To finish this progress bar, we will need the format and slice property commands.
Format
This command is simple & easy, format just converts numbers & other non-word/strings to words/strings.
To print the 20 on the right of the progress bar, Notion doesn’t let you directly print number properties like % value, so you have to convert it to a word/string form first.
You literally do this just by putting the property inside a format command, which is shown below.
format(prop("% value"))
To get the percentage sign on the very right, we just add it as another string.
format(prop("% value")) + "%"
Slice
Slice takes a phrase or word and slices it, keeping a smaller part of it.
If I was trying to slice the word “supercharger”, each letter would be associated with a number to track its location, increasing from left to right.
supercharger
s=0, u=1, p=2, e=3, and so on…
Instead of marking 1-10 from left to right though, we start at 0 instead when using slice commands in code.
If I wanted to cut down “supercharger” into “super”, I would use the syntax below.
slice("supercharger", 0, 5)
On the very left, I would put my word in quotations. In the middle, I choose the first letter of the phrase I’m keeping, which is s. On the very right, I choose c, which is the first letter of the part I want to cut out (charger).
Recall that we currently have a property called % value, that is tracking the percent of completed checkboxes. The code below tracks the % of checked habits.
slice("■■■■■■■■■■", 0, prop("% value") * 0.1)
Inside the quotation marks, there are 10 filled boxes, each of which is representing 10%. So let’s say we have 20% of our habits checked, we will get 2 boxes. This is because (prop("% value") * 0.1)
is taking the value of 20 and multiplying it by 0.1, to get 2.
As a result, we get: ■■
Our next step is to get: ■■□□□□□□□□
To do so, we need to track the % of unchecked habits on the right.
slice("□□□□□□□□□□", 0, 10 - round(prop("% value")) * 0.1)
There are only 2 differences this time. Firstly we replace the 10 filled boxes with empty ones. Next, for where the slice ends, we take 10 and subtract it from the number of filled boxes. Since we had 2 filled boxes, we would get 8 unfilled.
This returns: □□□□□□□□
And voila, if we combine them, we get
slice("■■■■■■■■■■", 0, round(prop("% value")) * 0.1) + slice("□□□□□□□□□□", 0, 10 - round(prop("% value")) * 0.1)
This puts the filled boxes on the left, and unfilled on the right, returning: ■■□□□□□□□□
Putting it Together
All we have to do now is to add the format snippet we had above.
slice("■■■■■■■■■■", 0, round(prop("% value")) * 0.1) + slice("□□□□□□□□□□", 0, 10 - round(prop("% value")) * 0.1) + " " + format(prop("% value")) + "%"
Firstly we just add a little space between the progress bar and the format snippet with “ “. After we add the format snippet, all this does is add “20%” to the right.
Before we had: ■■□□□□□□□□
Our final result: ■■□□□□□□□□
20%
Feel free to not use boxes and customize the formulas in any way you want, with this basic foundation, you can make any type of progress bar you want.
Conclusion
Now if people ask if you code, you do 😎.
If you enjoyed this issue, feel free to hit the heart button. If you’re new and enjoyed this issue, feel free to hit the subscribe button below and get a free template of my base all-in-one Notion workspace. Thanks again for everyone’s support; it inspires me every day to write!