Codebase Visualization
Codegen provides the ability to create interactive graph visualizations via the codebase.visualize(…) method.
These visualizations have a number of applications, including:
- Understanding codebase structure
- Monitoring critical code paths
- Analyzing dependencies
- Understanding inheritance hierarchies
This guide provides a basic overview of graph creation and customization. Like the one below which displays the call_graph for the modal/client.py module.
Basic Usage
The Codebase.visualize method operates on a NetworkX DiGraph.
It is up to the developer to add nodes and edges to the graph.
Adding Nodes and Edges
When adding nodes to your graph, you can either add the symbol directly or just its name:
Adding symbols to the graph directly (as opposed to adding by name) enables automatic type information, code preview on hover, and more.
Common Visualization Types
Call Graphs
Visualize how functions call each other and trace execution paths:
Learn more about traversing the call graph here.
React Component Trees
Visualize the hierarchy of React components:
Inheritance Graphs
Visualize class inheritance relationships:
Module Dependencies
Visualize dependencies between modules:
Function Modularity
Visualize function groupings by modularity:
Customizing Visualizations
You can customize your visualizations using NetworkX’s attributes while still preserving the smart node features:
Best Practices
-
Use Symbol Objects for Rich Features
-
Focus on Relevant Subgraphs
-
Use Meaningful Layouts
-
Add Visual Hints
Limitations
- Large graphs may become difficult to read
- Complex relationships might need multiple views
- Some graph layouts may take time to compute
- Preview features only work when adding symbol objects directly
Was this page helpful?