sigma.plugins.relativeSize.js 710 B

12345678910111213141516171819202122232425262728
  1. (function() {
  2. 'use strict';
  3. if (typeof sigma === 'undefined')
  4. throw 'sigma is not declared';
  5. sigma.utils.pkg('sigma.plugins');
  6. var _id = 0,
  7. _cache = {};
  8. /**
  9. * This function will change size for all nodes depending to their degree
  10. *
  11. * @param {sigma} s The related sigma instance.
  12. * @param {object} initialSize Start size property
  13. */
  14. sigma.plugins.relativeSize = function(s, initialSize) {
  15. var nodes = s.graph.nodes();
  16. // second create size for every node
  17. for(var i = 0; i < nodes.length; i++) {
  18. var degree = s.graph.degree(nodes[i].id);
  19. nodes[i].size = initialSize * Math.sqrt(degree);
  20. }
  21. s.refresh();
  22. };
  23. }).call(window);