Skip to content

Add support for labels on-hover for bar plots#13483

Open
eqbech wants to merge 1 commit intomainfrom
add-bar-types-to-gradient-plot
Open

Add support for labels on-hover for bar plots#13483
eqbech wants to merge 1 commit intomainfrom
add-bar-types-to-gradient-plot

Conversation

@eqbech
Copy link
Copy Markdown
Contributor

@eqbech eqbech commented May 5, 2026

Issue
Resolves #13474

Add support for on-hover labels for bar plots. PlotTools have been updated with a new method that takes care of on-hover labeling and its currently only supported for bar plots, but the template is outlined for different type of plots.

Math Func example

image

Egg example

image

Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/everest_gradients_plot.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/everest_gradients_plot.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 5, 2026

Codecov Report

❌ Patch coverage is 40.81633% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.92%. Comparing base (7aa972d) to head (9ff29b8).
⚠️ Report is 17 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rc/ert/gui/tools/plot/plottery/plots/plot_tools.py 31.42% 24 Missing ⚠️
...ools/plot/plottery/plots/everest_gradients_plot.py 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13483      +/-   ##
==========================================
- Coverage   89.95%   89.92%   -0.04%     
==========================================
  Files         459      460       +1     
  Lines       32173    32372     +199     
==========================================
+ Hits        28942    29111     +169     
- Misses       3231     3261      +30     
Flag Coverage Δ
cli-tests 37.17% <0.00%> (-0.16%) ⬇️
fuzz 44.05% <36.73%> (-0.10%) ⬇️
gui-tests 66.84% <40.81%> (+0.05%) ⬆️
performance-and-unit-tests 78.03% <40.81%> (+0.06%) ⬆️
test 45.61% <36.73%> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/ert/gui/tools/plot/plottery/plot_context.py 93.61% <100.00%> (+2.31%) ⬆️
...ools/plot/plottery/plots/everest_gradients_plot.py 16.39% <16.66%> (+0.32%) ⬆️
...rc/ert/gui/tools/plot/plottery/plots/plot_tools.py 72.88% <31.42%> (-17.71%) ⬇️

... and 16 files with indirect coverage changes

@eilskra
Copy link
Copy Markdown
Contributor

eilskra commented May 5, 2026

Ref skjermbildet, hva betyr det øverste totallet?

@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch 4 times, most recently from 49c1688 to bc27452 Compare May 6, 2026 06:31
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 6, 2026

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing add-bar-types-to-gradient-plot (36fa2c5) with main (beb9d13)

Open in CodSpeed

@eilskra
Copy link
Copy Markdown
Contributor

eilskra commented May 6, 2026

I would add f"value: {val:.3g}" to the value to prevent large numbers. The values can become really big

@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch from bc27452 to b23a469 Compare May 6, 2026 08:04
Comment thread src/ert/gui/tools/plot/plottery/plot_context.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch from b23a469 to b94dc64 Compare May 6, 2026 08:22
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
Comment thread src/ert/gui/tools/plot/plottery/plots/plot_tools.py Outdated
@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch from b94dc64 to f158ee0 Compare May 6, 2026 10:03
@eqbech
Copy link
Copy Markdown
Contributor Author

eqbech commented May 6, 2026

Added label to appear on cursor hover position!

@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch 2 times, most recently from 60a822f to c5a3c79 Compare May 6, 2026 10:09
Comment on lines +208 to +218
for bar_container_idx, bars in enumerate(data[0]):
for bar_idx, bar in enumerate(bars):
if bar.contains(event)[0]:
value = bar.get_height()

hover_box.xy = (event.xdata, event.ydata) # type: ignore
idx = bar_idx * len(data[0]) + bar_container_idx
hover_box.set_text(f"{data[1][idx]}\nValue: {value:.3g}")
hover_box.set_visible(True)
figure.canvas.draw_idle()
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this tuple passed into this function, the use of data[0] and data[1] hides the content, making this a bit harder for the reader to understand what is going on.

