Index-based solution was already falling apart, this is a much cleaner approach and maps better to visualization code, not just for the charming
crate but potentially graphviz and similar programs.
Q3Z6XMP5FFCC3PWC5FSV4C6ICNDPMKMELOV7MYQGC5A42LVHGVPAC
use cargo_metadata::{Node, PackageId};
use charming::{
series::{Graph, GraphCategory, GraphData, GraphLayout, GraphLink, GraphNode},
Chart, HtmlRenderer,
use cargo_metadata::{Node, Package, PackageId};
use charming::{Chart, HtmlRenderer};
use petgraph::{
data::{Element, FromElements},
Graph,
let mut node_index = HashMap::with_capacity(resolve.nodes.len());
for node in &resolve.nodes {
let insertion_result = node_index.insert(&node.id, node);
// Make sure we didn't overwrite any existing entries
assert!(insertion_result.is_none());
let edge_count = resolve.nodes.iter().map(|node| node.deps.len()).count();
let mut dependency_tree = Graph::with_capacity(metadata.packages.len(), edge_count);
let mut node_indexes = HashMap::new();
for node in &metadata.packages {
let node_index = dependency_tree.add_node(&node.id);
node_indexes.insert(&node.id, node_index);
}
for resolved_dependency in &resolve.nodes {
let parent_index = node_indexes.get(&resolved_dependency.id).unwrap();
for child in &resolved_dependency.deps {
let child_index = node_indexes.get(&child.pkg).unwrap();
dependency_tree.add_edge(*parent_index, *child_index, 1);
}
petgraph = "0.6.4"
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"