Permalink
Browse files

Update doc and allows to pass an array of node ids in options

  • Loading branch information...
1 parent a17a70f commit 9ea6a7b0501845cb72f897b22ddedd6980b08811 @sheymann sheymann committed Dec 9, 2014
Showing with 87 additions and 10 deletions.
  1. +63 −0 plugins/sigma.plugins.animate/README.md
  2. +24 −10 plugins/sigma.plugins.animate/sigma.plugins.animate.js
@@ -6,3 +6,66 @@ Plugin developed by [Alexis Jacomy](https://github.com/jacomyal).
---
This plugin provides a method to animate a sigma instance by interpolating some node properties. Check the `sigma.plugins.animate` function doc or the `examples/animate.html` code sample to know more.
+
+Interpolate coordinates as follows:
+
+```js
+sigma.plugins.animate(
+ s,
+ {
+ x: 'target_x',
+ y: 'target_y',
+ }
+ );
+```
+
+Interpolate colors and sizes as follows:
+
+```js
+sigma.plugins.animate(
+ s,
+ {
+ size: 'target_size',
+ color: 'target_color'
+ }
+ );
+```
+
+Animate a subset of nodes as follows:
+
+```js
+sigma.plugins.animate(
+ s,
+ {
+ x: 'to_x',
+ y: 'to_y',
+ size: 'to_size',
+ color: 'to_color'
+ },
+ {
+ nodes: ['n0', 'n1', 'n2']
+ }
+ );
+```
+
+Example using all options:
+
+```js
+sigma.plugins.animate(
+ s,
+ {
+ x: 'to_x',
+ y: 'to_y',
+ size: 'to_size',
+ color: 'to_color'
+ },
+ {
+ nodes: ['n0', 'n1', 'n2'],
+ easing: 'cubicInOut',
+ duration: 300,
+ onComplete: function() {
+ // do stuff here after animation is complete
+ }
+ }
+ );
+```
@@ -78,6 +78,9 @@
* Here is the exhaustive list of every accepted parameters in the settings
* object:
*
+ * {?array} nodes An array of node objects or node ids. If
+ * not specified, all nodes of the graph
+ * will be animated.
* {?(function|string)} easing Either the name of an easing in the
* sigma.utils.easings package or a
* function. If not specified, the
@@ -106,16 +109,27 @@
o.easing :
sigma.utils.easings.quadraticInOut,
start = sigma.utils.dateNow(),
- nodes = options.nodes || s.graph.nodes(),
- // Store initial positions:
- startPositions = nodes.reduce(function(res, node) {
- var k;
- res[node.id] = {};
- for (k in animate)
- if (k in node)
- res[node.id][k] = node[k];
- return res;
- }, {});
+ nodes,
+ startPositions;
+
+ if (o.nodes && o.nodes.length) {
+ if (typeof o.nodes[0] === 'object')
+ nodes = o.nodes;
+ else
+ nodes = s.graph.nodes(o.nodes); // argument is an array of IDs
+ }
+ else
+ nodes = s.graph.nodes();
+
+ // Store initial positions:
+ startPositions = nodes.reduce(function(res, node) {
+ var k;
+ res[node.id] = {};
+ for (k in animate)
+ if (k in node)
+ res[node.id][k] = node[k];
+ return res;
+ }, {});
s.animations = s.animations || Object.create({});
sigma.plugins.kill(s);

0 comments on commit 9ea6a7b

Please sign in to comment.