Skip to content

Instantly share code, notes, and snippets.

@jchia
Created October 13, 2017 06:02
Show Gist options
  • Save jchia/c4a19f2a862d8476cc0b9cd024b383f6 to your computer and use it in GitHub Desktop.
Save jchia/c4a19f2a862d8476cc0b9cd024b383f6 to your computer and use it in GitHub Desktop.
graphviz package generates graph with wrong arc direction.
#!/usr/bin/env stack
-- stack --resolver nightly-2017-10-08 runghc --package graphviz
import qualified Data.GraphViz.Types.Graph as GV
import Data.GraphViz.Commands (GraphvizOutput(..), dirCommand, runGraphvizCommand)
main :: IO ()
main = do
-- This generates an arc with the wrong direction. There should be an arc from 0 to 1 but this code produces
-- an arc from 1 to 0, contrary to the documentation of the fields of DotEdge, popular convention and fgl
-- convention.
let gv = GV.mkGraph [GV.DotNode (0 :: Int) [], GV.DotNode 1 []] [GV.DotEdge 0 1 []]
runGraphvizCommand dirCommand gv DotOutput "/tmp/gv.dot"
pure ()
{-
Output:
digraph {
graph [bb="0,0,54,108"];
node [label="\N"];
0 [height=0.5,
pos="27,18",
width=0.75];
1 [height=0.5,
pos="27,90",
width=0.75];
1 -> 0 [pos="e,27,36.104 27,71.697 27,63.983 27,54.712 27,46.112"];
}
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment