gicentre / elm-vegalite

Elm - Vega-Lite Integration for functional declarative visualization
BSD 3-Clause "New" or "Revised" License
73 stars 11 forks source link

how to handle 'text: [...]' setting? #31

Closed DougBurke closed 4 years ago

DougBurke commented 4 years ago

I was going through the Vega-Lite examples for hvega, and came to https://vega.github.io/vega-lite/examples/concat_layer_voyager_result.html which has this construct (the ability for text to take an array of strings looks to have been added somewhere in v4):

          "mark": {
            "type": "text",
            "align": "right",
            "style": "arrow-label",
            "text": ["Polestar", "More Valuable"]
          },

My current approach in hvega is to add an equivalent to maText but for lists - e.g.

maTexts : List String -> MarkProperty

An alternative was to make maText accept a list rather than a scalar (I'm not sure which is better).

I know you have a version of this visualization in your gallery code, but it looks like it requires a lot more work to get a similar display than supporting lists for text.

I haven't checked to see if any of the other mark properties can now take lists. I guess I should.

jwoLondon commented 4 years ago

Thanks for raising this. In order to avoid inflating the API, I have simply allowed maText to accept multi-line strings (or strings with '\n' within them). This is consistent with multi-line text handling elsewhere (mStr, title etc.).

I've updated the Likert example to reflect this.

For anyone wishing to allow input of string lists, it would be a simple case of creating a helper function List.intersperse "\n" >> String.concat