DougBurke / hvega

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

how to specify logLevel in toHtml*With #170

Open eflister opened 4 years ago

eflister commented 4 years ago

hi- i don't know anything about javascript, JSON, or Aeson, but i'm trying to set the logLevel option on toHtmlFileWith. everything i try winds up translating to {"logLevel":"vega.Debug"}, whereas i think the right side (and probably the left side) can't have the quotes. i don't see how to properly indicate that.

here's what i've tried:

data VOpt = VOpt {
      logLevel :: String
    } deriving (Generic, Show)
instance J.ToJSON VOpt

opt = Just $ J.toJSON VOpt {logLevel = "vega.Debug"}

obviously that makes strings. to go this route, i think you'd have to export a type for the javascript enum from https://github.com/vega/vega/blob/master/packages/vega-util/src/logger.js#L6 but i'm not sure.

and

opt = Just $ J.object [ "logLevel" J..= ("vega.Debug" :: Text) ] -- following https://github.com/DougBurke/hvega/blob/master/hvega/tools/PlayTutorial.hs#L238

also makes strings.

searching for how to make literal javascript values comes up with Data.Aeson.QQ.Simple, but i can't find any way that compiles that doesn't also quote "vega.Debug"

[aesonQQ| { logLevel : "vega.Debug" } |]

using a bare Int for logLevel does work, but is v dirty :(

eflister commented 4 years ago

great discussion here, and see also https://github.com/bos/aeson/issues/807

DougBurke commented 4 years ago

Sorry, I've had no time to look at @hvega@ recently. I will note that the option support in toHtmlFileWith has only been lightly tested, so there may well be work needed here.

eflister commented 4 years ago

nbd, the Int hack works fine, just wanted to figure out the "right" way -- looks like it is not simple+obvious, so i'm not pushing on it