BaH.Graphviz

BlitzMax Modules Forums/Brucey's Modules/BaH.Graphviz

It's taken me long enough, but I've finally released BaH.Graphviz.

Graphviz is a graph layout engine. Essentially, you feed it a graph description, and it will lay it out nicely for you.

You can see examples of what it can do HERE.

The Graphviz module adds the ability to interact with the generated graphs, by zooming, selecting nodes and edges, and retrieving information on them.

You are also able to generate graphs on-the-fly using the built-in graph-builder object hierarchy. You might use it to show the class-structure of your sourcecode, for example, changing dynamically as the source is modified...

You can learn more about it here : http://code.google.com/p/maxmods/wiki/GraphvizModule

Note - You will also need the Expat and GraphvizMax2D modules, available from the Downloads section.

As usual, it's cross-platform, *free*, and fully documented.


Yet another niche module from the makers of the other niche modules ;-)

Nice one.

It's just that I get an error when running the examples:
D:/BlitzMax/mod/bah.mod/graphviz.mod/graphviz.release.win32.x86.a(input.c.release.win32.x86.o):input.c:(.text+0xc29): undefined reference to `setenv'


same here:
C:/Programmi/BlitzMax/mod/bah.mod/graphviz.mod/graphviz.debug.win32.x86.a(input.c.debug.win32.x86.o):input.c:(.text+0xc41): undefined reference to `setenv'


Woops... Fixed.

Apologies.

nice! everything worked as expected,
thanks

you should update your graphviz download on your homepage.

Also, i noticed when loading some of the dot files that came with your module it crashes, more on this when im on my home computer.

Here is a modified example to show the crash

'
' Keys : 1-5 to switch layout engine
' Keys : A, B to load different graphs and re-layout.
'
SuperStrict

Framework BaH.Graphviz
Import BaH.GraphvizMax2D

Import BRL.StandardIO
Import BRL.TextStream
Import BRL.glmax2d

?linux
Import "glsupport.bmx"
?macos
Import "glsupport.bmx"
?

Local renderSupport:TGVRenderSupport

?linux
renderSupport = New TOpenGLRenderSupport
?macos
renderSupport = New TOpenGLRenderSupport
?

Local renderer:TGVGraphviz = TGVGraphviz.Create(800, 600, renderSupport) ' with optional render support

'change <blitzmaxpath> to your blitzmax install location
renderer.loadGraphText(LoadText("<blitzmaxpath>\mod\BaH.mod\graphviz.mod\graphs\directed\arrows.dot"))

Graphics 800, 600, 0

SetClsColor(255, 255, 255)
SetBlend alphablend

renderer.layout("dot")
renderer.fit(800, 600)


Local mx:Int
Local my:Int
Local mz:Int
Local oldZ:Int
Local buttons:Int[] = New Int[3]

Local currentGraph:Int = 1
Local currentLayout:Int = 1

While Not KeyDown(KEY_ESCAPE)

	If KeyDown(key_1) Then
		If currentLayout <> 1 Then
			renderer.layout("dot")
			renderer.fit(800, 480)
			currentLayout = 1
		End If
	End If

	If KeyDown(key_2) Then
		If currentLayout <> 2 Then
			renderer.layout("neato")
			renderer.fit(800, 480)
			currentLayout = 2
		End If
	End If

	If KeyDown(key_3) Then
		If currentLayout <> 3 Then
			renderer.layout("twopi")
			renderer.fit(800, 480)
			currentLayout = 3
		End If
	End If

	If KeyDown(key_4) Then
		If currentLayout <> 4 Then
			renderer.layout("fdp")
			renderer.fit(800, 480)
			currentLayout = 4
		End If
	End If

	If KeyDown(key_5) Then
		If currentLayout <> 5 Then
			renderer.layout("circo")
			renderer.fit(800, 480)
			currentLayout = 5
		End If
	End If

	If KeyDown(key_A) Then
		If currentGraph <> 1 Then
			renderer.loadGraphText(LoadText("../graphs/directed/sdh.dot"))
			renderer.layout("dot")
			renderer.fit(800, 480)
			currentLayout = 1
			currentGraph = 1
		End If
	End If

	If KeyDown(key_B) Then
		If currentGraph <> 2 Then
			renderer.loadGraphText(LoadText("example_02.dot"))
			renderer.layout("dot")
			renderer.fit(800, 480)
			currentLayout = 1
			currentGraph = 2
		End If
	End If
	
	Cls
	
	SetColor(255, 255, 255)
	
	mx = MouseX()
	my = MouseY()
	mz = MouseZ()
		
	' tell graphviz we've moved the mouse
	renderer.mouseMove(mx, my)
	
	For Local i:Int = 1 To 3
		If MouseDown(i)
			If Not buttons[i - 1] Then
				renderer.MouseDown(mx, my, i) ' mouse button press
				buttons[i - 1] = 1
			End If
		Else
			If buttons[i - 1] Then
				buttons[i - 1] = 0
				renderer.mouseUp(mx, my, i) ' mouse button release
			End If
		End If
	Next
	
	If mz <> oldZ Then
		If mz < oldZ Then
			renderer.mouseScroll(mx, my, -1) ' scroll up - zoom in
		Else
			renderer.mouseScroll(mx, my, 1) ' scroll down - zoom out
		End If
		oldZ = mz
	End If
	
	If KeyHit(key_down) Then
		renderer.mouseScroll(mx, my, -1) ' scroll up - zoom in
	End If
	
	If KeyHit(key_up) Then
		renderer.mouseScroll(mx, my, 1) ' scroll down - zoom out
	End If

	' refresh/redraw the graph
	renderer.refresh()

	' draw the current tooltip under the mouse - if there is one!
	renderer.drawTooltip(mx, my + 16)
	
	' get data for current object
	Local obj:TGViewObject = renderer.currentObject()
	
	If obj Then
		SetImageFont(Null)
		
		SetColor 255, 100, 100
		
		DrawText obj.name, 400, 0
		DrawText obj.skind, 400, 15
		
		For Local i:Int = 0 Until obj.attributes.length			
			DrawText obj.attributes[i].name + " : " + obj.attributes[i].value, 400, 60 + i * 15
		Next
	End If
	

	Flip
Wend

End


Also, there are several other dot files that crash it.

I haven't checked this out yet, but it looks like something i'll definite find a great use of. Amazing addition. Thanks bruce.

@Plash
Looks like my poly drawing code wasn't very good ;-)
Seems to work now - Tried it on most of the directed graphs without problems.

You can get the updated BaH.GraphvizMax2D module from the Downloads section, or via SVN.

@Retimer
Thanks :-)
It's definitely one of the more interesting modules.