Home · Developers · Guides · Code Visualization

Workspace

Code Visualization

Graph visualization

Graph visualization and diagram generation for code structure visualization with DOT format support.

Overview

The CodeVisualizer provides comprehensive code visualization capabilities including:

  • Graph visualization (call, inheritance, knowledge graphs)
  • DOT diagram generation for Graphviz
  • Dependency tree generation
  • Configurable diagram styles and layouts

Components

from novacoder.workspace.visualization import CodeVisualizer, GraphVisualization, DiagramConfig

visualizer = CodeVisualizer("/path/to/workspace")
graph = visualizer.visualize_graph("call")

Usage

Visualize Graph

Generates a graph visualization with nodes and edges:

graph = visualizer.visualize_graph("call")
print(f"Graph type: {graph.graph_type}")
print(f"Nodes: {len(graph.nodes)}")
print(f"Edges: {len(graph.edges)}")
print(f"Layout: {graph.layout}")

Generate Diagram

Generates a DOT format diagram for Graphviz:

config = DiagramConfig(
    diagram_type="dependency",
    include_labels=True,
    include_edges=True,
    style="dot"
)
diagram = visualizer.generate_diagram(config)
print(diagram)

Generate Dependency Tree

Generates a text-based dependency tree for a file:

tree = visualizer.generate_dependency_tree("my_module.py")
print(tree)

Data Structures

GraphVisualization

Represents a graph visualization:

  • graph_type: Type of graph (call, inheritance, knowledge)
  • nodes: List of node dictionaries
  • edges: List of edge dictionaries
  • layout: Graph layout algorithm (dot, neato, etc.)

DiagramConfig

Configuration for diagram generation:

  • diagram_type: Type of diagram to generate
  • include_labels: Whether to include node labels
  • include_edges: Whether to include edges
  • style: Diagram style

Integration

WorkspaceService

from novacoder.workspace.service import WorkspaceService

service = WorkspaceService()
service.initialize()
visualizer = service.code_visualizer

Web API

GET /api/workspace/visualize?graph_type=call

CLI

novacoder code visualize call

Features

  • Multiple Graph Types: Supports call, inheritance, and knowledge graphs
  • DOT Format: Generates Graphviz-compatible DOT output
  • Dependency Trees: Text-based dependency visualization
  • Configurable Layouts: Supports different graph layout algorithms
  • Error Handling: Gracefully handles non-existent files

Graph Types

  • call: Function call graph
  • inheritance: Class inheritance hierarchy
  • knowledge: Knowledge graph relationships

Example Output

graph = visualizer.visualize_graph("call")
# Returns:
# GraphVisualization(
#     graph_type="call",
#     nodes=[{"id": "func1", "label": "func1"}],
#     edges=[{"source": "func1", "target": "func2"}],
#     layout="dot"
# )

Source: wiki/workspace-visualization.md · rendered 2026-11-10