开发者

Tree visualisation and animation

I'm working with multiple search strategies on trees in Haskell. I want to visualize them and also animate the search I'm doing in it. The best I've found so far is graphviz images that I could generate by writing DOT files (like in Land of Lisp) but I doubt that it is the best approach. My trees can get quite big so I don't want to enter the position of each node in my program, I want them to be places correctly automatically.

I've also looked a little bit at Gephi but I'm not sure if I can input my data in it.

Also my Tree datatype is very basic : data Tree a = Leaf a | Branch (Tree a) (Tree a).

So in short, I'm looking for a way to get tree visualisation and animation on search strategy in it. I'm not looking necessarily for a Haskell centric solution but it could be great. Also bei开发者_高级运维ng able to output the images/animation in standard format such as gif would a big plus.


I'll expand my comment: I haven't investigated pricing policy of Ubigraph, but you can download a free version from their site ("basic" one?). Then you can install vacuum-ubigraph package (there seems to be a build failure HackageDB under GHC 7.0, but I've just managed to install it under my 7.0.2 without a problem). Once it's done you can just start ubigraph_server and start 'feeding' it with your data structures right from ghci:

import System.Vacuum.Ubigraph

data Tree a = Leaf a | Branch (Tree a) (Tree a)
data Root a = Root a

tree =
    Root
    (Branch
     (Branch
      (Leaf "A")
      (Leaf "B"))
     (Leaf "C"))

Type view tree and you'll get something similar to:

Tree visualisation and animation

You can zoom in/out and rotate it. Not sure how practical it is (it shows the entire Haskell object graph like it is - note shared []), but there are lots of settings to play with, so you can definitely make it look nicer. Animation seems to be supported as well.


If you go the Ubigraph route you can just use the HUbigraph bindings directly, for example:

import Graphics.Ubigraph
import Control.Monad

main = do
  h <- initHubigraph "http://127.0.0.1:20738/RPC2"
  runHubigraph op h

op = do
  clear
  vs <- mapM (const newVertex) [0..400]
  mapM_ (setVAttr (VShape Sphere)) vs
  let bind i = zipWithM (\a b -> newEdge (a,b)) vs (drop i vs ++ take i vs)
  mapM_ bind [1..15]
  return ()

I just spent some time playing with this - it's fun but don't try to up the value of 15 to, say, 40 or ubigraph gets very upset (constant motion of the verticies)!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