@@ -47,15 +47,31 @@ def run(self):
4747 en = {module : ModuleStats (total = stats ['total' ], translated = stats ['total' ], fuzzy = stats ['total' ], untranslated = 0 , percentage = 100 ) for module , stats in next (iter (data .values ())).items ()}
4848 data = {'en' : en } | data
4949
50- # extract data to plot
50+ # Calculate average completion percentage for each locale and sort locales
51+ locale_completion = {locale : np .mean ([stats ['percentage' ] for stats in loc_stats .values ()]) for locale , loc_stats in data .items ()}
52+ sorted_locales = sorted (locale_completion .keys (), key = lambda locale : locale_completion [locale ], reverse = True )
53+
54+ # Reorder data based on sorted locales
55+ data = {locale : data [locale ] for locale in sorted_locales }
56+
57+ # Update locales list after sorting
5158 locales = list (data .keys ())
52- modules = list (data [locales [- 1 ]].keys ())
59+ modules = list (next (iter (data .values ())).keys ())
60+
61+ # Extract data to plot
5362 values = [[stats ['percentage' ] for stats in loc_stats .values ()] for loc_stats in data .values ()]
5463 hoverdata = [[{'module' : module } | stats for module , stats in loc_stats .items ()] for loc_stats in data .values ()]
64+
65+ # Add text to display percentages directly in the heatmap boxes
66+ text = [[f"{ int (stats ['percentage' ])} %" for stats in loc_stats .values ()] for loc_stats in data .values ()]
67+
5568 heatmap = go .Heatmap (
56- x = modules ,
69+ x = modules ,
5770 y = locales ,
5871 z = values ,
72+ text = text , # Add text to the heatmap
73+ texttemplate = "%{text}" , # Format the text to display directly
74+ textfont = {"size" : 10 }, # Adjust font size for better readability
5975 xgap = 5 ,
6076 ygap = 5 ,
6177 customdata = np .array (hoverdata ),
@@ -67,8 +83,18 @@ def run(self):
6783 "yref" : "container" ,
6884 "title" : "Completion %" ,
6985 "thickness" : 10 ,
86+ "tickvals" : [12.5 , 50 , 87.5 , 100 ], # Midpoints for each category
87+ "ticktext" : ["0-25%" , "25-75%" , "75-<100%" , "100%" ], # Labels for categories
7088 },
71- colorscale = "Plotly3" ,
89+ colorscale = [
90+ [0.0 , "rgb(254, 255, 231)" ], # 0-25%
91+ [0.25 , "rgb(254, 255, 231)" ],
92+ [0.25 , "rgb(187, 130, 176)" ], # 25-75%
93+ [0.75 , "rgb(187, 130, 176)" ],
94+ [0.75 , "rgb(129, 192, 170)" ], # 75-<100%
95+ [0.99 , "rgb(129, 192, 170)" ],
96+ [1.0 , "rgb(0, 128, 0)" ], # 100%
97+ ],
7298 )
7399 # Create figure
74100 fig = go .Figure (data = heatmap )
@@ -82,7 +108,6 @@ def run(self):
82108 xaxis_tickangle = - 45 ,
83109 xaxis_tickfont = {
84110 "family" : "var(--bs-font-monospace)" ,
85- "color" : "#fff"
86111 },
87112 yaxis_showgrid = False ,
88113 yaxis_title = "Locale" ,
0 commit comments