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

Custom hover labels for plot x/y values #933

Closed
isegal opened this issue Dec 6, 2021 · 0 comments
Closed

Custom hover labels for plot x/y values #933

isegal opened this issue Dec 6, 2021 · 0 comments

Comments

@isegal
Copy link
Contributor

isegal commented Dec 6, 2021

Currently, it is possible to customize the name of the line graph, but x and y coordinate names for hovering over the plot is not customizable. When hovering over a plot line, the user will always see

<name>
x = 123
y = 234

This is a request to add a set of api functions to be able to customize how the hover text gets displayd in the plot graph.

For example, the user may want to label x axis as time and y axis as percent or cost or another metric.

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

One option is to allow the user to add a custom closure that takes the plot name and Value as input and returns a formatted string of how the values are to be displayed.

Plot::new("my_plot")
    .custom_label_func(|name, value| {
        if let Some(name) = name {
            format!("{}: {:.*}%", name, 1, value.y).to_string()
        } else {
            "CPU".to_string()
        }
    })
    .show(ui, |plot_ui| plot_ui.line(line));

This would allow relabeling x and y and display a custom formatted string for the hover values.

Describe alternatives you've considered
Considered adding x and y names, but this removes some flexibility on how the hover would be displayd.

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

No branches or pull requests

2 participants