Hi there fellow Makers !
Creating and using āProgress Barā within Coda has always been one of my favorite trickā¦ The trick that blew my mind when I stumbled upon it, not long after joining this awesome Community !
āProgress Barsā can be used in various ways : you could create HSL Sliders, a visual summary of your day or your budgetsā¦
One thing I never thought about though, was to use a progress bar within the label of a button to show the progress of the buttonās action, while the action runs ā¦ and of course, I was in amazed by seeing it done in @Paul_Danyliuk wonderful Duplicates Finder & Merger Template , not only by the astounding template Paul created but by how this āsmallā visual detail made a huge difference .
In case, youāve missed it or donāt know what Iām talking about, just look at the Find duplicates
button in the gif below
The thing is that I didnāt really see how to create such āProgress Barā ā¦ So yesterday, I finally gave it a try and found a way, which is why Iām here .
But first, letās just talk a little bit aboutā¦
āProgress Barsā in Coda
A progress bar can be created by concatenating X
number of Rectangle()
you would needā¦
Concatenate(Rectangle(),Rectangle()) => Progress Bar
Where the Width
of each Rectangle() is a fraction (%
) of the total Width
of the resulting āProgress Barā .
Just to illustrateā¦
In my 1st Rectangle()
Rectangle(120 * Percent_1/100, 15, Color_1)
120
is the whole Width
of my Progress Bar from which we only keep 40% ā¦
(15
is for the Height
and Color_1
is the color of this rectangle should have)
In my 2nd Rectangle()
Rectangle(120 * Percent_2/100, 15, Color_2)
120 is still the whole Width
of my Progress Bar but this time we keep 60% ā¦
Rectangle 1 + Rectangle 2 => 100% => The Progress Bar
Now that we know thisā¦ hereās how I was able to get a ā¦
Dynamic Progress Bar within the Label of a Button
As I needed an Action
I knew would run for āa whileā I used a canvas button to create all dates for the first quarter (Q1
) of 2022 . (It just adds 1 row/per dates in the table called [2022 - Q1]
)
The Action
Formula looks like this:
Sequence(Date(2022,01,01),Date(2022,03,31)).FormulaMap(
RunActions(
AddRow(
[2022 - Q1],
[2022 - Q1].Date,
CurrentValue
)
)
)
And I ended up with this formula for the Label
of that button:
Sequence(Date(2022,01,01),Date(2022,03,31)).Count().WithName(RowsCount,
SwitchIf(
[2022 - Q1].Count() = 0,
"Create Q1 2022",
[2022 - Q1].Count() >= 1 AND [2022 - Q1].Count() < RowsCount,
Concatenate(
Rectangle(
120 * [2022 - Q1].Count()/RowsCount, 10, "#5cff85"
),
Rectangle(
120 - (120 * [2022 - Q1].Count()/RowsCount), 10, "#a0a0a0"
)
),
[2022 - Q1].Count() = RowsCount,
"Done!"
)
)
The 1st condition in the SwitchIf()
is the text to display when the button has not been clicked yet : and the 3rd condition is to display āDone!
ā when the Action
is completed and the button added all the needed rows .
The 2nd SwitchIf()
condition is where the āmagicā happens but this time, the Width
of each Rectangle()
is determined by āhow complete the Action
isā and in this case, the Action
is complete when the numbers of rows in the table is equal to the numbers of rows I ask the button to add .
[2022 - Q1].Count() = RowsCount
And RowsCount
being:
Sequence(Date(2022,01,01),Date(2022,03,31)).Count()
So in my 1st Rectangle()
Rectangle(
120 * [2022 - Q1].Count()/RowsCount,10,"#5cff85"
)
120
is the whole Width
of the Progress Bar (i.e.: 100%
) from which we only keep the portion equal to [2022 - Q1].Count()/RowsCount
For the 2nd Rectangle()
:
Rectangle(
120 - (120 * [2022 - Q1].Count()/RowsCount), 10, "#a0a0a0"
)
As the Progress Bar needs to reflect an āemptyā state at the beginning of the Action
, then it needs to reflect a āfullerā state as the Action
progresses and as 120
is still the whole Width
of the Progress Bar, the Width
of this rectangle can be determined by 120 - (120 * [2022 - Q1].Count()/RowsCount)
ā¦
And thatās it !
Sorry for the length ā¦ But thanks for reading !
I wonāt be able to thank @Paul_Danyliuk enough for the inspiration, so Iām just going to stick with a simple Thank you so so so very much !!!
Iām pretty sure youāll probably have things to add and/or correct here and there ā¦