fkling / JSNetworkX

Build, process and analyze graphs in JavaScript (port of NetworkX)
https://felix-kling.de/jsnetworkx/
Other
757 stars 185 forks source link

Redesign drawing API #46

Open fkling opened 9 years ago

fkling commented 9 years ago

There currently is only the draw function which is like a one-of black box. It's not possible to make changes to the drawing config (without completely redrawing the graph), to extend it to support different kinds of visualization or different layouts.

I already started working on rewriting this part a long time ago and think that it's a good opportunity to introduce it with the next release.

The drawing API will be evolve around an abstract Visualization class which exposes an API that allows easily update an existing visualization. This class can be subclassed to provide different implements. I already have one for SVG output (with D3) and WebGL (experimental, with Three.js). The configuration options will mostly stay the same, but the API is richer.

Usage will look something like this:

var v = jsnx.draw(G, container, {/* some config here */}); // defaults to SVG visualization
// now or later
v.labels(true); // show labels
// or
v.labels(function(d) { return d.data.name; }); // show labels and use node data "name"
v.nodeStyle({style: {fill: 'red' }}); // style options depend on visualization

An implementation might not support every method. E.g. the WebGL implementation currently doesn't support labels, so calling v.labels() will just do nothing. On the other hand, implementations might offer additional methods, e.g. the WebGL implementation provides v.camera to the set the camera to be used.

fkling commented 9 years ago

I decided to make this a lower priority. Over the last one/two years, many libraries for drawing graphs emerged. I think the main value of JSNetworkX is now to provide a comprehensive set of graph analysis methods.

Graph visualization is still going to be important if the library is used in the browser, but what exists now works well enough I think.

beyssac commented 8 years ago

Does it mean that you will not work on WebGL migration for awhile? =/ I was hoping that, because I work with around 2k nodes =/

fkling commented 8 years ago

@beyssac: I actually have a WebGL implementation that works OK. The issue is that wasn't able yet to port all of the SVG functionality to the new style.

But because I only have limited time, I don't not currently plan make changes to the drawing system. However, I could create a separate branch with the changes I have so far for everyone to try who's interested. If someone wants to work on it so it can be merged into master, that would be great!

beyssac commented 8 years ago

Sorry for my delay, what do you mean saying that you don't plan to make changes to the drawing system? As it is now, could I draw graphs in WebGL mode? I mean, when you say that you actually have a WebGL implementation that works ok, you are saying that you can draw with it, can't you?

If yes, I really would like to try it! Unfortunatelly I can not help in programming this part of the API for now =/