Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[benchmarks] adjust label and legend positions on bar charts #2443

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions scripts/benchmarks/output_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,27 @@ def create_grouped_bar_charts(groups: list[ExplicitGroup]) -> list[BenchmarkChar
if height > max_height:
max_height = height

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

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

# normally we'd just set legend to be outside
# the chart, but this is not supported by mpld3.
# instead, we adjust the y axis to account for
# the height of the bars.
legend_height = len(group.runs) * 0.1
ax.set_ylim(0, max_height * (1 + legend_height))

ax.set_xticks([])
ax.grid(True, axis='y', alpha=0.2)
ax.set_ylabel(f"Value ({group.metadata.unit})")
Expand All @@ -190,7 +199,7 @@ def create_grouped_bar_charts(groups: list[ExplicitGroup]) -> list[BenchmarkChar
# this is a hack to get labels to show above the legend
# we normalize the idx to transAxes transform and offset it a little.
x_norm = (idx + 0.3 - ax.get_xlim()[0]) / (ax.get_xlim()[1] - ax.get_xlim()[0])
ax.text(x_norm, 1.00, label,
ax.text(x_norm, 1.03, label,
transform=ax.transAxes,
color='#666666')

Expand Down
Loading