Skip to content
Understand by Scitools
Menu
  • Home
  • Support
  • Contact
  • Login
  • Pricing
  • Free Trial
Menu

Making a Custom Cluster Graph

Posted on August 2, 2022

Abstract: Extend the custom architecture dependencies graph by adding clusters.

In a previous article, we made an architecture dependency graph with custom edges. However, the graph doesn’t preserve parent-children relationships. For example, if you made this architecture in Fastgrep:

A custom architecture for Fastgrep

You’d get this graph:

But, “Ent Children Only” is a child of “Arch and Entity Children.” A parent child relationship is usually shown by creating clusters. This article describes how to extend the previously described plugin to cluster architectures.

Python Code

First, we’ll update the name of the graph:

Update the name

Next, we need to track the created clusters just like we track the created nodes. So, we’ll have a clusters dictionary in the draw function that gets passed to grabNode:

Track clusters

Then, we need a grabCluster function that will create new clusters as needed. The grabCluster function must be recursive to allow an arbitrary nesting level. The recursion ends when arch is “None”, meaning there was no parent. In that case, the graph object is returned. 

def grabCluster(graph, clusters, arch):
  if not arch:
    return graph
  if arch not in clusters:
    parcluster = grabCluster(graph,clusters,arch.parent())
    clusters[arch] = parcluster.cluster(arch.name(),arch)
  return clusters[arch]

Finally, the grabNode function needs to be updated to use the correct graph parent for each node. There’s a little bit of trickiness here because, like the example at the beginning, an architecture might have both entity and architecture children. In that case, there might be an edge directly to the architecture and edges to its architecture children. We catch that case by checking if there are architecture children on the node we’re grabbing. If there are, we style this node as just text and clear the label on the cluster making it look like the edge goes to the cluster label.

Update grabNode to use the correct cluster

Now, with the initial architecture we get this graph:

Dependency Graph with Clusters
python_arch_cluster_deps.upy_Download

Related

  • API
  • Architectures
  • Business
  • Code Comparison
  • Code Comprehension
  • Code Navigation
  • Code Visualization
  • Coding Standards
  • Dependencies
  • Developer Notes
  • DevOps
  • Getting Started
  • Legacy Code
  • Licensing
  • Metrics
  • Platform
  • Power User Tips
  • Programming Practices
  • Uncategorized
  • Useful Scripts
  • January 2023
  • December 2022
  • November 2022
  • September 2022
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

©2023 SciTools Blog | Design: Newspaperly WordPress Theme