Source: metrics/NodeCountMetric.js

/**
 * the object for the node-count metric
 */
var NodeCountMetric = {};

// define the ranges for the visual link- and node-properties
NodeCountMetric.scaleFontSize = d3.scale.linear().range([20, 100]);
NodeCountMetric.scaleFontColor = d3.scale.linear().range(["#A8C8FF", "#000B82"]);
NodeCountMetric.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
 */
NodeCountMetric.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.count;})}),
	                           d3.max(nodes, function(node) {return d3.max(node.subnodes, function(subnode) {return subnode.count;})})]);
	
	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
 */
NodeCountMetric.getFontSize = function(node)
{
	return this.scaleFontSize(node.count);
}



/**
 * 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
 */
NodeCountMetric.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
 */
NodeCountMetric.getLinkWidth = function(link)
{
	return this.scaleLinkWidth(link.count);
}