Search code examples
haskellgraphvizhaskell-diagrams

Haskell Diagrams Graphviz Gtk Display alignment and scaling


I want to display a graph layed out by graphviz (via Data.GraphViz) in a Gtk window. The code I have does not automatically center the graph or size the diagram. I have setup a github repo with an example (see src/Main.hs at https://github.com/avras/diagrams-gtk-graphviz-example. I get the following output.

enter image description here

If I try showing a circle of radius one, I get the following output (which is expected). The code for this example is at src/Circle.hs in the same github repository. Main.hs and Circle.hs differ only in the diagram which is rendered (afaict).

enter image description here

How can I get the graph to be centered in the window with the right width automatically calculated?

I had to play around with the argument to mkWidth to get this picture. Also without setting lw 0.005 the result was the following. The line width seems to be very large.

enter image description here

EDIT Here is the result after the fix suggested by Joachim Breitner. enter image description here


Solution

  • This is a guess, but I assume that the circle is centered on the origin (0,0), and the diagram is put in the unit square (between (0,0) and (1,1)).

    I would guess that if you remove the line

    GRC.translate (w/2) (h/2)
    

    in Main.hs it will work.