I am trying to use Nodebox Graph on Ubuntu and python 2.7.
So I got Nodebox OpenGL: http://www.cityinabottle.org/nodebox/
Nodebox Graph: https://www.nodebox.net/code/index.php/Graph
I tried to run their basic example 1 :
graph = ximport("graph")
size(500, 500)
g = graph.create()
# Create some relations.
g.add_edge("roof" , "house")
g.add_edge("garden" , "house")
g.add_edge("room" , "house")
g.add_edge("kitchen" , "room")
g.add_edge("bedroom" , "room")
g.add_edge("bathroom" , "room")
g.add_edge("living room" , "room")
g.add_edge("sofa" , "living room")
g.add_edge("table" , "living room")
# Calculate a good layout.
g.solve()
# Apply default rules for node colors and size,
# for example, important nodes become blue.
g.styles.apply()
# Draw the graph, indicating the direction of each relation
# and the two nodes that get the most traffic.
g.draw(
directed=True,
traffic=1
)
That doesn't work because ximport is not defined, it is only define by nodebox, so instead I tried two things, first doing a normal import import graph second putting the ximport function from nodebox in my code:
def ximport(library):
from sys import modules
library = __import__(library)
library._ctx = modules[__name__]
return library
graph = ximport("graph")
size(500, 500)
g = graph.create()
# Create some relations.
g.add_edge("roof" , "house")
g.add_edge("garden" , "house")
g.add_edge("room" , "house")
g.add_edge("kitchen" , "room")
g.add_edge("bedroom" , "room")
g.add_edge("bathroom" , "room")
g.add_edge("living room" , "room")
g.add_edge("sofa" , "living room")
g.add_edge("table" , "living room")
# Calculate a good layout.
g.solve()
# Apply default rules for node colors and size,
# for example, important nodes become blue.
g.styles.apply()
# Draw the graph, indicating the direction of each relation
# and the two nodes that get the most traffic.
g.draw(
directed=True,
traffic=1
)
That still doesn't work because now the function size is not recognized. If I just comment size out, I get the following error:
self.x = _ctx.WIDTH - max.x*self.d - min_.x*self.d
AttributeError: 'NoneType' object has no attribute 'WIDTH'
What do I do?
This question could be similar:
Pydev Nodebox: "AttributeError: 'NoneType' object has no attribute 'WIDTH'"
but the given answer is not helpful at all to me.
The code in https://www.nodebox.net/code/index.php/Graph doesn't work for nodebox opengl, it is only compatible for nodebox 1 for mac so there is no easy fix. However, nodebox opengl has it's own interactive functions to it is possible to use them instead. Here is partial example code: