Skip to content

Commit

Permalink
de-nest messages for callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
chriddyp committed Jan 21, 2015
1 parent 138bbd2 commit e07b25c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 73 deletions.
53 changes: 19 additions & 34 deletions plotly/widgets/graph_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ def _handle_msg(self, message):
self._message = _message

if content.get('event', '') in ['click', 'hover', 'zoom']:
self._event_handlers[content['event']](self, content)
# De-nest the message
if content['event'] == 'click' or content['event'] == 'hover':
message = content['message']['points']
elif content['event'] == 'zoom':
message = content['message']['ranges']

self._event_handlers[content['event']](self, message)

def _handle_registration(self, event_type, callback, remove):
self._event_handlers[event_type].register_callback(callback,
Expand Down Expand Up @@ -118,21 +124,14 @@ def on_click(self, callback, remove=False):
which point(s) were clicked on.
click_obj example:
{
'event': 'hover',
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
'message': {
'points': [
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
],
'type': 'hover'
[
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
}
]
remove (bool, optional): If False, attach the callback.
If True, remove the callback. Defaults to False.
Expand Down Expand Up @@ -173,21 +172,14 @@ def on_hover(self, callback, remove=False):
which point(s) was hovered over.
hover_obj example:
{
'event': 'hover',
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
'message': {
'points': [
{
[
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
],
'type': 'hover'
}
}
]
remove (bool, optional): If False, attach the callback.
If True, remove the callback. Defaults to False.
Expand Down Expand Up @@ -230,15 +222,8 @@ def on_zoom(self, callback, remove=False):
zoom_obj example:
{
'event': 'zoom',
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
'message': {
'ranges': {
'x': [1.8399058038561549, 2.16443359662],
'y': [4.640902872777017, 7.855677154582]
},
'type': 'zoom'
}
'x': [1.8399058038561549, 2.16443359662],
'y': [4.640902872777017, 7.855677154582]
}
remove (bool, optional): If False, attach the callback.
Expand Down
57 changes: 18 additions & 39 deletions specs/GraphWidgetSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,14 @@ g.on_click(callback, remove=False)
which point(s) were clicked on.

click_obj example:
{
'event': 'hover',
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
'message': {
'points': [
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
],
'type': 'hover'
}
}
[
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
]

remove (bool, optional): If False, attach the callback.
If True, remove the callback. Defaults to False.
Expand Down Expand Up @@ -79,21 +72,14 @@ g.on_hover(callback, remove=False)
points belong to.

hover_obj example:
{
'event': 'hover',
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
'message': {
'points': [
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
],
'type': 'hover'
}
}
[
{
'curveNumber': 1,
'pointNumber': 2,
'x': 4,
'y': 14
}
]

remove (bool, optional): If False, attach the callback.
If True, remove the callback. Defaults to False.
Expand Down Expand Up @@ -136,15 +122,8 @@ g.on_zoom(callback, remove=False)

zoom_obj example:
{
'event': 'zoom',
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
'message': {
'ranges': {
'x': [1.8399058038561549, 2.1644335966246384],
'y': [4.640902872777017, 7.8556771545827635]
},
'type': 'zoom'
}
'x': [1.8399058038561549, 2.1644335966246384],
'y': [4.640902872777017, 7.8556771545827635]
}

remove (bool, optional): If False, attach the callback.
Expand Down

0 comments on commit e07b25c

Please sign in to comment.