Skip to content

Update for compatibility with purescript-dotlang #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/Graphics/Graphviz.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Graphics.Graphviz (renderToJson, renderToSvg, renderReprSvg, Engine(..)) where

import Data.DotLang (class DotLang, class GraphRepr, toGraph, toText)
import Data.DotLang (class GraphRepr, toGraph)
import Data.DotLang.Class (class DotLang, toText)
import Data.Function (($))
import Data.Function.Uncurried (Fn4, runFn4)
import Data.Show (class Show, show)
Expand Down Expand Up @@ -31,5 +32,5 @@ renderToJson e a = runFn4 viz_internal (toText a) "json" (show e) 1
renderToSvg :: ∀a. DotLang a => Engine -> a -> String
renderToSvg e a = runFn4 viz_internal (toText a) "svg" (show e) 1

renderToXDot :: ∀a. DotLang a => Engine → a → String
renderToXDot e a = runFn4 viz_internal (toText a) "xdot" (show e) 1
renderToXDot :: ∀a. DotLang a => Engine → a → String
renderToXDot e a = runFn4 viz_internal (toText a) "xdot" (show e) 1
18 changes: 11 additions & 7 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
module Test.Main where

import Prelude

import Color.Scheme.MaterialDesign (red)
import Data.DotLang (Attr(..), Definition(..), FillStyle(..), Graph(..), ShapeType(..), node, (==>))
import Effect (Effect)
import Data.DotLang (Definition(..), EdgeType(..), Graph(..), edge, node, (==>))
import Data.DotLang.Attr (FillStyle(..))
import Data.DotLang.Attr.Edge as Edge
import Data.DotLang.Attr.Node (Attr(..), ShapeType(..))
import Data.DotLang.Attr.Node as Node
import Graphics.Graphviz (Engine(..), renderToSvg)
import Test.Unit (suite, test)
import Node.FS.Aff (writeTextFile)
import Node.Encoding (Encoding(..))
import Node.FS.Aff (writeTextFile)
import Test.Unit (suite, test)
import Test.Unit.Assert (equal)
import Test.Unit.Main (runTest)

main = runTest do
suite "Graphviz" do
test "simple" do
let g = DiGraph [
node "a" [ Shape Diamond, Style Filled, FillColor red ],
node "a" [ Shape Diamond, Style Filled, Node.FillColor red ],
node "b" [],
"a" ==> "b",
"a" ==> "d",
edge Forward "a" "d" [ Edge.Color red, Edge.PenWidth 3.0 ],
Subgraph [
node "d" []
]
]
let rendered = renderToSvg Dot g
writeTextFile UTF8 "./example.svg" rendered
equal "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n -->\n<!-- Title: %0 Pages: 1 -->\n<svg width=\"134pt\" height=\"116pt\"\n viewBox=\"0.00 0.00 134.00 116.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 112)\">\n<title>%0</title>\n<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-112 130,-112 130,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<polygon fill=\"#f44336\" stroke=\"#000000\" points=\"63,-108 36,-90 63,-72 90,-90 63,-108\"/>\n<text text-anchor=\"middle\" x=\"63\" y=\"-85.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"#000000\" cx=\"27\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"27\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">b</text>\n</g>\n<!-- a&#45;&gt;b -->\n<g id=\"edge1\" class=\"edge\">\n<title>a&#45;&gt;b</title>\n<path fill=\"none\" stroke=\"#000000\" d=\"M56.2287,-76.4574C51.7233,-67.4465 45.6551,-55.3103 40.2156,-44.4311\"/>\n<polygon fill=\"#000000\" stroke=\"#000000\" points=\"43.2549,-42.6835 35.6522,-35.3045 36.9939,-45.814 43.2549,-42.6835\"/>\n</g>\n<!-- d -->\n<g id=\"node3\" class=\"node\">\n<title>d</title>\n<ellipse fill=\"none\" stroke=\"#000000\" cx=\"99\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"99\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">d</text>\n</g>\n<!-- a&#45;&gt;d -->\n<g id=\"edge2\" class=\"edge\">\n<title>a&#45;&gt;d</title>\n<path fill=\"none\" stroke=\"#000000\" d=\"M69.7713,-76.4574C74.2767,-67.4465 80.3449,-55.3103 85.7844,-44.4311\"/>\n<polygon fill=\"#000000\" stroke=\"#000000\" points=\"89.0061,-45.814 90.3478,-35.3045 82.7451,-42.6835 89.0061,-45.814\"/>\n</g>\n</g>\n</svg>\n" rendered
equal "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n -->\n<!-- Title: %0 Pages: 1 -->\n<svg width=\"134pt\" height=\"116pt\"\n viewBox=\"0.00 0.00 134.00 116.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 112)\">\n<title>%0</title>\n<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-112 130,-112 130,4 -4,4\"/>\n<!-- a -->\n<g id=\"node1\" class=\"node\">\n<title>a</title>\n<polygon fill=\"#f44336\" stroke=\"#000000\" points=\"63,-108 36,-90 63,-72 90,-90 63,-108\"/>\n<text text-anchor=\"middle\" x=\"63\" y=\"-85.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">a</text>\n</g>\n<!-- b -->\n<g id=\"node2\" class=\"node\">\n<title>b</title>\n<ellipse fill=\"none\" stroke=\"#000000\" cx=\"27\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"27\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">b</text>\n</g>\n<!-- a&#45;&gt;b -->\n<g id=\"edge1\" class=\"edge\">\n<title>a&#45;&gt;b</title>\n<path fill=\"none\" stroke=\"#000000\" d=\"M56.2287,-76.4574C51.7233,-67.4465 45.6551,-55.3103 40.2156,-44.4311\"/>\n<polygon fill=\"#000000\" stroke=\"#000000\" points=\"43.2549,-42.6835 35.6522,-35.3045 36.9939,-45.814 43.2549,-42.6835\"/>\n</g>\n<!-- d -->\n<g id=\"node3\" class=\"node\">\n<title>d</title>\n<ellipse fill=\"none\" stroke=\"#000000\" cx=\"99\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"99\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">d</text>\n</g>\n<!-- a&#45;&gt;d -->\n<g id=\"edge2\" class=\"edge\">\n<title>a&#45;&gt;d</title>\n<path fill=\"none\" stroke=\"#f44336\" stroke-width=\"3\" d=\"M69.7713,-76.4574C74.2767,-67.4465 80.3449,-55.3103 85.7844,-44.4311\"/>\n<polygon fill=\"#f44336\" stroke=\"#f44336\" stroke-width=\"3\" points=\"89.0061,-45.814 90.3478,-35.3045 82.7451,-42.6835 89.0061,-45.814\"/>\n</g>\n</g>\n</svg>\n" rendered