Can we combine and create this up front instead? Thus avoiding much of the logic later on?

bar_label_pairs: list[tuple[Rectangle, str]] = []
 
 for i, control in enumerate(self.selected_controls):
     color = colors[i % len(colors)][0]
     values = []
     for batch_id in batch_ids:
         batch_data = combined[combined["batch_id"] == batch_id]
         match = batch_data[batch_data["control_name"] == control]
         values.append(
             match[response_key].to_numpy()[0] if not match.empty else 0.0
         )
 
     offsets = pos + (i - n_controls / 2) * bar_width + bar_width / 2
 
     bars = axes.bar(
         offsets,
         values,
         width=bar_width,
         color=color,
         alpha=0.7,
     )
     config.addLegendItem(control, bars[0])
 
     for batch_id, bar in zip(batch_ids, bars):
         bar_label_pairs.append((bar, f"batch {batch_id}\n{control}"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is clunky as it is now, im also thinking we might do something like this for the function signature of labels_on_hover

@staticmethod
def labels_on_hover(
    axes: Axes,
    plot_context: PlotContext,
    figure: Figure,
    **kwargs
) -> None:

As we dont yet know exactly what data the different plot types require and that they will most likely differ.

@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch 2 times, most recently from a2ea499 to 36fa2c5 Compare May 6, 2026 12:43
@eqbech
Copy link
Copy Markdown
Contributor Author

eqbech commented May 6, 2026

Screen.Recording.2026-05-06.at.15.19.48.mov

@jaakson
Copy link
Copy Markdown

jaakson commented May 6, 2026

Screen.Recording.2026-05-06.at.15.19.48.mov

This looks good to me, with a couple of nitpicky comment-questions:

  • If the pink background tint for the hover_box was not chosen for some specific reason (is it?), I propose swapping it out either for a tint that matches the hovered bar or a white tint (which improves legibility). If there is any possibility of really dark colours being used for the bars in the future, then a white tint is the way to go, imo.
  • Can we do anything to lengthen the "hit area" around really short bars? My guess is users might be frustrated if they can only see a tooltip if they manage to hover over the tiny handful of pixels over/under the x axis.

@eqbech eqbech force-pushed the add-bar-types-to-gradient-plot branch from 36fa2c5 to 9ff29b8 Compare May 6, 2026 13:53
@eqbech
Copy link
Copy Markdown
Contributor Author

eqbech commented May 6, 2026

Screen.Recording.2026-05-06.at.15.19.48.mov

This looks good to me, with a couple of nitpicky comment-questions:

  • If the pink background tint for the hover_box was not chosen for some specific reason (is it?), I propose swapping it out either for a tint that matches the hovered bar or a white tint (which improves legibility). If there is any possibility of really dark colours being used for the bars in the future, then a white tint is the way to go, imo.
  • Can we do anything to lengthen the "hit area" around really short bars? My guess is users might be frustrated if they can only see a tooltip if they manage to hover over the tiny handful of pixels over/under the x axis.

Great Feedback!

I tried changing color from "pink" to "white". I guess its also possible to be more precise by using RGBA if needed. Regarding the "hit area" i agree. We do have a zoom functionality for the plots that may help with this. I think implementing "lengthening" of the bars can be a bit cumbersome. Attached is a screenshot of the smallest bar zoomed in, as well as the new color implemented!

image

@jaakson
Copy link
Copy Markdown

jaakson commented May 6, 2026

Attached is a screenshot of the smallest bar zoomed in, as well as the new color implemented!

That looks great! I forgot about the zoom -- that's sufficient, then, no need to mess around with hover hit zones then. 😄

(And I think RGBA would maybe just obfuscate things if we can otherwise go with "white", which is readable to everyone.)

@SAKavli
Copy link
Copy Markdown
Contributor

SAKavli commented May 7, 2026

I support the color change 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tool-tip/other mouse-hover functionality to Everest Plots

7 participants