Skip to content

Commit c7cc03b

Browse files
authored
Merge pull request #2443 from pbalcer/bar-chart-adjustments
[benchmarks] adjust label and legend positions on bar charts
2 parents 7cd0443 + 79b6789 commit c7cc03b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

scripts/benchmarks/output_html.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,27 @@ def create_grouped_bar_charts(groups: list[ExplicitGroup]) -> list[BenchmarkChar
161161
if height > max_height:
162162
max_height = height
163163

164-
ax.text(rect.get_x() + rect.get_width()/2., height + 2,
164+
ax.text(rect.get_x() + rect.get_width()/2., height + 1,
165165
f'{res.value:.1f}',
166166
ha='center', va='bottom', fontsize=9)
167167

168168
tooltip_labels = [
169+
f"Date: {res.date.strftime('%Y-%m-%d %H:%M:%S')}\n"
169170
f"Run: {run}\n"
170171
f"Label: {res.label}\n"
171172
f"Value: {res.value:.2f} {res.unit}\n"
173+
f"Stddev: {res.stddev:.2f} {res.unit}\n"
172174
]
173175
tooltip = mpld3.plugins.LineHTMLTooltip(rect, tooltip_labels, css=tooltip_css())
174176
mpld3.plugins.connect(ax.figure, tooltip)
175177

178+
# normally we'd just set legend to be outside
179+
# the chart, but this is not supported by mpld3.
180+
# instead, we adjust the y axis to account for
181+
# the height of the bars.
182+
legend_height = len(group.runs) * 0.1
183+
ax.set_ylim(0, max_height * (1 + legend_height))
184+
176185
ax.set_xticks([])
177186
ax.grid(True, axis='y', alpha=0.2)
178187
ax.set_ylabel(f"Value ({group.metadata.unit})")
@@ -190,7 +199,7 @@ def create_grouped_bar_charts(groups: list[ExplicitGroup]) -> list[BenchmarkChar
190199
# this is a hack to get labels to show above the legend
191200
# we normalize the idx to transAxes transform and offset it a little.
192201
x_norm = (idx + 0.3 - ax.get_xlim()[0]) / (ax.get_xlim()[1] - ax.get_xlim()[0])
193-
ax.text(x_norm, 1.00, label,
202+
ax.text(x_norm, 1.03, label,
194203
transform=ax.transAxes,
195204
color='#666666')
196205

0 commit comments

Comments
 (0)