Learn R Programming

softwareRisk (version 0.1.0)

plot_top_paths_fun: Plot the top risky call paths on a Sugiyama layout

Description

Visualizes the most risky entry-to-sink paths (by decreasing path_risk_score) computed by all_paths_fun(). Edges that occur on the top paths are highlighted, with edge colour mapped to the mean path risk and edge width mapped to the number of top paths using that edge. Nodes on the top paths are emphasized, with node size mapped to in-degree and node fill mapped to binned cyclomatic complexity.

Usage

plot_top_paths_fun(
  graph,
  all_paths_out,
  model.name = "",
  language = "",
  top_n = 10,
  alpha_non_top = 0.05
)

Value

A ggplot object (invisibly). The plot is also printed as a side effect.

Arguments

graph

A directed tidygraph::tbl_graph representing the call graph to plot (typically the same graph used as input to all_paths_fun()).

all_paths_out

Output from all_paths_fun(), i.e. a list with elements nodes and paths. For backward compatibility, a paths tibble can also be supplied directly; in that case node metrics are derived from graph where possible.

model.name

Character scalar used in the plot title (e.g., model name).

language

Character scalar used in the plot title (e.g., language name).

top_n

Integer. Number of highest-risk paths to display (default 10).

alpha_non_top

Numeric in $$[0, 1]$$. Alpha (transparency) for edges that are not on the top-risk paths. Smaller values fade background edges more.

Details

The function selects the top_n paths by sorting paths_tbl on path_risk_score (descending). For those paths, it:

  • builds an edge list from path_nodes,

  • marks graph edges that appear on at least one top path,

  • computes path_freq (how many top paths include each edge),

  • computes risk_mean_path (mean of risk_sum across top paths that include each edge),

  • highlights nodes that appear on any top path.

Node fills are based on cyclomatic_complexity using breaks (-Inf, 10], (10, 20], (20, 50], (50, Inf] as per Watson & McCabe (1996).

This function relies on external theming/label objects theme_AP() and lab_expr being available in the calling environment or package namespace.

References

Watson, A. H. and McCabe, T. J. (1996). Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric. NIST Special Publication 500-235, National Institute of Standards and Technology, Gaithersburg, MD. doi:10.6028/NIST.SP.500-235

Examples

Run this code
data(synthetic_graph)
out <- all_paths_fun(graph = synthetic_graph, alpha = 0.6, beta = 0.3,
gamma = 0.1, complexity_col = "cyclo")
p <- plot_top_paths_fun(synthetic_graph, out, model.name = "MyModel", language = "R", top_n = 10)
p

Run the code above in your browser using DataLab