documentationfor yFiles for HTML 2.6

KMeansClustering

Partitions the graph into clusters using k-means clustering.

Inheritance Hierarchy
KMeansClustering

Remarks

The nodes of the graph will be partitioned into k clusters, based on their positions such that their distance to the cluster's mean (centroid) is minimized.

Other Clustering Algorithms

yFiles for HTML supports a number of other clustering algorithms:

Examples

Calculating the k-means clusters of a graph
// prepare the k-means clustering algorithm
const algorithm = new KMeansClustering()
// run the algorithm
const result = algorithm.run(graph)

// highlight the nodes of the clusters with different styles
for (const node of graph.nodes) {
  const componentId = result.nodeClusterIds.get(node)
  graph.setStyle(node, clusterStyles.get(componentId))
}// prepare the k-means clustering algorithm
const algorithm = new KMeansClustering()
// run the algorithm
const result = algorithm.run(graph)

// highlight the nodes of the clusters with different styles
for (const node of graph.nodes) {
  const componentId = result.nodeClusterIds.get(node)
  graph.setStyle(node, clusterStyles.get(componentId)!)
}

Type Details

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

See Also

If the number of given centroids is smaller than k or if no centroids are given, random initial centroids will be assigned for all clusters.

Constructors

Properties

Methods