Fork me on GitHub
#reveal
<
2020-09-21
>
wilkerlucio17:09:15

hello, Im using the bar chart to try a chart with multiple series, my data looks like this:

{:impl-a {0 25.299999862909317,
           7 19.39000003039837,
           1 21.464999997988343,
           4 20.795000018551946,
           15 20.76500002294779,
           13 21.65500004775822,
           6 19.154999870806932,
           17 20.804999861866236,
           3 19.88500007428229,
           12 23.38000014424324,
           2 21.63999993354082,
           19 23.924999870359898,
           11 22.635000059381127,
           9 25.545000098645687,
           5 24.910000152885914,
           14 19.585000118240714,
           16 20.885000005364418,
           10 20.819999976083636,
           18 20.195000106468797,
           8 19.580000080168247},
 :impl-b {0 4.239999921992421,
         7 17.385000130161643,
         1 6.2200000975281,
         4 9.77999996393919,
         15 29.254999943077564,
         13 25.88499989360571,
         6 12.69999984651804,
         17 38.07000000961125,
         3 7.009999826550484,
         12 24.105000076815486,
         2 5.545000080019236,
         19 41.569999884814024,
         11 23.08499999344349,
         9 24.960000067949295,
         5 12.189999921247363,
         14 29.519999865442514,
         16 35.47999984584749,
         10 20.249999826774,
         18 40.43000005185604,
         8 22.23999984562397}}

wilkerlucio17:09:52

so when I plot it looks like this:

wilkerlucio17:09:34

but in this chart, the order of the groups is important (I want it to go from 0 to 18, in order), is there any way to control the order of the series?

vlaaad17:09:09

Hmm, sorted maps worked for me:

{:a (into (sorted-map) (map #(vector % (rand-int 100))) (range 10))
 :b (into (sorted-map) (map #(vector % (rand-int 100))) (range 10))}

wilkerlucio17:09:45

@vlaaad the problem to me is that I'm generating the data in CLJS and just copying over to a Reveal window (since I can't use cljs directly), and if I remember correctly, sorted-maps will sort based on values, not on keys, or I'm confusing things?

wilkerlucio17:09:21

what you think about having some extra data to control the order? so it could be made explicit on the data itself

vlaaad17:09:40

hmm, I think sorting chart series/keys makes sense anyway.. I'll think about that, thank you for input!

vlaaad17:09:39

Also, if the order matters, wouldn't it make more sense to use lists with line chart instead of maps?

vlaaad17:09:43

e.g.

{:a (repeatedly 18 #(rand-int 100))
 :b (repeatedly 18 #(rand-int 100))}

wilkerlucio17:09:00

maybe, I didn't knew about this option, let me try 🙂

seancorfield17:09:17

sorted-map works on the keys, not values (I just tried it in a REPL)

😄 3
vlaaad17:09:24

sorted-map sorts on keys!

😄 3
wilkerlucio17:09:16

@vlaaad yup, using as a vector there works great!

👍 3