Created
July 17, 2014 14:33
Sample code of vispyjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(["widgets/js/widget"], function(WidgetManager){ | |
var Widget = IPython.DOMWidgetView.extend({ | |
render: function(){ | |
this.$canvas = $('<canvas />') | |
.attr('id', 'canvas') | |
.attr('tabindex', '1') | |
.appendTo(this.$el); | |
}, | |
events: { | |
'mousemove': 'mouse_move', | |
}, | |
mouse_move: function(e) { | |
// Generate and send event | |
var event = gen_mouse_event(this.c, e, "mouse_move"); | |
if(pos[0] != last_pos[0] || pos[1] != last_pos[1]) | |
this.send(event); | |
}, | |
// Update, whenever value attribute of our widget changes | |
update : function(){ | |
var img_str = this.model.get("value"); | |
var img = new Image(); | |
img.src = "data:image/png;base64," + img_str; | |
this.canvas2d.drawImage(img, 0, 0); | |
}, | |
}) | |
WidgetManager.register_widget_view("Widget", Widget); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment