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

Allow plot tooltip to show extra columns #9800

Merged
merged 11 commits into from
Nov 2, 2024

Conversation

aliabid94
Copy link
Collaborator

@aliabid94 aliabid94 commented Oct 22, 2024

If tooltip="all", will show all columns for a datapoint, not just the axis column names
Screenshot 2024-10-22 at 11 52 35 AM

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 22, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/dc1545193da353c9599980bb0648a2b058eb4e44/gradio-5.4.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@dc1545193da353c9599980bb0648a2b058eb4e44#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/dc1545193da353c9599980bb0648a2b058eb4e44/gradio-client-1.7.1.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/dc1545193da353c9599980bb0648a2b058eb4e44/dist/lite.js""></script>

}
return obj;
});
if (tooltip == "all") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can't filter out "irrelevant" columns if tooltip == "all"

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 22, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/nativeplot minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Allow plot tooltip to show extra columns

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@@ -94,6 +95,7 @@ def __init__(
x_axis_labels_visible: Whether the x-axis labels should be visible. Can be hidden when many x-axis labels are present.
caption: The (optional) caption to display below the plot.
sort: The sorting order of the x values, if x column is type string/category. Can be "x", "y", "-x", "-y", or list of strings that represent the order of the categories.
tooltip: The tooltip to display when hovering on a point. "axis" shows the values for the axis columns, "all" shows all column values, and "none" shows no tooltips.
Copy link
Member

Choose a reason for hiding this comment

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

I think a better api would be to just let it take a list of column names. Often, dataframes will have a large number of irrelevant columns and I'm sure we'll get the request to be able to select specific columns to show in the tooltip

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok added support for passing list of column names

@@ -94,6 +95,7 @@ def __init__(
x_axis_labels_visible: Whether the x-axis labels should be visible. Can be hidden when many x-axis labels are present.
caption: The (optional) caption to display below the plot.
sort: The sorting order of the x values, if x column is type string/category. Can be "x", "y", "-x", "-y", or list of strings that represent the order of the categories.
tooltip: The tooltip to display when hovering on a point. "axis" shows the values for the axis columns, "all" shows all column values, and "none" shows no tooltips. Can also provide a list of strings representing columns to show in the tooltip.
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended behavior that the axes are always shown in the tooltip? If so let's mention it here in the docstring

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

lgtm @aliabid94. Just noting that the axes are always shown in the tooltip, even if not explicitly listed in the list of columns e.g. see this example:

import pandas as pd
import numpy as np
import gradio as gr

# Generate random data
np.random.seed(42)
dates = pd.date_range(start='2024-01-01', periods=30, freq='D')
data = {
    'Date': dates,
    'Value1': np.random.normal(100, 15, 30).cumsum(),
    'Value2': np.random.normal(50, 10, 30).cumsum()
}
df = pd.DataFrame(data)

with gr.Blocks() as demo:
    plot = gr.LinePlot(
        df,
        x="Date",
        y="Value1",
        title="Random Time Series Data",
        tooltip=["Value2"],
    )

demo.launch()

If this is intended behavior, let's make a note of it in the docstring

@aliabid94
Copy link
Collaborator Author

Yep its intended, added to docstring

@abidlabs
Copy link
Member

abidlabs commented Nov 2, 2024

Merging in for the release!

@abidlabs abidlabs merged commit d1cfe1e into main Nov 2, 2024
22 of 23 checks passed
@abidlabs abidlabs deleted the allow_tooltip_to_show_extra_columns branch November 2, 2024 02:00
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.

3 participants