DougBurke / hvega

Create Vega-Lite visualizations from Haskell.
BSD 3-Clause "New" or "Revised" License
52 stars 12 forks source link

Question: What is the simplest way to build a [DataRow] ? #169

Open MMesch opened 4 years ago

MMesch commented 4 years ago

This is a question rather than a bug. I am a happy hvega user but my code usually gets bloated up at the point where I need to convert some Haskell data type into an HVega datatype.

dataFromRows expects a [DataRow] which can be constructed with dataRow. However, this constructor doesn't have the typical form [(FieldName, DataValue)] -> [DataRow] that one would expect and that could be used with a simple dataRow <$> myrows to convert a whole list of fields with associated value into a list of DataRows.

I don't understand the point of this other constructor yet. Yes it allows us to concatenate lists of DataRows but wouldn't we be able to do this with simple list operators anyway?

What are the objections against simple dataRow :: [(FieldName, DataValue)] -> [DataRow] and dataColumn :: FieldName -> [DataValue] -> [DataRow] constructors that I would expect?

DougBurke commented 4 years ago

So, this is code I based on the Elm Vega Lite version and haven't really looked at since (to see if it can be made "more" haskelly, to abuse a term or two).

I'm not sure if this helps you, but you can see some examples in the tests - e.g. https://github.com/DougBurke/hvega/blob/master/hvega/tests/DataTests.hs and https://github.com/DougBurke/hvega/blob/master/hvega/tests/Gallery/Bar.hs