Graphoon (Now with online demo)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Graphoon (Now with online demo)

Post by rmcode »

A force directed graph algorithm written in Lua.

Image

Graphoon emerged from the graph calculation code used in both LoGiVi and LoFiVi.

A force directed graph layout is achieved by simulating physical forces, which push and pull each node in the graph until a nice layout is found.

The code lives on github.

A demo .love can be found here (requires LÖVE 0.10.0).

The same demo can also be found online here.
Last edited by rmcode on Mon Feb 08, 2016 7:17 pm, edited 1 time in total.
User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Re: Graphoon

Post by riidom »

Looks awesome, you just wiped out the main reason why I didnt start to check out this 4X-idea I am having :)
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Graphoon

Post by rmcode »

riidom wrote:Looks awesome, you just wiped out the main reason why I didnt start to check out this 4X-idea I am having :)
Thank you :)

I'm always open for suggestions.
Katamori
Prole
Posts: 47
Joined: Wed Aug 21, 2013 10:06 pm

Re: Graphoon

Post by Katamori »

Holy shit, it's beautiful!

Was it as painful to create as painful I think it was?
not active here anymore
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Graphoon

Post by rmcode »

Katamori wrote:Was it as painful to create as painful I think it was?
I wouldn't call it painful. I learned a lot while working on the graph code, but it definitely took some time :D

It's not perfect either: First of all the runtime increases exponentially with each added node (I have an idea how to break it down using a spatial index, but haven't tried implementing one yet) and there still are some cases where the graph will "explode" or not form a nice layout.

All in all I am quite happy with the current version though :)
Xugro
Party member
Posts: 110
Joined: Wed Sep 29, 2010 8:14 pm

Re: Graphoon

Post by Xugro »

rmcode wrote:It's not perfect either: First of all the runtime increases exponentially with each added node (I have an idea how to break it down using a spatial index, but haven't tried implementing one yet) and there still are some cases where the graph will "explode" or not form a nice layout.
I have the same problems, but I did not work any further on my code (see attachment).

What could work is using a global potential of all nodes instead of using forces between each node-pair. But thats something I have not tried.
Attachments
PageRankGraph.love
(227.25 KiB) Downloaded 157 times
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Graphoon

Post by rmcode »

Xugro wrote:
rmcode wrote:It's not perfect either: First of all the runtime increases exponentially with each added node (I have an idea how to break it down using a spatial index, but haven't tried implementing one yet) and there still are some cases where the graph will "explode" or not form a nice layout.
I have the same problems, but I did not work any further on my code (see attachment).

What could work is using a global potential of all nodes instead of using forces between each node-pair. But thats something I have not tried.
Hehe when I started messing around with this whole force-directed layout stuff I wrote a program quite similar to yours. It basically attracts all nodes towards the center and adds repulsion forces between them (so no extra attraction force between connected nodes).

I then started connecting nodes at random, but it quickly turned out that with a global attraction point the nodes won't get close to the nodes they are connected to, which leads to a messy layout. It's because of the attraction forces between connected nodes that a nice layout is formed (aka connected nodes are close to each other).

One idea I wanted to try out uses a spatial index. You could iterate over all edges and attract nodes along their connections regardless of where they are, but use a quadtree to only repel nodes which are close to each other. Depending on the distance between nodes, a lot of the repulsion forces are small enough to be negligible. (I actually tried this with LoGiVi about a year ago, but didn't manage to get a nice layout: https://twitter.com/rm_code/status/579957755613745152).
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Graphoon (Now with online demo)

Post by rmcode »

Added an online demo (using love.js): http://rm-code.github.io/Graphoon/
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Graphoon (Now with online demo)

Post by Ref »

Thought I might have an application so diddled with the code.
Your comment:

Code: Select all

DISCLAIMER: Don't scroll down if you can't stand ugly code.
Don't mind ugly code (produce a lot of it myself) but semicolons - UG!
Moved all of the constants up front for easy adjustments (rather than having them distributed in the modules).

Code: Select all

-- ------------------------------------------------
-- Constants
-- ------------------------------------------------

local color = {
	background = { 204, 224, 232 },
	node		 = { 130, 190, 238 },
	edge		 = { 100, 100, 100 },
	text		= {  30, 100, 256 },
	cursor	= { 234, 49,  110 }
	}

local sprite	= { image = love.graphics.newImage( 'file.png' ), size = 16 }
	sprite.ht	= sprite.image:getHeight()
	sprite.scale= sprite.size/sprite.ht
	sprite.offset= sprite.ht/2

force = { spring = 0.005, change  = 20,   max  = 4 }
param = { speed  = 128,   damping = 0.95, mass = 3 }

local data		= { sets = { 'GraphoonData', 'program', 'EvilDead' }, selected = 1 }
local screen	= { wd = 1200, ht = 700 }
and added ability to switch data sets on the fly ('N' key).
Conclusion: Very interesting but really don't know what to do with it.
Last edited by Ref on Fri Feb 12, 2016 3:14 am, edited 1 time in total.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Graphoon (Now with online demo)

Post by Ref »

Really surprised as to how easy it was to add rotation (just press 'R')
Really a neat script.
Good job.
Edit: My bad! Forgot to include the license!
Reloaded love with license.
Attachments
GraphoonDemoWithRotation.love
(26.95 KiB) Downloaded 135 times
Post Reply

Who is online

Users browsing this forum: No registered users and 81 guests