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

Label bars with their values #269

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
38 changes: 36 additions & 2 deletions lib/yjit-metrics/report_types/bloggable_speed_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
# Set up the top legend with coloured boxes and Ruby config names
top_legend_box_height = 0.032
top_legend_box_width = 0.12
top_legend_text_height = 0.015
text_height = 0.015

top_legend_item_width = plot_effective_width / n_configs
n_configs.times do |config_idx|
Expand Down Expand Up @@ -466,7 +466,7 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
end
svg.text @configs_with_human_names[config_idx][0],
x: ratio_to_x(item_center_x),
y: ratio_to_y(item_center_y + 0.5 * top_legend_text_height),
y: ratio_to_y(item_center_y + 0.5 * text_height),
font_size: font_size,
text_anchor: "middle",
font_weight: "bold",
Expand Down Expand Up @@ -510,6 +510,7 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
bar_data.last[:bars] << {
value: bar_height_ratio,
fill: ruby_config_bar_colour[config],
label: sprintf("%.2f", relative_value),
tooltip: tooltip_text,
stddev_ratio: stddev_ratio,
}
Expand All @@ -532,6 +533,7 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
{
value: value / max_value,
fill: ruby_config_bar_colour[config],
label: sprintf("%.2f", value),
tooltip: sprintf("%.2fx baseline (%s)", value, ruby_human_names[index]),
}
end.compact,
Expand All @@ -542,6 +544,8 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
num_groups = bar_data.size
bar_width = plot_width / (num_groups + bar_data.map { |x| x[:bars].size }.sum + 1)

bar_labels = []

# Start at the y-axis.
left = plot_left_edge
bar_data.each.with_index do |data, group_index|
Expand All @@ -563,6 +567,14 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
fill: bar[:fill],
data_tooltip: bar[:tooltip]

if bar[:label]
bar_labels << {
x: bar_left + 0.004,
y: bar_top - 0.01,
text: bar[:label],
}
end

if bar[:stddev_ratio]&.nonzero?
# Whiskers should be centered around the top of the bar, at a distance of one stddev.
stddev_top = bar_top - bar[:stddev_ratio] * plot_effective_height
Expand Down Expand Up @@ -618,6 +630,28 @@ def svg_object(relative_values_by_config_and_benchmark, benchmarks: @benchmark_n
# Horizontal line for baseline of CRuby at 1.0.
svg.line x1: ratio_to_x(plot_left_edge), y1: ratio_to_y(baseline_y), x2: ratio_to_x(plot_right_edge), y2: ratio_to_y(baseline_y), stroke: baseline_colour, "stroke-width": baseline_strokewidth

# Do value labels last so that they are above bars, variance whiskers, etc.
bar_labels.each do |label|
text_length = ratio_to_x(0.02)
svg.rect \
x: ratio_to_x(label[:x]),
y: ratio_to_y(label[:y] - 0.9 * text_height),
width: text_length,
height: ratio_to_y(text_height),
transform: "rotate(-60, #{ratio_to_x(label[:x] + (bar_width * 0.5))}, #{ratio_to_y(label[:y])})",
**Theme.bar_text_background_attrs

svg.text label[:text],
x: ratio_to_x(label[:x]),
y: ratio_to_y(label[:y]),
fill: Theme.text_color,
font_size: "x-small",
text_anchor: "start",
textLength: text_length,
transform: "rotate(-60, #{ratio_to_x(label[:x] + (bar_width * 0.5))}, #{ratio_to_y(label[:y])})",
**Theme.bar_text_attrs
end

svg
end

Expand Down
6 changes: 6 additions & 0 deletions theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ legend_box_attrs:
legend_text_attrs:
style: "text-shadow: 0 0 1px #000;"

bar_text_attrs:
style: "text-shadow: 0 0 1px #fff;"

bar_text_background_attrs:
fill: "#fff8"

stddev_marker_attrs:
stroke-dasharray: "1,0.5"
stroke: "#333c"
Loading