@@ -92,18 +92,31 @@ def prepare_charts(self, context):
92
92
93
93
work_by_caregiver_role_and_type = get_total_minutes_by_role_and_work_type ()
94
94
95
- context [ " work_by_caregiver_role_and_type_chart" ] = px .histogram (
95
+ work_by_caregiver_role_and_type_chart = px .histogram (
96
96
work_by_caregiver_role_and_type ,
97
97
x = "role_name" ,
98
98
y = "total_minutes" ,
99
99
color = "work_type" ,
100
100
title = _ ("Work minutes by caregiver role and work type" ),
101
101
labels = {
102
102
"role_name" : _ ("Caregiver role" ),
103
- "total_minutes" : _ ("total minutes" ),
104
- "work_type" : _ ("Type of work " ),
103
+ "total_minutes" : _ ("Total minutes" ),
104
+ "work_type" : _ ("Work type " ),
105
105
},
106
- ).to_html ()
106
+
107
+ )
108
+
109
+ # Note: For correct localization, we need to remove the English text "sum of" from the
110
+ # y-axis label and hover template, as per the following comment.
111
+ # https://github.com/plotly/plotly.py/issues/2876#issuecomment-1111339561
112
+ #
113
+ # The feature request below asks for English texts to not be prepended
114
+ # to the axis label and hover template, which will hopefully obsolete the next lines of code.
115
+ # https://github.com/plotly/plotly.py/issues/3694
116
+ work_by_caregiver_role_and_type_chart .for_each_trace (lambda t : t .update (hovertemplate = t .hovertemplate .replace ("sum of " , "" )))
117
+ work_by_caregiver_role_and_type_chart .for_each_yaxis (lambda a : a .update (title_text = a .title .text .replace ("sum of " , "" )))
118
+
119
+ context ["work_by_caregiver_role_and_type_chart" ] = work_by_caregiver_role_and_type_chart .to_html ()
107
120
108
121
return context
109
122
0 commit comments