documentationfor yFiles for HTML 2.6

ClosenessCentrality

Computes the closeness centrality for the nodes of a graph.

Inheritance Hierarchy
ClosenessCentrality

Remarks

Closeness centrality is defined as the reciprocal of the sum of shortest path distances of a node to all other nodes in the graph. Therefore, a node with high closeness centrality has short distances to all other nodes of a graph.

Other Centrality Measures

yFiles for HTML supports a number of other centrality measures:

  • GraphCentrality – emphasizes nodes that have short paths to other nodes in a slightly different way
  • DegreeCentrality – emphasizes nodes with many edges
  • WeightCentrality – emphasizes nodes with highly-weighted edges
  • BetweennessCentrality – emphasizes nodes that are part of many short paths
  • EigenvectorCentrality – computes the influence a node has on a network. The centrality value is higher if more nodes are connected to that node
  • PageRank – computes page rank values for all nodes based on their attached edges

Examples

const result = new ClosenessCentrality({
  directed: true,
  // Use the geometric edge length as weight
  weights: (edge) =>
    edge.style.renderer
      .getPathGeometry(edge, edge.style)
      .getPath()
      .getLength()
}).run(graph)

// add node labels for centrality values
// and adjust node size according to centrality
result.normalizedNodeCentrality.forEach(({ key, value }) => {
  const node = key
  const centrality = value
  graph.addLabel(key, String(value))
  graph.setNodeLayout(
    node,
    new Rect(node.layout.center, new Size(centrality, centrality))
  )
})const result = new ClosenessCentrality({
  directed: true,
  // Use the geometric edge length as weight
  weights: (edge) =>
    edge.style.renderer
      .getPathGeometry(edge, edge.style)
      .getPath()!
      .getLength()
}).run(graph)

// add node labels for centrality values
// and adjust node size according to centrality
result.normalizedNodeCentrality.forEach(({ key, value }) => {
  const node = key
  const centrality = value
  graph.addLabel(key, String(value))
  graph.setNodeLayout(
    node,
    new Rect(node.layout.center, new Size(centrality, centrality))
  )
})

Type Details

yfiles module
view-layout-bridge
yfiles-umd modules
view-layout-bridge
Legacy UMD name
yfiles.analysis.ClosenessCentrality

See Also

For graphs with multiple components, the centrality values will be calculated per component.
For graphs which contain only a single node, the centrality value is Number.POSITIVE_INFINITY.

Constructors

Properties

Methods