[Bug] HexagonLayer has a bug on tooltips
Description
When using "HexagonLayer" of Pydeck, tooltips always return "undefined" when you put in the tooltips a variable that is on the data, such as:
tooltip = {
"html": "<b>{variable_onmydataframe}</b>",
}
The problem disappears if you change to "ColumnLayer", for example.
Flavors
- [ ] Script tag
- [ ] React
- [X] Python/Jupyter notebook
- [ ] MapboxOverlay
- [ ] GoogleMapsOverlay
- [ ] CartoLayer
- [ ] ArcGIS
Expected Behavior
Tooltips should return the variable you put in them, such as when you run "ColumnLayer":
Instead they return undefined if you run "HexagonLayer"
Steps to Reproduce
Sample code provided by TYL on this link of stackoverflow.
import pandas as pd
import pydeck as pdk
DATA_URL = "https://raw.githubusercontent.com/ajduberstein/geo_datasets/master/housing.csv"
df = pd.read_csv(DATA_URL)
view = pdk.data_utils.compute_view(df[["lng", "lat"]])
view.pitch = 75
view.bearing = 60
column_layer = pdk.Layer(
"ColumnLayer",
data=df,
get_position=["lng", "lat"],
get_elevation="price_per_unit_area",
elevation_scale=100,
radius=50,
get_fill_color=["mrt_distance * 10", "mrt_distance", "mrt_distance * 10", 140],
pickable=True,
auto_highlight=True,
)
hexagon_layer = pdk.Layer(
"HexagonLayer",
data=df,
get_position=["lng", "lat"],
get_elevation="price_per_unit_area",
elevation_scale=100,
radius=50,
get_fill_color=["mrt_distance * 10", "mrt_distance", "mrt_distance * 10", 140],
pickable=True,
auto_highlight=True,
)
tooltip = {
"html": "<b>{mrt_distance}</b> meters away from an MRT station, costs <b>{price_per_unit_area}</b> NTD/sqm",
"style": {"background": "grey", "color": "white", "font-family": '"Helvetica Neue", Arial', "z-index": "10000"},
}
r = pdk.Deck(
column_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style=pdk.map_styles.SATELLITE,
)
r2 = pdk.Deck(
hexagon_layer,
initial_view_state=view,
tooltip=tooltip,
map_provider="mapbox",
map_style=pdk.map_styles.SATELLITE,
)
r.to_html("column_layer.html")
r2.to_html("hexagon_layer.html")
Environment
- Framework version: pydeck 0.8.0
- Browser: Microsoft Edge
- OS: Windows 10
Logs
None
I can confirm this same bug of "HexagonLayer" happens with "GridLayer"
This is likely not a bug, but a missing feature.
HexagonLayer/GridLayer are aggregation layers, so each column you hover over is a "bin" that contains an array of rows from your original data. So what do you expect to see in the tooltip here - a list of values, their sum, or average? There isn't enough information about this field to make that decision.
@Pessimistress Thanks. I did not know that. It would be nice to have some indication of that on the Pydeck documentation.
To be honest, the ColumnLayer already does what I need, except the colors of the HexagonLayer, going from yellow to red, which are a nice aspect I can't reproduce on the ColumnLayer.
As for what I think would be best on the hexagon tooltip, a list of values would be my choice, since it works for variables which are not quantitative, such as strings or categorical.
Hi @danilo-css,
I will make a POC with your proposal and think about the API for aggregating values.