Hi there,
I am using this solution to populate stylized tooltips since the styling options on the SVG/path hover-templates don’t offer box-shadow, border-radius, etc.
@callback(
Output("some_graphical_figure_bullshit_graph_tooltip", "show"),
Output("some_graphical_figure_bullshit_graph_tooltip", "bbox"),
Output("some_graphical_figure_bullshit_graph_tooltip", "children"),
# get click input
Input("some_graphical_figure_bullshit", "clickData"),
Input("some_graphical_figure_bullshit", "hoverData"),
)
def display_hover(clickData, hoverData):
try:
pt = hoverData["points"][0]
except:
return False, {}, None
bbox = pt["bbox"]
num = pt["pointNumber"]
df_row = real_df.iloc[num]
img_src = df_row["id"]
img_ext = df_row["img_ext"]
img = f"assets/icons/{img_src}.{img_ext}" # <---------------------- the image
name = df_row["Token"]
form = df_row["Platform"]
price = df_row["Price [USD]"]
if hoverData is None or hoverData["points"] == []:
return False, no_update, no_update
tooltip = [
html.Div(
[
html.Img(
src=img, # <---------------------- the image going into the tooltip
style={"width": "80px", "border-radius": "50%"},
),
html.H3(
f"{name}",
style={"color": "#192437", "font-family": "ProductSans-Black"},
),
html.P(f"{form}"),
html.P(f"{price:.0f}"),
],
style={
"width": "225px",
"white-space": "normal",
"padding": "5px",
"display": "flex",
"flex-direction": "column",
"align-items": "left",
"justify-content": "center",
},
)
]
return True, bbox, tooltip
I’m including minimal code here to show that there is an image being searched for, some data is selected from an available pandas df, and the tooltip is constructed… nothing too fancy… the assets folder is 13,427 images/logos deep, 250x250.
As I hover across the chart, I get the images to load, but I’m suspecting that getting the images (searching through a few thousand) is taking a relatively long time. In the gif, below, you can see the lag as one “sweeps” across. It gives a laggy feeling.
How would one go about speeding this up? Should I load all several thousand images as base64s into a Storage item? Or just file locally? Ideally, the solution would make the callback-driven tooltip pop-up with the same speed and fluidity as the built-in hovertext that’s generated with SVG elements… (maybe I’m asking too much?).
Thank you <3