Repository: bokeh/bokeh

Issue:
Make it possible to create HoverTool with attachment set to explicit left, right, above, below
Bokeh 0.12.13

Right now, the only possible values for the `attachment` attribute of `HoverTool` are `horizontal` and `vertical`. I think it would be great to allow other values that `Tooltip` supports - `left`, `right`, `above`, `below`.


Discussion:
cc @clairetang6 re: recent discussions to make `Tooltip` an actual independently usable thing
@p-himik I think that would be great but I think it should be done in conjunction with making `Tooltips` usable in their own right (currently they are a semi-implementation detail of hover tools)
This is just a matter of updating `HoverTool.attachment`'s type to what `Tooltip.attachment` supports. @p-himik, this is a 5 minute PR if you want to help fixing this.
>  recent discussions to make Tooltip an actual independently usable thing

Can you expand. `Tooltip` is a standalone model, independent of hover tool, though bound to canvas. 
> Can you expand. Tooltip is a standalone model, independent of hover tool, though bound to canvas.

Users have often wanted to be able to create a single tooltip, then add it and position it explicitly themselves and have it stay permanently visible (basically to act as a fancy annotation). I don't believe this is currently possible. 
I see, this feature. There is issue #5724 requesting this.

Resolving patch:
diff --git a/bokeh/core/enums.py b/bokeh/core/enums.py
--- a/bokeh/core/enums.py
+++ b/bokeh/core/enums.py
@@ -191,6 +191,10 @@ def enumeration(*values, **kwargs):
 #: Specify a horizontal location in plot layouts
 HorizontalLocation = enumeration("left", "right")
 
+#: Specify an attachment for tooltips
+TooltipAttachment = enumeration("horizontal", "vertical",
+                                "left", "right", "above", "below")
+
 #: Specify a named dashing patter for stroking lines
 DashPattern = enumeration("solid", "dashed", "dotted", "dotdash", "dashdot")
 
diff --git a/bokeh/models/annotations.py b/bokeh/models/annotations.py
--- a/bokeh/models/annotations.py
+++ b/bokeh/models/annotations.py
@@ -7,7 +7,8 @@
 from six import string_types
 
 from ..core.enums import (AngleUnits, Dimension, FontStyle, LegendClickPolicy, LegendLocation,
-                          Orientation, RenderMode, SpatialUnits, VerticalAlign, TextAlign)
+                          Orientation, RenderMode, SpatialUnits, VerticalAlign, TextAlign,
+                          TooltipAttachment)
 from ..core.has_props import abstract
 from ..core.properties import (Angle, AngleSpec, Auto, Bool, ColorSpec, Datetime, Dict, DistanceSpec, Either,
                                Enum, Float, FontSizeSpec, Include, Instance, Int, List, NumberSpec, Override,
@@ -980,8 +981,8 @@ class Tooltip(Annotation):
     '''
     level = Override(default="overlay")
 
-    attachment = Enum("horizontal", "vertical", "left", "right", "above", "below", help="""
-    Whether the tooltip should display to the left or right off the cursor
+    attachment = Enum(TooltipAttachment, help="""
+    Whether the tooltip should be displayed to the left or right of the cursor
     position or above or below it, or if it should be automatically placed
     in the horizontal or vertical dimension.
     """)
diff --git a/bokeh/models/tools.py b/bokeh/models/tools.py
--- a/bokeh/models/tools.py
+++ b/bokeh/models/tools.py
@@ -22,7 +22,8 @@
 '''
 from __future__ import absolute_import
 
-from ..core.enums import Anchor, Dimension, Dimensions, Location, TooltipFieldFormatter
+from ..core.enums import (Anchor, Dimension, Dimensions, Location,
+                          TooltipFieldFormatter, TooltipAttachment)
 from ..core.has_props import abstract
 from ..core.properties import (
     Auto, Bool, Color, Dict, Either, Enum, Float, Percent, Instance, List,
@@ -819,8 +820,10 @@ class HoverTool(Inspection):
     point of a tooltip. The default is to attach to the center of a glyph.
     """)
 
-    attachment = Enum("horizontal", "vertical", help="""
-    Whether tooltip's arrow should appear in the horizontal or vertical dimension.
+    attachment = Enum(TooltipAttachment, help="""
+    Whether the tooltip should be displayed to the left or right of the cursor
+    position or above or below it, or if it should be automatically placed
+    in the horizontal or vertical dimension.
     """)
 
     show_arrow = Bool(default=True, help="""


Test patch:
diff --git a/bokeh/core/tests/test_enums.py b/bokeh/core/tests/test_enums.py
--- a/bokeh/core/tests/test_enums.py
+++ b/bokeh/core/tests/test_enums.py
@@ -69,6 +69,7 @@ def test_enums_contents():
         'StepMode',
         'TextAlign',
         'TextBaseline',
+        'TooltipAttachment',
         'TooltipFieldFormatter',
         'VerticalAlign',
         'VerticalLocation',