-
Notifications
You must be signed in to change notification settings - Fork 150
Add visualize
command
#262
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f615964
Add method to load all graphs for a file or directory
hendrikvanantwerpen 235ffa2
Add command to visualize graph
hendrikvanantwerpen db1ddc9
Include paths in visualize command
hendrikvanantwerpen 2998319
Add note about limitations
hendrikvanantwerpen 230c1ae
Update d3 and d3-dag files to new versions
hendrikvanantwerpen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// -*- coding: utf-8 -*- | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright © 2023, stack-graphs authors. | ||
// Licensed under either of Apache License, Version 2.0, or MIT license, at your option. | ||
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details. | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
use clap::Args; | ||
use clap::ValueHint; | ||
use stack_graphs::serde::NoFilter; | ||
use stack_graphs::stitching::Database; | ||
use stack_graphs::storage::SQLiteReader; | ||
use stack_graphs::NoCancellation; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
/// Visualize database | ||
#[derive(Args)] | ||
#[clap(after_help = r#"LIMITATIONS: | ||
Visualizations will only work for very small stack graphs. This command is | ||
useful for debugging minimal examples, but running it on any real-world code | ||
will most likely result in HTML files that will not load in any browser. | ||
"#)] | ||
pub struct VisualizeArgs { | ||
/// Source file or directory paths. | ||
#[clap( | ||
value_name = "SOURCE_PATH", | ||
value_hint = ValueHint::AnyPath, | ||
)] | ||
pub source_paths: Vec<PathBuf>, | ||
|
||
#[clap( | ||
long, | ||
short = 'o', | ||
value_name = "OUTPUT_PATH", | ||
value_hint = ValueHint::AnyPath, | ||
default_value = "stack-graph.html", | ||
)] | ||
pub output: PathBuf, | ||
} | ||
|
||
impl VisualizeArgs { | ||
pub fn run(self, db_path: &Path) -> anyhow::Result<()> { | ||
let cancellation_flag = &NoCancellation; | ||
let mut db = SQLiteReader::open(&db_path)?; | ||
for source_path in &self.source_paths { | ||
let source_path = source_path.canonicalize()?; | ||
db.load_graph_for_file_or_directory(&source_path, cancellation_flag)?; | ||
} | ||
let (graph, _, _) = db.get(); | ||
let starting_nodes = graph | ||
.iter_nodes() | ||
.filter(|n| graph[*n].is_reference()) | ||
.collect::<Vec<_>>(); | ||
let mut complete_paths_db = Database::new(); | ||
db.find_all_complete_partial_paths(starting_nodes, cancellation_flag, |g, ps, p| { | ||
complete_paths_db.add_partial_path(g, ps, p.clone()); | ||
})?; | ||
let (graph, partials, _) = db.get(); | ||
let html = | ||
graph.to_html_string("stack-graph", partials, &mut complete_paths_db, &NoFilter)?; | ||
if let Some(dir) = self.output.parent() { | ||
std::fs::create_dir_all(dir)?; | ||
} | ||
std::fs::write(&self.output, html)?; | ||
println!("Visualization at {}", self.output.display()); | ||
Ok(()) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thank you for including this help text.