Programmatically generate SVG (vector) images, animations, and interactive Jupyter widgets

Improve interactive widget mouse event throttling

Changed files
+16 -2
drawSvg
+16 -2
drawSvg/widgets/drawing_javascript.py
···
javascript = '''
require.undef('drawingview');
-
define('drawingview', ["@jupyter-widgets/base"], function(widgets) {
+
define('drawingview', ['@jupyter-widgets/base'], function(widgets) {
var DrawingView = widgets.DOMWidgetView.extend({
render: function() {
this.container = document.createElement('a');
···
this.container.appendChild(this.svg_view);
this.el.appendChild(this.container);
this.model.on('change:_image', this.image_changed, this);
+
this.model.on('change:_mousemove_blocked', this.block_changed,
+
this);
},
image_changed: function() {
this.container.innerHTML = this.model.get('_image');
···
this.cursor_point = this.svg_view.createSVGPoint();
this.register_events();
},
+
last_move: null,
+
block_changed: function() {
+
var widget = this;
+
window.setTimeout(function() {
+
if (!widget.model.get('_mousemove_blocked') && widget.last_move) {
+
widget.send_mouse_event('mousemove', widget.last_move);
+
}
+
}, 0);
+
},
send_mouse_event: function(name, e) {
+
this.last_move = null;
if (this.model.get('disable')) {
return;
}
···
});
this.svg_view.addEventListener('mousemove', function(e) {
e.preventDefault();
-
if (!widget.model.get('_mousemove_blocked')) {
+
if (widget.model.get('_mousemove_blocked')) {
+
widget.last_move = e;
+
} else {
widget.send_mouse_event('mousemove', e);
}
});