/**
* the object for the node-degree metric
*/
var NodeDegreeMetric = {};
// define the ranges for the visual link- and node-properties
NodeDegreeMetric.scaleFontSize = d3.scale.linear().range([20, 100]);
NodeDegreeMetric.scaleFontColor = d3.scale.linear().range(["#A8C8FF", "#000B82"]);
NodeDegreeMetric.scaleLinkWidth = d3.scale.linear().range([4, 20]);
/**
* determines the domains of the ranges for the visual link- and node-properties
*
* @param {array} nodes All nodes of a graph
* @param {array} links All links of a graph
*/
NodeDegreeMetric.setDomains = function(nodes, links)
{
// determine the domain of the node-properties
this.scaleFontSize.domain([d3.min(nodes, function(node) {return d3.min(node.subnodes, function(subnode) {return subnode.inDegree + subnode.outDegree;})}),
d3.max(nodes, function(node) {return d3.max(node.subnodes, function(subnode) {return subnode.inDegree + subnode.outDegree;})})]);
this.scaleFontColor.domain([0.0, 1.0]);
// determine the domain of the link-properties
this.scaleLinkWidth.domain([d3.min(links, function(link) {return link.count;}),
d3.max(links, function(link) {return link.count;})]);
}
/**
* determines the font-size for the given node according to this metric
*
* @param {object} node A single node of a graph
*
* @returns the font-size
*/
NodeDegreeMetric.getFontSize = function(node)
{
return this.scaleFontSize(node.inDegree + node.outDegree);
}
/**
* determines the font-color for the given node according to this metric
*
* @param {object} node A single node of a graph
*
* @returns the font-color
*/
NodeDegreeMetric.getFontColor = function(node)
{
return this.scaleFontColor(node.outDegree / (node.inDegree + node.outDegree));
}
/**
* determines the width for the given link according to this metric
*
* @param {object} link A single link of a graph
*
* @returns the link-width
*/
NodeDegreeMetric.getLinkWidth = function(link)
{
return this.scaleLinkWidth(link.count);
}