Note: My original approach was broken.
Broken original approach
\procedure get-point(idx)
<$let
x={{{ [<idx>addprefix[data]] }}}
y={{{ [<idx>addprefix[score]] }}}
><$text text={{{ [get<x>] [get<y>] +[join[,]]}}} /></$let>
\end
<$list
filter="[<currentTiddler>fields[]prefix[data]removeprefix[data]]"
variable="idx"
join=","
><$transclude
$variable="get-point"
idx=<<idx>>
/></$list>
In a tiddler with these fields:
data1: 125
data2: 138
data3: 146
data4: 161
score1: 5864
score2: 6127
score3: 6430
score4: 7396
It gives this result:
125,5864,138,6127,146,6430,161,7396
My Graph.json (605 Bytes)
It does depend on your fields being well-structured, with dataN
and scoreN
always coming in pairs. It also works only on the data in the current tiddler. If you wanted to fetch the data from a different one, it would need some work.
Here’s a fixed version:
\procedure get-points(tid)
\whitespace trim
\procedure get-point(idx, tid)
<$let
x={{{ [<idx>addprefix[data]] }}}
y={{{ [<idx>addprefix[score]] }}}
><$text text={{{ [<tid>get<x>] [<tid>get<y>] +[join[,]]}}} /></$let>
\end get-point
<$list
filter="[<tid>fields[]prefix[data]removeprefix[data]]"
variable="idx"
join=","
><$transclude
$variable="get-point"
tid=<<tid>>
idx=<<idx>>
/></$list>
\end get-points
We call it like this, using the points from the tiddler “My Graph”:
<<get-points "My Graph">>
If “My Graph” has these fields:
data1: 125
data2: 138
data3: 146
data4: 161
score1: 5864
score2: 6127
score3: 6430
score4: 7396
It gives this result:
125,5864,138,6127,146,6430,161,7396
My Graph.json (735 Bytes)
This depends on your fields being well-structured, with dataN
and scoreN
always coming in pairs.
I would love to hear of simplifications. I feel as though there should be some approach that does the extraction in a single filter, but I haven’t figured out how.