In this question (How to return two customSVGSeries from a single function in clojurescript), I learned how to insert the result of a function creating two customSVGSeries
into an XYPlot
.
Now I want to insert the result of a for
calling that same function:
(into [:> rvis/FlexibleXYPlot {...}]
(doall (for [[id {:keys [x y texto]}] etiquetas]
(crear-etiqueta id x y texto))))
Where etiquetas
is a map with this form:
{:etiqueta-1 {:x 0, :y 0, :texto ["176.6"]}, :etiqueta-2 {:x 1, :y 2, :texto ["Hidrógeno"]}}
and crear-etiqueta
is the function returning two customSGVSeries
. The problem is that using the code above, nothing is shown in the plot.
I uploaded a repo with a MWE: https://github.com/lopezsolerluis/annie-test-for-stackoverflow
Edit
I used the excellent idea of Eugene... it works like a charm!
(into [:> rvis/FlexibleXYPlot {...}]
(mapcat (fn [[id {:keys [x y texto]}]]
(crear-etiqueta id x y texto))
etiquetas))
Expanding on my comment to the question.
Using
for
with two collections:for
will iterate overeqieuetas
and for each item it will destructure it and pass the result intocrear-etiqueta
, which returns a collection.for
then iterates over that collection and assigns the value of each item toseries
. Then the body is finally evaluated, which just returns the value ofseries
.Using the
mapcat
transducer:I won't go into the details of how it works - it's all documented here. I definitely recommend reading that reference in full because of immense usefulness of transducers in many contexts.