Get basic graph display
This commit is contained in:
8
index.html
Normal file
8
index.html
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="svgContainer" class="my-class"></div>
|
||||||
|
</body>
|
||||||
|
<script src="index.js"></script>
|
||||||
|
</html>
|
||||||
@@ -15,12 +15,17 @@ to generate this file without the comments in this block.
|
|||||||
[ "arrays"
|
[ "arrays"
|
||||||
, "console"
|
, "console"
|
||||||
, "effect"
|
, "effect"
|
||||||
|
, "either"
|
||||||
|
, "exceptions"
|
||||||
, "integers"
|
, "integers"
|
||||||
, "lists"
|
, "lists"
|
||||||
, "maybe"
|
, "maybe"
|
||||||
, "numbers"
|
, "numbers"
|
||||||
, "prelude"
|
, "prelude"
|
||||||
, "tuples"
|
, "tuples"
|
||||||
|
, "web-dom"
|
||||||
|
, "web-dom-parser"
|
||||||
|
, "web-html"
|
||||||
]
|
]
|
||||||
, packages = ./packages.dhall
|
, packages = ./packages.dhall
|
||||||
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
|
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
|
||||||
|
|||||||
@@ -1,10 +1,61 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Data.Maybe (Maybe(..))
|
||||||
|
import Data.Either (Either(..))
|
||||||
import Effect (Effect)
|
import Effect (Effect)
|
||||||
import Effect.Console (log)
|
import Effect.Console (log)
|
||||||
|
import Effect.Class (liftEffect)
|
||||||
|
import Effect.Exception (throw)
|
||||||
import TernaryGraph (ternaryGraph)
|
import TernaryGraph (ternaryGraph)
|
||||||
import Prelude (($), Unit)
|
import Web.DOM.Document (contentType
|
||||||
|
, getElementsByClassName
|
||||||
|
, importNode
|
||||||
|
, toNode
|
||||||
|
, toNonElementParentNode
|
||||||
|
, toParentNode
|
||||||
|
, url
|
||||||
|
)
|
||||||
|
import Web.DOM.DOMParser (makeDOMParser, parseSVGFromString)
|
||||||
|
import Web.DOM.Element (toNode) as Element
|
||||||
|
import Web.DOM.HTMLCollection (length)
|
||||||
|
import Web.DOM.Node (appendChild, nodeName, setTextContent)
|
||||||
|
import Web.DOM.NonElementParentNode (getElementById)
|
||||||
|
import Web.DOM.ParentNode (firstElementChild)
|
||||||
|
import Web.HTML (window)
|
||||||
|
import Web.HTML.HTMLDocument (toDocument)
|
||||||
|
import Web.HTML.HTMLMetaElement (setContent)
|
||||||
|
import Web.HTML.HTMLDivElement (fromElement)
|
||||||
|
import Web.HTML.Window (document)
|
||||||
|
|
||||||
|
-- Consider DOM.Simple.Types
|
||||||
|
|
||||||
main :: Effect Unit
|
main :: Effect Unit
|
||||||
main = do
|
main = do
|
||||||
log $ ternaryGraph 100.0 50.0 50.0 10
|
w <- window
|
||||||
|
d <- document w
|
||||||
|
let dd = toDocument d
|
||||||
|
dUrl <- url dd
|
||||||
|
let containerID = "svgContainer"
|
||||||
|
domParser <- makeDOMParser
|
||||||
|
let mySVG = ternaryGraph 100.0 50.0 50.0 10
|
||||||
|
svgDoc <- parseSVGFromString mySVG domParser
|
||||||
|
maybeElement <- getElementById containerID $ toNonElementParentNode dd
|
||||||
|
case maybeElement of
|
||||||
|
Nothing -> do
|
||||||
|
throw $ "Unable to find " <> containerID
|
||||||
|
Just e -> do
|
||||||
|
let node = Element.toNode e
|
||||||
|
case svgDoc of
|
||||||
|
Left error -> throw error
|
||||||
|
Right doc -> do
|
||||||
|
log $ nodeName (toNode doc)
|
||||||
|
elMay <- firstElementChild $ toParentNode doc
|
||||||
|
case elMay of
|
||||||
|
Nothing -> throw "oops"
|
||||||
|
Just el -> do
|
||||||
|
let svgNode = Element.toNode el
|
||||||
|
log $ nodeName svgNode
|
||||||
|
newNode <- importNode svgNode true dd
|
||||||
|
appendChild newNode node
|
||||||
|
|||||||
Reference in New Issue
Block a user