22
33import shutil
44import tempfile
5- from pathlib import Path
65
76import matplotlib
87import matplotlib .pyplot as plt
1110from rich import print
1211
1312from codesectools .sasts .all .sast import AllSAST
13+ from codesectools .utils import shorten_path
1414
1515## Matplotlib config
1616matplotlib .rcParams .update (
@@ -107,7 +107,7 @@ def __init__(self, project_name: str) -> None:
107107 def plot_overview (self ) -> Figure :
108108 """Generate an overview plot with stats by files, SAST tools, and categories."""
109109 fig , (ax1 , ax2 , ax3 ) = plt .subplots (1 , 3 , layout = "constrained" )
110- by_files = { Path ( k ). name : v for k , v in self .result .stats_by_files (). items ()}
110+ by_files = self .result .stats_by_files ()
111111 by_sasts = self .result .stats_by_sasts ()
112112 by_categories = self .result .stats_by_categories ()
113113
@@ -117,7 +117,7 @@ def plot_overview(self) -> Figure:
117117 list (by_files .items ()), key = lambda e : e [1 ]["count" ], reverse = True
118118 )
119119 for k , v in sorted_files [: self .limit ]:
120- X_files .append (k )
120+ X_files .append (shorten_path ( k ) )
121121 Y_files .append (v ["count" ])
122122
123123 COLORS_COUNT = {v : 0 for k , v in self .color_mapping .items ()}
@@ -130,11 +130,11 @@ def plot_overview(self) -> Figure:
130130 current_height = 0
131131 for color , height in COLORS_COUNT .items ():
132132 if height > 0 :
133- bars .append ((k , current_height + height , color ))
133+ bars .append ((shorten_path ( k ) , current_height + height , color ))
134134 current_height += height
135135
136- for k , height , color in bars [::- 1 ]:
137- ax1 .bar (k , height , color = color )
136+ for k_short , height , color in bars [::- 1 ]:
137+ ax1 .bar (k_short , height , color = color )
138138
139139 ax1 .set_xticks (X_files , X_files , rotation = 45 , ha = "right" )
140140 ax1 .set_title (f"Stats by files (limit to { self .limit } )" )
@@ -231,7 +231,7 @@ def plot_top_cwes(self) -> Figure:
231231 def plot_top_scores (self ) -> Figure :
232232 """Generate a stacked bar plot for files with the highest scores."""
233233 fig , ax = plt .subplots (1 , 1 , layout = "constrained" )
234- by_scores = { Path ( k ). name : v for k , v in self .result .stats_by_scores (). items ()}
234+ by_scores = self .result .stats_by_scores ()
235235
236236 for file , data in by_scores .items ():
237237 by_scores [file ]["total_score" ] = sum (data ["score" ].values ())
@@ -244,7 +244,7 @@ def plot_top_scores(self) -> Figure:
244244
245245 X_files , score_data = [], []
246246 for file , data in sorted_files [: self .limit ]:
247- X_files .append (file )
247+ X_files .append (shorten_path ( file ) )
248248 score_data .append (data ["score" ])
249249
250250 score_keys = score_data [0 ].keys ()
0 commit comments