Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a89ec04

Browse files
committed
Fix handling of circular references
1 parent cebbfe3 commit a89ec04

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ def get_renderer(self, cleared=None):
271271

272272
def handle_event(self, event):
273273
e_type = event['type']
274+
guiEvent = event.get('guiEvent', None)
275+
274276
if e_type == 'ack':
275277
# Network latency tends to decrease if traffic is flowing
276278
# in both directions. Therefore, the browser sends back
@@ -290,7 +292,6 @@ def handle_event(self, event):
290292
# Javascript button numbers and matplotlib button numbers are
291293
# off by 1
292294
button = event['button'] + 1
293-
guiEvent = event['guiEvent']
294295

295296
# The right mouse button pops up a context menu, which
296297
# doesn't work very well, so use the middle mouse button

lib/matplotlib/backends/web_backend/mpl.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,18 @@ mpl.findpos = function(e) {
454454
return {"x": x, "y": y};
455455
};
456456

457+
/*
458+
* return a copy of an object with only non-object keys
459+
* we need this to avoid circular references
460+
* http://stackoverflow.com/a/24161582/3208463
461+
*/
462+
function simpleKeys (original) {
463+
return Object.keys(original).reduce(function (obj, key) {
464+
obj[key] = typeof original[key] === 'object' ? '{ ... }' : original[key];
465+
return obj;
466+
}, {});
467+
}
468+
457469
mpl.figure.prototype.mouse_event = function(event, name) {
458470
var canvas_pos = mpl.findpos(event)
459471

@@ -468,7 +480,7 @@ mpl.figure.prototype.mouse_event = function(event, name) {
468480

469481
this.send_message(name, {x: x, y: y, button: event.button,
470482
step: event.step,
471-
guiEvent: event});
483+
guiEvent: simpleKeys(event)});
472484

473485
/* This prevents the web browser from automatically changing to
474486
* the text insertion cursor when the button is pressed. We want
@@ -509,7 +521,7 @@ mpl.figure.prototype.key_event = function(event, name) {
509521
this._key_event_extra(event, name);
510522

511523
this.send_message(name, {key: value,
512-
guiEvent: event});
524+
guiEvent: simpleKeys(event)});
513525
return false;
514526
}
515527

0 commit comments

Comments
 (0)