Move visualization logic into separate module

finchie
Apr 23, 2024, 5:04 AM
C43IWI7GMF6UEKGTXTK4GSQLAFD2SH6BKQRGR4ZQNITYSUK6RMXAC

Dependencies

  • [2] OPTMCUTB Use timings `duration` to set size of rendered node
  • [3] 475UXTLY Use multiple force-directed layout algorithms to improve graph readability
  • [4] B2L26LOA Store index of dependency nodes
  • [5] JVYWRCPT Add basic chart visualisation
  • [6] Q3Z6XMP5 Migrate dependency tree to `petgraph::Graph`
  • [7] UXJFRBBL Move graph functionality into `graph` module
  • [8] UQJO24KB Use `forceatlas2` to construct graph layout
  • [9] 7CVIL7UJ Create simple metadata parser
  • [10] ZPFD3275 Switch from `cargo_metadata`+`petgraph` to `guppy`
  • [11] LOR3KOXG Parse JSON output from `cargo build --timings`

Change contents

  • file addition: visualize (d--r------)
    [4.15]
  • file addition: mod.rs (----------)
    [0.21]
    use crate::timings;
    use charming::series::{GraphLayoutForce, Series};
    use charming::{series, Chart, HtmlRenderer};
    use guppy::graph::PackageGraph;
    mod graph;
    #[derive(Clone, Copy, Debug)]
    pub enum Style {
    Graph,
    }
    pub fn for_style(style: Style, graph: &PackageGraph, timings: &timings::Output) {
    let series: Series = match style {
    Style::Graph => {
    series::Graph::new()
    // Use charming's force-directed layout, in combination with
    // `graph::layout()` using `forceatlas2`, as they seem to get the best results
    // when used together.
    .layout(charming::series::GraphLayout::Force)
    .force(GraphLayoutForce::new().layout_animation(false))
    .roam(true)
    .data(graph::data(graph, timings))
    .into()
    }
    };
    let chart = Chart::new().series(series);
    let mut renderer = HtmlRenderer::new("Cargo dependencies", 1000, 800);
    renderer.save(&chart, "/tmp/chart.html").unwrap();
    }
  • file move: graph.rs (----------)graph.rs (----------)
    [0.21]
    [4.146]
  • edit in src/main.rs at line 1
    [4.49][3.0:63]()
    use charming::{series::GraphLayoutForce, Chart, HtmlRenderer};
  • edit in src/main.rs at line 3
    [4.2712][4.52:63]()
    mod graph;
  • edit in src/main.rs at line 4
    [4.2725]
    [4.1077]
    mod visualize;
  • replacement in src/main.rs at line 14
    [4.897][4.1299:1336](),[4.1336][4.1275:1314](),[4.1314][4.1357:1397](),[4.1357][4.1357:1397](),[4.1397][3.64:389](),[3.389][4.1436:1460](),[4.1372][4.1436:1460](),[4.1436][4.1436:1460](),[4.1460][2.182:240](),[4.112][4.1499:1636](),[2.240][4.1499:1636](),[4.1336][4.1499:1636](),[4.1417][4.1499:1636](),[4.1499][4.1499:1636]()
    let chart = Chart::new().series(
    charming::series::Graph::new()
    .name("Cargo dependencies")
    // Use charming's force-directed layout, in combination with
    // `graph::layout()` using `forceatlas2`, as they seem to get the best results
    // when used together.
    .layout(charming::series::GraphLayout::Force)
    .force(GraphLayoutForce::new().layout_animation(false))
    .roam(true)
    .data(graph::data(&package_graph, &timings)),
    );
    let mut renderer = HtmlRenderer::new("Cargo dependencies", 1000, 800);
    renderer.save(&chart, "/tmp/chart.html").unwrap();
    [4.897]
    [4.924]
    visualize::for_style(visualize::Style::Graph, &package_graph, &timings);