Repository: bokeh/bokeh

Issue:
HoverTool for last value of a line plot sticks on second last value (works fine with circles)
The hover tool is not displaying data for the last value of a line glyph, when hovering over the end of the line it always jumps on the second last data point of a line plot. On the other hand it works as expected if the same data is plotted as circles. Tested with bokeh 12.4.

Working example with circles (hover tool pops up for data point x=5, y=7 when hovering over last circle in figure):

```python
from bokeh.plotting import figure, output_file, show
from bokeh.models import HoverTool, BoxSelectTool

output_file("toolbar.html")
TOOLS = [BoxSelectTool(), HoverTool()]

p = figure(plot_width=400, plot_height=400, title=None, tools=TOOLS)

p.circle([1, 2, 3, 4, 5], [2, 5, 8, 2, 7])

show(p)
```

Non-working example (hover tool jumps to data point x=4, y=2 when hovering over end of the line):

```python
from bokeh.plotting import figure, output_file, show
from bokeh.models import HoverTool, BoxSelectTool

output_file("toolbar.html")
TOOLS = [BoxSelectTool(), HoverTool()]

p = figure(plot_width=400, plot_height=400, title=None, tools=TOOLS)

p.line([1, 2, 3, 4, 5], [2, 5, 8, 2, 7])

show(p)
```


Discussion:
Hello, @geissbuehler 
Here is what I have observed:

When doing your line plot, the line segment after the point is being denoted with the index # of the data of the prior point.

So the zeroth point connecting to the first point is being annotated in the hover tool as index 0
then the first point going to the second is index 1
the second to third is index 2
then the third to the fourth is being indexed 3

Since there is no fifth point for a line to be drawn from the fourth data point to the fifth, then the fourth data point never appears in the hover tool.

I suppose the reasoning is, a line takes two points to make - and the annotation by index is done by the 1st of the two points to create the line.

This seems logical to me - and also makes sense why the circle example is working as you expect - since each circle is created from each point, and they all have their own representation eg) unlike the lines that require a minimum of two points to draw. 



![example_1](https://cloud.githubusercontent.com/assets/1798497/22430249/95a77e08-e6db-11e6-9fbc-42bd39102ba8.png)

So as seen above index:4 is only used to connect index:3's data to generate the line and thus does not appear in the naming since it is not connecting to anything after it, only to something prior to it.
Right, @afonit  has the general idea. Lines differ from circles in that lines have a connected topology. There are different "line policy" settings on hover tool you could try:

http://bokeh.pydata.org/en/latest/docs/reference/models/tools.html#bokeh.models.tools.HoverTool.line_policy

The "interp" or "nearest" ones might work better for your use case. If you really want hover over just the points, another option is to create some invisible circles (i.e. with alpha zero) that only exist to drive the hover tool hit-testing. 

It's possible another line policy like "points" could be added, which would effectively add an invisible  circular hit-test region around the line points auto-magically. But it's worth dome discussion first to see if adding that complexity is really warranted. 
`line_policy="nearest"` gives me the expected behaviour. This really looked like a bug to me, but it's just a question of parameters.

Thanks for your quick replies!
Well, perhaps "nearest" would be a better default value. 
Re-opening, I actually think "nearest" is probably a better default, and the "prev" is probably only default by accident of being the first value in the enum, rather than any explicit decision. 

Thoughts, @bokeh/dev ?
+1 for a default of nearest.
I agree that "nearest" is the most useful default. 
@geissbuehler or @afonit if either of you is interested in picking up a super quick PR, this would just be adding `default="nearest"` to this line:

https://github.com/bokeh/bokeh/blob/master/bokeh/models/tools.py#L768

changing this BokehJS line to match (e.g. "nearest" instead of "prev"):

https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/tools/inspectors/hover_tool.coffee#L308

and a short migration note in the release notes:

https://raw.githubusercontent.com/bokeh/bokeh/master/sphinx/source/docs/releases/0.12.5.rst
Thank you very much, @bryevdv! I'm glad to see that my finding will improve the default hover tool behavior.

Resolving patch:
diff --git a/bokeh/models/tools.py b/bokeh/models/tools.py
--- a/bokeh/models/tools.py
+++ b/bokeh/models/tools.py
@@ -765,11 +765,12 @@ class HoverTool(Inspection):
     position.
     """)
 
-    line_policy = Enum("prev", "next", "nearest", "interp", "none", help="""
-    When showing tooltips for lines, whether the tooltip position should be
-    the "previous" or "next" points on the line, the nearest point to the
-    current mouse position, or interpolate along the line to the current
-    mouse position.
+    line_policy = Enum("prev", "next", "nearest", "interp", "none",
+                       default="nearest", help="""
+    When showing tooltips for lines, designates whether the tooltip position
+    should be the "previous" or "next" points on the line, the "nearest" point
+    to the current mouse position, or "interpolate" along the line to the
+    current mouse position.
     """)
 
     anchor = Enum(Anchor, default="center", help="""


Test patch: