Passing the result of a defined macro to a HTML element

99 views
Skip to first unread message

hubertgk

unread,
Oct 26, 2017, 9:59:00 AM10/26/17
to TiddlyWiki
Hi All,

I'm building a goal tracker using two html elements: <progress> and <svg>, the brilliant "rpn" macro by Thomas Elmiger and a simple "DaysDiff" macro that I created myself (it returns the number of days elapsed from a given date).

The <svg> HTML element moves along the x axis and shows the completion rate (using the fields 'tracker_current_value' divided by 'tracker_target_value' multiplied by 520 [px] as "520" is the width that amounts to "100% completion"); the <svg> element moves in parallel to the <progress> element that is measuring the time that's elapsed:

The relevant snippets of code:

<svg><text x=<<ProgressMark>> y=16 fill="red">▼</text></svg>
<progress value=<
<some value>> max=<<max value>>></progress>

The problem that I have is that the <svg> element will not accept the output value of the <<ProgressMark>> macro that I've defined ad-hoc in the tiddler in order to calculate the position of the <svg> element in this way:

\define Proportion()
<$macrocall $name="rpn" a=$(currentVal)$ b=$(targetVal)$ operation="/">
\end

\define ProgressMark()
<$macrocall $name="rpn" a=<<Proportion>> b=520 operation="*">
\end

<$set name=currentVal value={{!!tracker_current_value}}>
<$set name=targetVal value={{!!tracker_target_value}}>

<svg> does accept the value if it's entered as <<SomeMacro 12345>> but not when entered as <$macrocall...> or <<ProgressMark>> even though the <<ProgressMark>> returns the correct value when used outside of the <svg> element.

How can I process the result of the macro? Could I use <$wikify> perhaps? If so, how? I've looked around this group and could not find a satisfactory solution.

Thank you very much for any suggestions!

BJ

unread,
Oct 26, 2017, 11:03:35 AM10/26/17
to TiddlyWiki
You can see what is going on by using the text widget:


<$text text=<<ProgressMark>>/>

gives

<$macrocall $name="rpn" a=<<Proportion>> b=520 operation="*">

- macro are not 'wikified' when used in params

I would use a macro around the svg

\define mymacro(ProgressMark)
<svg><text x=$ProgressMark$ y=16 fill="red">▼</text></svg>
\end

Maybe this is what you are saying....

hubertgk

unread,
Oct 26, 2017, 11:47:01 AM10/26/17
to TiddlyWiki
Thanks for the idea, BJ. Unfortunately, it doesn't seem to work.

When I invoke <<mymacro>> (as below), nothing happens (just a few empty lines are entered). But when I change the x value from x=$ProgressMark$ to, say, x=50 (or any other number), the svg/text element is displayed and moved as expected.

Below is the updated code. Is there any other way I could get $ProgressMark$ evaluated?

\define Proportion()
<$macrocall $name="rpn" a=$(currentVal)$ b=$(targetVal)$ operation="/">
\end

\define ProgressMark()
<$macrocall $name="rpn" a=<<Proportion>> b=520 operation="*">
\end

\define mymacro(ProgressMark)
<svg><text x=$ProgressMark$ y=16 fill="red">▼</text></svg>
\end

<$set name=currentVal value={{!!tracker_current_value}}>
<$set name=targetVal value={{!!tracker_target_value}}>

<<mymacro>>

</$set>

Thank you again!

Mark S.

unread,
Oct 26, 2017, 12:19:49 PM10/26/17
to TiddlyWiki
Try calling the macro like:

<$macrocall $name="mymacro" ProgressMark=<<ProgressMark>>/>

It would be easier to help you if you posted your whole TW or a link to it (maybe on tiddlyspot)

Good luck,
Mark

BJ

unread,
Oct 26, 2017, 12:45:25 PM10/26/17
to TiddlyWiki
more like:

\define m()
<$set name=pmar value=<<rpn a:$(currentVal)$ b:$(targetVal)$ operation:"/">>>
<<mymacro>>
</$set>
\end

\define mymacro()
<svg><text x=<<rpn a:$(pmar)$ b:520 operation:"*">> y=16 fill="red">▼</text></svg>
\end


$set name=currentVal value={{!!tracker_current_value}}>
<$set name=targetVal value={{!!tracker_target_value}}>

<<m>>

</$set>

hubertgk

unread,
Oct 26, 2017, 1:03:11 PM10/26/17
to TiddlyWiki
Thank you both for your input.

BJ -- your code works like a charm, amazing!! Thank you very much! Issue solved :)

Best regards,
Hubert

Thomas Elmiger

unread,
Oct 26, 2017, 2:44:51 PM10/26/17
to TiddlyWiki
Hi Hubert

Would you mind sharing your DaysDiff solution?

(I wrote my own, but it's not as solid as rpn.)

Cheers,
Thomas

Message has been deleted

hubertgk

unread,
Oct 26, 2017, 5:24:12 PM10/26/17
to TiddlyWiki
Sure; I've attached the exported tiddler with the macro (previously I've pasted the full code in here but it appears to have been truncated, so I deleted my post). Please let me know if the macro doesn't work for you.

Any improvement suggestions welcome! :)

Thanks,
Hubert
$___Macros_DaysDiff.js.tid
Reply all
Reply to author
Forward
0 new messages