Skip to content

Commit 1b0fdfe

Browse files
committed
Remove auto-generated English text from label and hover
Related to plotly/plotly.py#2876 (comment) Related to plotly/plotly.py#3694
1 parent 3cc1976 commit 1b0fdfe

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

project/work/views.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,31 @@ def prepare_charts(self, context):
9292

9393
work_by_caregiver_role_and_type = get_total_minutes_by_role_and_work_type()
9494

95-
context["work_by_caregiver_role_and_type_chart"] = px.histogram(
95+
work_by_caregiver_role_and_type_chart = px.histogram(
9696
work_by_caregiver_role_and_type,
9797
x="role_name",
9898
y="total_minutes",
9999
color="work_type",
100100
title=_("Work minutes by caregiver role and work type"),
101101
labels={
102102
"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"),
105105
},
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()
107120

108121
return context
109122

0 commit comments

Comments
 (0)