Source: metrics/NodeDegreeMetric.js

  1. /**
  2. * the object for the node-degree metric
  3. */
  4. var NodeDegreeMetric = {};
  5. // define the ranges for the visual link- and node-properties
  6. NodeDegreeMetric.scaleFontSize = d3.scale.linear().range([20, 100]);
  7. NodeDegreeMetric.scaleFontColor = d3.scale.linear().range(["#A8C8FF", "#000B82"]);
  8. NodeDegreeMetric.scaleLinkWidth = d3.scale.linear().range([4, 20]);
  9. /**
  10. * determines the domains of the ranges for the visual link- and node-properties
  11. *
  12. * @param {array} nodes All nodes of a graph
  13. * @param {array} links All links of a graph
  14. */
  15. NodeDegreeMetric.setDomains = function(nodes, links)
  16. {
  17. // determine the domain of the node-properties
  18. this.scaleFontSize.domain([d3.min(nodes, function(node) {return d3.min(node.subnodes, function(subnode) {return subnode.inDegree + subnode.outDegree;})}),
  19. d3.max(nodes, function(node) {return d3.max(node.subnodes, function(subnode) {return subnode.inDegree + subnode.outDegree;})})]);
  20. this.scaleFontColor.domain([0.0, 1.0]);
  21. // determine the domain of the link-properties
  22. this.scaleLinkWidth.domain([d3.min(links, function(link) {return link.count;}),
  23. d3.max(links, function(link) {return link.count;})]);
  24. }
  25. /**
  26. * determines the font-size for the given node according to this metric
  27. *
  28. * @param {object} node A single node of a graph
  29. *
  30. * @returns the font-size
  31. */
  32. NodeDegreeMetric.getFontSize = function(node)
  33. {
  34. return this.scaleFontSize(node.inDegree + node.outDegree);
  35. }
  36. /**
  37. * determines the font-color for the given node according to this metric
  38. *
  39. * @param {object} node A single node of a graph
  40. *
  41. * @returns the font-color
  42. */
  43. NodeDegreeMetric.getFontColor = function(node)
  44. {
  45. return this.scaleFontColor(node.outDegree / (node.inDegree + node.outDegree));
  46. }
  47. /**
  48. * determines the width for the given link according to this metric
  49. *
  50. * @param {object} link A single link of a graph
  51. *
  52. * @returns the link-width
  53. */
  54. NodeDegreeMetric.getLinkWidth = function(link)
  55. {
  56. return this.scaleLinkWidth(link.count);
  57. }