deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

[Bug] HexagonLayer has a bug on tooltips

Open danilo-css opened this issue 2 years ago • 4 comments

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": image

Instead they return undefined if you run "HexagonLayer" image

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

danilo-css avatar Jun 01 '23 19:06 danilo-css

I can confirm this same bug of "HexagonLayer" happens with "GridLayer"

danilo-css avatar Jun 01 '23 21:06 danilo-css

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 avatar Jun 01 '23 22:06 Pessimistress

@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.

danilo-css avatar Jun 02 '23 00:06 danilo-css

Hi @danilo-css,

I will make a POC with your proposal and think about the API for aggregating values.

Jesus89 avatar Jul 07 '23 07:07 Jesus89