diff --git a/index.html b/index.html index 55ed958..683546d 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,9 @@ -
+ ticks: + +
\ No newline at end of file diff --git a/src/Main.purs b/src/Main.purs index 0273ab8..1a86053 100644 --- a/src/Main.purs +++ b/src/Main.purs @@ -19,14 +19,11 @@ import Web.DOM.Document (contentType ) 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 @@ -36,26 +33,24 @@ main = do 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 + + let containerID = "svg-container" 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 + node <- case maybeElement of + Nothing -> throw $ "Unable to find " <> containerID + Just e -> pure $ Element.toNode e + + let mySVG = ternaryGraph 100.0 50.0 50.0 10 + svgDocMay <- parseSVGFromString mySVG domParser + svgDoc <- case svgDocMay of + Left error -> throw error + Right doc -> pure doc + + elMay <- firstElementChild $ toParentNode svgDoc + svgNode <- case elMay of + Nothing -> throw "no child in svg doc" + Just el -> pure $ Element.toNode el + + newNode <- importNode svgNode true dd + appendChild newNode node