/usr/lib/hugs/packages/fgl/Data/Graph/Inductive/Graphviz.hs is in libhugs-fgl-bundled 98.200609.21-5.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | -- | Simple graphviz output.
module Data.Graph.Inductive.Graphviz(
Orient(..),
graphviz, graphviz'
) where
import Data.Graph.Inductive.Graph
data Orient = Portrait | Landscape deriving (Eq, Show)
o2s :: Orient -> String
o2s Portrait = "\trotate = \"0\"\n"
o2s Landscape = "\trotate = \"90\"\n"
-- | Formats a graph for use in graphviz.
graphviz :: (Graph g, Show a, Show b) => g a b -- ^ The graph to format
-> String -- ^ The title of the graph
-> (Double, Double) -- ^ The size
-- of the page
-> (Int, Int) -- ^ The width and
-- height of the page
-- grid
-> Orient -- ^ The orientation of
-- the graph.
-> String
i2d :: Int -> Double
i2d = fromInteger . toInteger
graphviz g t (w, h) p@(pw', ph') o =
let n = labNodes g
e = labEdges g
ns = concatMap sn n
es = concatMap se e
sz w' h' = if o == Portrait then show w'++","++show h' else show h'++","++show w'
ps = show w++","++show h
(pw, ph) = if o == Portrait then p else (ph', pw')
--gs = show ((w*(i2d pw))-m)++","++show ((h*(i2d ph))-m)
gs = sz (w*(i2d pw)) (h*(i2d ph))
in "digraph "++t++" {\n"
++"\tmargin = \"0\"\n"
++"\tpage = \""++ps++"\"\n"
++"\tsize = \""++gs++"\"\n"
++o2s o
++"\tratio = \"fill\"\n"
++ns
++es
++"}"
where sn (n, a) | sa == "" = ""
| otherwise = '\t':(show n ++ sa ++ "\n")
where sa = sl a
se (n1, n2, b) = '\t':(show n1 ++ " -> " ++ show n2 ++ sl b ++ "\n")
-- | Format a graph for graphviz with reasonable defaults: title of \"fgl\",
-- 8.5x11 pages, one page, landscape orientation
graphviz' :: (Graph g, Show a, Show b) => g a b -> String
graphviz' g = graphviz g "fgl" (8.5,11.0) (1,1) Landscape
sq :: String -> String
sq ('"':s) | last s == '"' = init s
| otherwise = s
sq ('\'':s) | last s == '\'' = init s
| otherwise = s
sq s = s
sl :: (Show a) => a -> String
sl a =
let l = sq (show a)
in if (l /= "()") then (" [label = \""++l++"\"]") else ""
|