DougBurke / hvega

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

javascript does not run: i is undefined #183

Open flip111 opened 3 years ago

flip111 commented 3 years ago

I have this code, made with stack new myproject rio https://github.com/commercialhaskell/stack-templates/blob/master/rio.hsfiles

{-# LANGUAGE OverloadedStrings #-}
module Run (run) where

import Import
import Graphics.Vega.VegaLite

run :: RIO App ()
run = do
  logInfo "We're inside the application!"
  liftIO $ toHtmlFile "test.html" plot

plot :: VegaLite
plot =
  let data_rows = dataFromRows [ Parse [ ( "Year", FoDate "%Y" ) ] ]
                . dataRow [ ( "name", Str "Ticket 1" ), ( "storypoints", Number 6 ), ( "timelogged", Number 20 )]
                . dataRow [ ( "name", Str "Ticket 2" ), ( "storypoints", Number 2 ), ( "timelogged", Number 20 )]
                . dataRow [ ( "name", Str "Ticket 3" ), ( "storypoints", Number 5 ), ( "timelogged", Number 20 )]

      enc = encoding
              . position X [PName "velocity", PmType Quantitative, PNoTitle]
              . position Y [PName "name", PmType Nominal, PNoTitle, PAxis [ AxOffset 5, AxTicks False, AxDomain False, AxOrient SRight], PSort [ByChannel ChX]]
              . position X [PDatum $ Number 7]

      tsfr = transform
              . calculateAs "datum.timelogged / datum.storypoints" "velocity"

  in toVegaLite [ data_rows []
                , enc []
                , tsfr []
                , mark Bar []
                ]

When i open the resulting html page and look in the webdeveloper tools i see

TypeError: "i is undefined"
    lite 4:1
    lite 4:1
    lite 4:1
    lite 4:1
    lite 4:1
    lite 4:1
    lite 4:1
    lite 4:1
    lite 4:1
    lite https://cdn.jsdelivr.net/npm/vega-embed:26
    tn https://cdn.jsdelivr.net/npm/vega-embed:26
    s https://cdn.jsdelivr.net/npm/vega-embed:1
    s https://cdn.jsdelivr.net/npm/vega-embed:1
    s https://cdn.jsdelivr.net/npm/vega-embed:1
    s https://cdn.jsdelivr.net/npm/vega-embed:1
    tn https://cdn.jsdelivr.net/npm/vega-embed:26
    Kr https://cdn.jsdelivr.net/npm/vega-embed:26
    s https://cdn.jsdelivr.net/npm/vega-embed:1
    s https://cdn.jsdelivr.net/npm/vega-embed:1
    a https://cdn.jsdelivr.net/npm/vega-embed:1

Did something escape from the haskell type safety here?

Maybe would be nice to have a debug html with not minimized javascript file or something.

flip111 commented 3 years ago

When i replace js dependencies from

  <script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
  <script src="https://cdn.jsdelivr.net/npm/vega-lite@4"></script>
  <script src="https://cdn.jsdelivr.net/npm/vega-embed"></script>

to

  <script src="https://cdn.jsdelivr.net/npm/vega@5.19.1/build/vega.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vega-lite@4.17.0/build/vega-lite.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/vega-embed@6.15.1/build/vega-embed.js"></script>

i get a different error (scary !!)

TypeError: "fieldDefToSortBy is undefined"
    lite 4.17.0/build/vega-lite.js:19106
    lite 4.17.0/build/vega-lite.js:18939
    lite 4.17.0/build/vega-lite.js:18870
    lite 4.17.0/build/vega-lite.js:18745
    lite 4.17.0/build/vega-lite.js:18735
    lite 4.17.0/build/vega-lite.js:20361
    lite 4.17.0/build/vega-lite.js:20655
    lite 4.17.0/build/vega-lite.js:20639
    lite 4.17.0/build/vega-lite.js:25305
    embed 6.15.1/build/vega-embed.js:4922
    embed 6.15.1/build/vega-embed.js:5108
    embed 6.15.1/build/vega-embed.js:215
    embed 6.15.1/build/vega-embed.js:196
    embed 6.15.1/build/vega-embed.js:189
    embed 6.15.1/build/vega-embed.js:185
    embed 6.15.1/build/vega-embed.js:5073
    embed 6.15.1/build/vega-embed.js:5020
    embed 6.15.1/build/vega-embed.js:215
    embed 6.15.1/build/vega-embed.js:196
    embed 6.15.1/build/vega-embed.js:186
flip111 commented 3 years ago

When i copy paste the json to vega editor https://vega.github.io/editor/#/url/vega-lite/N4IgLgTghgdgzgMwPYQLYgFwG1RTpkANwFMAbJAYwEswBPEAGhAqlIoFdSoxiCATbu1QA6MFVRkkAcynE+AAgD08gWCHC4YFLQAOSKjDD4AvgF0mqKBADWBAEZXGIVVEyhCrdsXzZQm7XoGRpgAbEwwUBIEACpUFNbEYPIAjE5iEuQycpgATAAMxgx+WhC6+oY+OeGRvBggsfGJ8jlp4pJZfLkFRSD+pYEVmACs1VF1DQlJAMytGdKynRj5ZkzIaNxuIDpWcLWgAJrEjnWqxBgA5ACk++cgxvdMACRwFAAWxJYEr2BgOnAYikUJCkUGEUhor3YdmEVCQihe70sQOIIIAtKQaMQgQAWYQAKzgSBgTmIMAoSD4BikmwAHptVEJMAB2QogegYUAIKhkRYgCJRJiEiBgTak8mUmDUup01liMCkWowTikJh0HS1PlIVAGVhOKA0qg+UBIBAIXYijAjZxaqAGTAIVi7JgobmGAgQKhSb6teI+B2kXb3e5AA

flip111 commented 3 years ago

Found the bug in my program position X [PDatum $ Number 7] to position X2 [PDatum $ Number 7]. I will leave issue open see if some type safety could be added.