DougBurke / hvega

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

Can we make it easy to generate common plot types? #189

Open DougBurke opened 3 years ago

DougBurke commented 3 years ago

As suggested by @ysangkok in the New-York Haskell Meetup Co-Hack, can we provide "simple" routines to set up basic operations - e.g. scatter plot?

One issue is that it's hard to extend since we can create a VegaLite type but then can't deconstruct it to extend/add/adjust plot options (given that VegaLite is just Aeson's Value rather than a hvega type).

ysangkok commented 3 years ago

I have been playing with VegaLite and I am still wondering how I'd input Haskell lists of numbers into the system. I saw dataFromColumns, and its example:

dataFromColumns [ Parse [ ( "Year", FoDate "%Y" ) ] ]
  . dataColumn "Animal" (Strings [ "Fish", "Dog", "Cat" ])
  . dataColumn "Age" (Numbers [ 28, 12, 6 ])
  . dataColumn "Year" (Strings [ "2010", "2014", "2015" ])

But this expression yields a function [DataColumn] -> [DataColumn]. I fail to get the intuition of this example, since each dataColumn call seems to tack on data, but doesn't actually change the type. Furthermore, I can't stuff this value into a place where I'd have a dataFromUrl. I think many users of the library will be plotting generated data, so I think an easy interface should allow for ingesting matrices of N dimensions easily without requiring having them in JSON.

Looking at the example in dataFromJson:

dataFromUrl "data/weather.csv" [ Parse [ ( "date", FoDate "%Y-%m-%d %H:%M" ) ] ]

This example indeed has type Data. So wouldn't it be more intuitive if the other dataFromX functions also had examples with the Data type?