-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: improve visualize graph #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds richer/cleaner visualize output options by moving console renderers into the ProjectGraph library, improving Mermaid output determinism, and updating CLI behavior/tests accordingly.
Changes:
- Add new
flatandtreegraph renderers inProjGraph.Lib.ProjectGraph.Renderingand select renderer by--format. - Improve Mermaid output with optional title front-matter and deterministic ordering for projects/dependencies.
- Update CLI defaults/examples and adjust integration/unit tests for the new formats and default behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ProjGraph.Tests.Unit.ProjectGraph/MermaidGraphRendererTests.cs | Adds assertions for Mermaid title front-matter and ordering. |
| tests/ProjGraph.Tests.Integration.Cli/VisualizeCommandTests.cs | Updates format-related tests and changes default format expectation to Mermaid. |
| src/ProjGraph.Lib.ProjectGraph/Rendering/TreeGraphRenderer.cs | New Spectre.Console-based hierarchical tree renderer returning a string. |
| src/ProjGraph.Lib.ProjectGraph/Rendering/FlatGraphRenderer.cs | New Spectre.Console-based flat list renderer returning a string. |
| src/ProjGraph.Lib.ProjectGraph/Rendering/SolutionGraphRendererBase.cs | New shared base for Spectre.Console renderers (writer/console, cycle helpers). |
| src/ProjGraph.Lib.ProjectGraph/Rendering/MermaidGraphRenderer.cs | Adds title front-matter and sorts projects/dependencies by name. |
| src/ProjGraph.Lib.ProjectGraph/DependencyInjection.cs | Registers multiple renderers and exposes them via IEnumerable<IDiagramRenderer<SolutionGraph>>. |
| src/ProjGraph.Cli/Commands/VisualizeCommand.cs | Switches to renderer selection by format and changes default format to Mermaid. |
| src/ProjGraph.Cli/Program.cs | Updates CLI examples (visualize/tree example; classdiagram depth example). |
| src/ProjGraph.Cli/Rendering/TreeRenderer.cs | Removes old CLI-only static renderer (moved into library as instance renderers). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var sortedDependencies = graph.Dependencies | ||
| .Select(d => new | ||
| { | ||
| sb.AppendLine($" {SanitizeId(source.Name)} --> {SanitizeId(target.Name)}"); | ||
| } | ||
| Source = graph.Projects.FirstOrDefault(p => p.Id == d.SourceId), | ||
| Target = graph.Projects.FirstOrDefault(p => p.Id == d.TargetId) | ||
| }) | ||
| .Where(d => d.Source != null && d.Target != null) | ||
| .OrderBy(d => d.Source!.Name) | ||
| .ThenBy(d => d.Target!.Name); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependency sorting currently does a graph.Projects.FirstOrDefault(...) lookup for every dependency, which is O(E*V) and can become expensive on large solutions. Consider building a Dictionary<Guid, Project> once (Id->Project) and resolving Source/Target via dictionary lookups before ordering.
src/ProjGraph.Lib.ProjectGraph/Rendering/MermaidGraphRenderer.cs
Outdated
Show resolved
Hide resolved
| var dependencies = graph.Dependencies | ||
| .Where(d => d.SourceId == project.Id) | ||
| .Select(d => graph.Projects.FirstOrDefault(p => p.Id == d.TargetId)) | ||
| .Where(p => p != null) | ||
| .OrderBy(p => p!.Name) | ||
| .ToList(); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RenderDependencies resolves dependency projects via graph.Projects.FirstOrDefault(...) for each edge, which is O(E*V) overall. Consider precomputing an Id->Project dictionary (and optionally per-project dependency lists) once per Render() to avoid repeated linear scans.
| foreach (var project in graph.Projects.OrderBy(p => p.Name)) | ||
| { |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Project/dependency ordering uses the default string comparer (culture-sensitive). Since the output order is now asserted in tests and is meant to be deterministic, consider ordering with a specific comparer (e.g., StringComparer.Ordinal) to avoid locale-dependent differences across environments.
No description provided.