bokeh / bokeh

Interactive Data Visualization in the browser, from Python
https://bokeh.org
BSD 3-Clause "New" or "Revised" License
19.29k stars 4.18k forks source link

[BUG/FEATURE] Multiple tooltips showing for same patch #9055

Open harmbuisman opened 5 years ago

harmbuisman commented 5 years ago

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

bokeh.version = 1.2.0 python: 3.7.3 OS: Windows 10 browser: all

Description of expected behavior and the observed behavior

I have a shapefile of the Netherlands provinces and when I define a tooltip I get in some locations of the map double, triple or even quadruple tooltips for the same region. This occurs mostly around the islands.

I am not sure if the root cause is a Bokeh bug or an error in the shapefile (not sure how to validate the polygons of the shapefile), but I would like to have only one tooltip. So if this is not a Bokeh bug I would like to request the setting for HoverTool which can be set to show only the first tooltip for a glyphrenderer.

Complete, minimal, self-contained example code that reproduces the issue

import geopandas as gpd 
from bokeh.palettes import Reds
from bokeh.models import GeoJSONDataSource, LinearColorMapper, HoverTool
from bokeh.plotting import figure, show

geodf = gpd.read_file("provinces.geojson")

color_mapper = LinearColorMapper(palette=Reds[9][::-1])

p = figure()
geo_source = GeoJSONDataSource(geojson=geodf.to_json())
p.patches('xs', 'ys', fill_alpha=1, 
              fill_color={'field': 'index', 'transform': color_mapper}, 
              line_color='white', line_width=0.5, 
              source=geo_source)
hover = HoverTool()

p.add_tools(hover)
show(p)

To run the code, you need the following geojson file: provinces.zip

Stack traceback and/or browser JavaScript console output

No errors thrown

Screenshots or screencasts of the bug in action

image

bryevdv commented 5 years ago

Will have to investigate, guessing it is showing a tooltip for each sup-patch in a multi-part patch. @harmbuisman if you have any way to help confirm that hypothesis it would be useful in the mean time. I should also mention there is not MultiPolygons which can express "patches with holes" that might be more suitable for GIS uses