packages feed

ihaskell-hvega (empty) → 0.1.0.0

raw patch · 5 files changed

+145/−0 lines, 5 filesdep +aesondep +basedep +hvegasetup-changed

Dependencies added: aeson, base, hvega, ihaskell, text

Files

+ IHaskell/Display/Hvega.hs view
@@ -0,0 +1,75 @@+{-# LANGUAGE OverloadedStrings #-}++module IHaskell.Display.Hvega where++import qualified Data.Text.Lazy as LT++import Data.Aeson.Text (encodeToLazyText)+import Data.Monoid ((<>))++import Graphics.Vega.VegaLite (VegaLite, fromVL)++import IHaskell.Display (IHaskellDisplay(..), Display(..), javascript)+++-- ^ Use <https://vega.github.io/vega-lite/usage/embed.html Vega-Embed>+--   to include the Vega-Lite visualization in an IHaskell notebook.+--+--   There is currently no way to pass+--   <https://github.com/vega/vega-embed#options options>+--   to the @vegaEmbed@ call.+--+--   Note that local file access is __not__ guaranteed to work - e.g.+--   @dataFromUrl@ where the file name refers to a local file -+--   since the JavaScript @fs@ module may not be loaded.+--+instance IHaskellDisplay VegaLite where+  display vl = +  +    let -- Note: need to look in the package.json files for these packages+        -- to find the "full name" (the contents of the jsdelivr key),+        -- since requirejs does seem to like appending .js to everything.+        --+        jsname n v = "'https://cdn.jsdelivr.net/npm/"+                     <> n+                     <> "@" <> v+                     <> "/build/"+                     <> n <> ".min'"++        -- Should the config be set on require or requirejs?+        --+        -- These versions are known to work; later versions+        -- do not work but I have not tried to work out the+        -- latest version that does work.+        --+        config = "requirejs({paths:{vg:" <> jsname "vega" "3.2.1"+                 <> ",vl:" <> jsname "vega-lite" "2.3.0"+                 <> ",vge:" <> jsname "vega-embed" "3.5.2"+                 <> "},shim:{vge:{deps:['vg.global','vl.global']}"+                 <> ",vl:{deps:['vg']}"+                 <> "}});"+                 <> "define('vg.global',['vg'],function(g){window.vega = g;});"+                 <> "define('vl.global',['vl'],function(g){window.vl = g;});"++        -- rely on the element variable being set up; it appears to be an array+        -- so use the first element to add the div to.+        makeDiv = "var ndiv = document.createElement('div');"+                   <> "ndiv.innerHTML = "+                   <> "'Awesome Vega-Lite visualization to appear here';"+                   <> "element[0].appendChild(ndiv);"+                +        js = LT.unpack (encodeToLazyText (fromVL vl))++        -- Use the div element we have just created for the plot.+        -- More options could be passed to vegaEmbed.+        --+        plot = "require(['vge'],function(vegaEmbed){"+               <> "vegaEmbed(ndiv," <> js <> ").then("+               <> "function (result) { console.log(result); }).catch("+               <> "function (error) { ndiv.innerHTML = "+               <> "'There was an error: ' + error; });"+               <> "});"+                      +        ds = [javascript (config <> makeDiv <> plot)]+             +    in pure (Display ds)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Author name here nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,8 @@+# ihaskell-hvega++View [Vega-Lite](https://vega.github.io/vega-lite/) visualizations+created by the `hvega` package in IHaskell notebooks. It relies on+[Vega-Embed](https://vega.github.io/vega-lite/usage/embed.html) to+do the hard work of parsing and displaying the Vega Lite specification.++This code is released under the BSD3 license.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ihaskell-hvega.cabal view
@@ -0,0 +1,30 @@+name:                ihaskell-hvega+version:             0.1.0.0+synopsis:            IHaskell display instance for hvega types.+description:         Support Vega-Lite visualizations in IHaskell notebooks.+homepage:            https://github.com/githubuser/ihaskell-hvega#readme+license:             BSD3+license-file:        LICENSE+author:              Douglas Burke+maintainer:          dburke.gw@gmail.com+copyright:           2018 Douglas Burke+category:            Development+build-type:          Simple+extra-source-files:  README.md+cabal-version:       >=1.10++library+  hs-source-dirs:      .+  exposed-modules:     IHaskell.Display.Hvega+  build-depends:       base >= 4.7 && < 5+                     , aeson >= 0.11 && < 1.3+                     , hvega < 0.2+                     , ihaskell >= 0.6.2+                     , text == 1.2.*+                     +  default-language:    Haskell2010+  ghc-options:         -Wall -fno-warn-orphans++source-repository head+  type:     git+  location: https://github.com/githubuser/ihaskell-hvega