Skip to content

Commit e07b25c

Browse files
committed
de-nest messages for callbacks
1 parent 138bbd2 commit e07b25c

File tree

2 files changed

+37
-73
lines changed

2 files changed

+37
-73
lines changed

plotly/widgets/graph_widget.py

+19-34
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ def _handle_msg(self, message):
8282
self._message = _message
8383

8484
if content.get('event', '') in ['click', 'hover', 'zoom']:
85-
self._event_handlers[content['event']](self, content)
85+
# De-nest the message
86+
if content['event'] == 'click' or content['event'] == 'hover':
87+
message = content['message']['points']
88+
elif content['event'] == 'zoom':
89+
message = content['message']['ranges']
90+
91+
self._event_handlers[content['event']](self, message)
8692

8793
def _handle_registration(self, event_type, callback, remove):
8894
self._event_handlers[event_type].register_callback(callback,
@@ -118,21 +124,14 @@ def on_click(self, callback, remove=False):
118124
which point(s) were clicked on.
119125
120126
click_obj example:
121-
{
122-
'event': 'hover',
123-
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
124-
'message': {
125-
'points': [
126-
{
127-
'curveNumber': 1,
128-
'pointNumber': 2,
129-
'x': 4,
130-
'y': 14
131-
}
132-
],
133-
'type': 'hover'
127+
[
128+
{
129+
'curveNumber': 1,
130+
'pointNumber': 2,
131+
'x': 4,
132+
'y': 14
134133
}
135-
}
134+
]
136135
137136
remove (bool, optional): If False, attach the callback.
138137
If True, remove the callback. Defaults to False.
@@ -173,21 +172,14 @@ def on_hover(self, callback, remove=False):
173172
which point(s) was hovered over.
174173
175174
hover_obj example:
176-
{
177-
'event': 'hover',
178-
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
179-
'message': {
180-
'points': [
181-
{
175+
[
176+
{
182177
'curveNumber': 1,
183178
'pointNumber': 2,
184179
'x': 4,
185180
'y': 14
186-
}
187-
],
188-
'type': 'hover'
189181
}
190-
}
182+
]
191183
192184
remove (bool, optional): If False, attach the callback.
193185
If True, remove the callback. Defaults to False.
@@ -230,15 +222,8 @@ def on_zoom(self, callback, remove=False):
230222
231223
zoom_obj example:
232224
{
233-
'event': 'zoom',
234-
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
235-
'message': {
236-
'ranges': {
237-
'x': [1.8399058038561549, 2.16443359662],
238-
'y': [4.640902872777017, 7.855677154582]
239-
},
240-
'type': 'zoom'
241-
}
225+
'x': [1.8399058038561549, 2.16443359662],
226+
'y': [4.640902872777017, 7.855677154582]
242227
}
243228
244229
remove (bool, optional): If False, attach the callback.

specs/GraphWidgetSpec.md

+18-39
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,14 @@ g.on_click(callback, remove=False)
2222
which point(s) were clicked on.
2323

2424
click_obj example:
25-
{
26-
'event': 'hover',
27-
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
28-
'message': {
29-
'points': [
30-
{
31-
'curveNumber': 1,
32-
'pointNumber': 2,
33-
'x': 4,
34-
'y': 14
35-
}
36-
],
37-
'type': 'hover'
38-
}
39-
}
25+
[
26+
{
27+
'curveNumber': 1,
28+
'pointNumber': 2,
29+
'x': 4,
30+
'y': 14
31+
}
32+
]
4033

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

8174
hover_obj example:
82-
{
83-
'event': 'hover',
84-
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
85-
'message': {
86-
'points': [
87-
{
88-
'curveNumber': 1,
89-
'pointNumber': 2,
90-
'x': 4,
91-
'y': 14
92-
}
93-
],
94-
'type': 'hover'
95-
}
96-
}
75+
[
76+
{
77+
'curveNumber': 1,
78+
'pointNumber': 2,
79+
'x': 4,
80+
'y': 14
81+
}
82+
]
9783

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

137123
zoom_obj example:
138124
{
139-
'event': 'zoom',
140-
'graphId': '2e66d4da-0523-4b6b-a3d7-f3b8ced416b1',
141-
'message': {
142-
'ranges': {
143-
'x': [1.8399058038561549, 2.1644335966246384],
144-
'y': [4.640902872777017, 7.8556771545827635]
145-
},
146-
'type': 'zoom'
147-
}
125+
'x': [1.8399058038561549, 2.1644335966246384],
126+
'y': [4.640902872777017, 7.8556771545827635]
148127
}
149128

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

0 commit comments

Comments
 (0)