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

hover tool doesn't work with gridplot #598

Closed
MadDataScience opened this issue May 2, 2014 · 2 comments · Fixed by #1348
Closed

hover tool doesn't work with gridplot #598

MadDataScience opened this issue May 2, 2014 · 2 comments · Fixed by #1348

Comments

@MadDataScience
Copy link

I'm at the Bokeh tutorial, trying to combine the last two of the basic exercises, and it's not working. Here's my code:

from bokeh.plotting import *
from bokeh.sampledata.autompg import autompg

#output_notebook()
output_file("scatter.html")

# Load some Automobile data into a data source. Interesting columns are:
# "yr" - Year manufactured
# "mpg" - miles per gallon
# "displ" - engine displacement
# "hp" - engine horsepower
# "cyl" - number of cylinders
source = ColumnDataSource(autompg.to_dict("list"))
source.add(autompg["yr"], name="yr")

mpg_range = Range1d(start=min(autompg["mpg"]), end=max(autompg["mpg"]))
yr_range = Range1d(start=min(autompg["yr"]), end=max(autompg["yr"]))
hp_range = Range1d(start=min(autompg["hp"]), end=max(autompg["hp"]))
displ_range = Range1d(start=min(autompg["displ"]), end=max(autompg["displ"]))

# Let's set up some plot options in a dict that we can re-use on multiple plots
plot_config = dict(plot_width=300, plot_height=300, tools="pan,wheel_zoom,box_zoom,select,hover")

# gridplot(...) accepts nested lists of plot objects
plots = [
  circle("mpg", "yr", color="blue", title="MPG by Year", source=source, x_range=mpg_range, y_range=yr_range, **plot_config),
  circle("hp", "yr", color="purple", title="Displacement by Year", source=source, x_range=hp_range, y_range=yr_range, 
         **plot_config),
  circle("mpg", "displ", color="orange", title="MPG by Displacement", source=source, x_range=mpg_range, y_range=displ_range, 
         **plot_config),
  circle("hp", "displ", color="red", title="HP by Displacement", source=source, x_range=hp_range, y_range=displ_range, 
         **plot_config)
]

gridplot([plots[:2],plots[2:]])

for p in plots:
    hover = [t for t in p.tools if isinstance(t, HoverTool)][0]
    hover.tooltips = OrderedDict([
        ("yr", "@yr"),
        ("mpg", "@mpg"),
        ("hp", "@radius"),
        ("disp", "@disp")
    ])

show()
@damianavila damianavila added the bug label May 2, 2014
@waqarmalik
Copy link

Adding a similar topic that I had put in google groups. That has another short program that shows the same problem. Crosslinking for reference.

https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/llhl6YUMtxA

@damianavila damianavila added this to the short-term milestone Oct 6, 2014
@kdodia
Copy link
Contributor

kdodia commented Oct 27, 2014

Updated the original code snippet with some necessary imports:

from bokeh.plotting import *
from bokeh.sampledata.autompg import autompg

from bokeh.objects import Range1d, HoverTool
from collections import OrderedDict


#output_notebook()
output_file("scatter.html")

# Load some Automobile data into a data source. Interesting columns are:
# "yr" - Year manufactured
# "mpg" - miles per gallon
# "displ" - engine displacement
# "hp" - engine horsepower
# "cyl" - number of cylinders
source = ColumnDataSource(autompg.to_dict("list"))
source.add(autompg["yr"], name="yr")

mpg_range = Range1d(start=min(autompg["mpg"]), end=max(autompg["mpg"]))
yr_range = Range1d(start=min(autompg["yr"]), end=max(autompg["yr"]))
hp_range = Range1d(start=min(autompg["hp"]), end=max(autompg["hp"]))
displ_range = Range1d(start=min(autompg["displ"]), end=max(autompg["displ"]))

# Let's set up some plot options in a dict that we can re-use on multiple plots
plot_config = dict(plot_width=300, plot_height=300, tools="pan,wheel_zoom,box_zoom,select,hover")

# gridplot(...) accepts nested lists of plot objects
plots = [
  circle("mpg", "yr", color="blue", title="MPG by Year", source=source, x_range=mpg_range, y_range=yr_range, **plot_config),
  circle("hp", "yr", color="purple", title="Displacement by Year", source=source, x_range=hp_range, y_range=yr_range, 
         **plot_config),
  circle("mpg", "displ", color="orange", title="MPG by Displacement", source=source, x_range=mpg_range, y_range=displ_range, 
         **plot_config),
  circle("hp", "displ", color="red", title="HP by Displacement", source=source, x_range=hp_range, y_range=displ_range, 
         **plot_config)
]

gridplot([plots[:2],plots[2:]])

for p in plots:
    hover = [t for t in p.tools if isinstance(t, HoverTool)][0]
    hover.tooltips = OrderedDict([
        ("yr", "@yr"),
        ("mpg", "@mpg"),
        ("hp", "@radius"),
        ("disp", "@disp")
    ])

show()

Throws error in console: Uncaught TypeError: Cannot read property 'push' of undefined

for (typ in inspectors) {
                          tools = inspectors[typ];
                          if (tools.length !== this.get('num_plots')) {
                            continue;
                          }
                          proxy = new _ToolProxy({
                            tools: tools
                          });
HERE ->                   this.get('inspectors').tools.push(proxy);
                        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants