jacomyal / sigma.js

A JavaScript library aimed at visualizing graphs of thousands of nodes and edges
https://www.sigmajs.org/
MIT License
11.25k stars 1.59k forks source link

extending graph API #309

Closed mef closed 10 years ago

mef commented 10 years ago

I need to implement new graph algorithms like HITS or Louvain method for community detection.

  1. According to you, would such features fit inside the graph model, or should they rather stay out in plugins ?
  2. Would you be interested by pull requests to add these algorithms to sigma.js?

P.S.: congrats on the 1.0 rewrite, sigma really looks much more easy to customize now, and greatly documented !

sheymann commented 10 years ago

my 2 cents: most sigma users don't need these features, so they should be provided as plugins.

How about naming: sigma.statistics.hits and sigma.statistics.louvain?

Yomguithereal commented 10 years ago

This would indeed be nice to see such a plugin. I cannot tell you whether it should belong to core or not but coding the plugin would absolutely not be in vain.

mef commented 10 years ago

@sheymann I see that you're one of the authors of the implementation of HITS algorithm in Gephi. I have based my code on yours. Does it seem acceptable for you to have this plugin, port of your java code, licensed under the same terms of sigma.js' license, or is it considered as a modification of Gephi's code, and should remain under Gephi's dual-license?

sheymann commented 10 years ago

Hello @mef,

Unfortunately the Gephi implementation has too many issues, therefore I recommend to write your own algorithm from scratch. Anna, a Google Summer of Code student has performed some testing that are available here, see section 11.

mef commented 10 years ago

Great test cases. I'm adding them to sigma's qunit to validate the plugin.

Is there any further documentation I could refer to as the base of the test cases?

sheymann commented 10 years ago

If I remember well, it's based on the original paper of J. Kleinberg, Authoritative Sources in a Hyperlinked Environment.

1tylermitchell commented 10 years ago

Any pointers to creating plugins (maybe also re: porting older versions from sigma to newer ver) would be helpful too. I'd love to help gets some more algorithms in but it's slow going. At least by the end of it I could write something up from a n00b perspective ;-)

@mef best wishes on this one!

mef commented 10 years ago

thanks @spatialguru.

You should have a look at the code of existing plugins, together with the examples in order to get an idea of how to write some.

I'm also just getting with sigma.js, but here's what I have found out.

The basis structure of a plugin is like this:

;(function(undefined) {
  'use strict';

  if (typeof sigma === 'undefined')
    throw 'sigma is not declared';

  // Initialize package:
  sigma.utils.pkg('sigma.myPluginNs');

  /**
   * sigma.myPluginNs.myFunction constructor.
   */
  sigma.myPluginNs.myConstructor = function() {
    // Access public and private methods
    // and attributes of the sigma instance
    // via `this` 
    this.myPluginFunction = function(params) {
      // features go here
    }
  }

}).call(window)

access from your client code with:


  var whatever = new sigma.myPluginNs.myConstructor();
  // execute plugin function
  var result = whatever.myPluginFunction()  

An alternative technique, if you just need to extend the graph model, is to use sigma.classes.graph.addMethod, cf. first part of the neighborhood plugin code

P.S.: If you're interested by HITS statistics, you can have a look here: https://github.com/jacomyal/sigma.js/pull/329

1tylermitchell commented 10 years ago

Thanks - I think my main challenge is around understanding how much I need to know about the web workers being used by FA2 algorithm :)

On Jul 5, 2014, at 12:04, mef notifications@github.com wrote:

thanks @spatialguru.

You should have a look at the code of existing plugins, together with the examples in order to get an idea of how to write some.

I'm also just getting with sigma.js, but here's what I have found out.

The basis structure of a plugin is like this:

;(function(undefined) { 'use strict';

if (typeof sigma === 'undefined') throw 'sigma is not declared';

// Initialize package: sigma.utils.pkg('sigma.myPluginNs');

/**

  • sigma.myPluginNs.myFunction constructor. */ sigma.myPluginNs.myConstructor = function() { // Access public and private methods // and attributes of the sigma instance // via this this.myPluginFunction = function(params) { // features go here } }

}).call(window) access from your client code with:

var whatever = new sigma.myPluginNs.myConstructor(); // execute plugin function var result = whatever.myPluginFunction()

An alternative technique, if you just need to extend the graph model, is to use sigma.classes.graph.addMethod, cf. first part of the neighborhood plugin code

P.S.: If you're interested by HITS statistics, you can have a look here: #329

— Reply to this email directly or view it on GitHub.

Yomguithereal commented 10 years ago

@spatialguru

What do yo need to know about them? What is your goal? Maybe I can help you.

mef commented 10 years ago

Is there any naming convention for the plugins?

Design guidelines would also be useful, so that plugins respect the same API style as core sigma...