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

Fixed projecting of FreehandDraw stream data #219

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions geoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def project_drawn(cb, msg):
return project(element, projection=crs)


def project_poly(cb, msg):
if not msg['data']:
return msg
projected = project_drawn(cb, msg)
if projected is None:
return msg
split = projected.split()
data = {d.name: [el.dimension_values(d) for el in split]
for d in projected.dimensions()}
xd, yd = projected.kdims
data['xs'] = data.pop(xd.name)
data['ys'] = data.pop(yd.name)
return {'data': data}



class GeoRangeXYCallback(RangeXYCallback):

def _process_msg(self, msg):
Expand Down Expand Up @@ -207,18 +223,7 @@ class GeoPolyDrawCallback(PolyDrawCallback):

def _process_msg(self, msg):
msg = super(GeoPolyDrawCallback, self)._process_msg(msg)
if not msg['data']:
return msg
projected = project_drawn(self, msg)
if projected is None:
return msg
split = projected.split()
data = {d.name: [el.dimension_values(d) for el in split]
for d in projected.dimensions()}
xd, yd = projected.kdims
data['xs'] = data.pop(xd.name)
data['ys'] = data.pop(yd.name)
return {'data': data}
return project_poly(self, msg)


class GeoBoxEditCallback(BoxEditCallback):
Expand All @@ -229,6 +234,7 @@ def _process_msg(self, msg):
element = self.source
if isinstance(element, UniformNdMapping):
element = element.last

if element.crs == proj or not isinstance(element, _Element):
return msg

Expand Down Expand Up @@ -262,9 +268,10 @@ def _process_msg(self, msg):
# Handle FreehandDraw (available in HoloViews 1.11.0)
from holoviews.plotting.bokeh.callbacks import FreehandDrawCallback
from holoviews.streams import FreehandDraw
class GeoFreehandDrawCallback(FreehandDrawCallback, GeoPolyDrawCallback):
class GeoFreehandDrawCallback(FreehandDrawCallback):
def _process_msg(self, msg):
return GeoPolyDrawCallback._process_msg(self, msg)
msg = super(GeoFreehandDrawCallback, self)._process_msg(msg)
return project_poly(self, msg)
callbacks[FreehandDraw] = GeoFreehandDrawCallback
except:
pass
Expand Down