Skip to content

Instantly share code, notes, and snippets.

@mfkaptan
Created July 17, 2014 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfkaptan/eb12cc91ee9d49f348d9 to your computer and use it in GitHub Desktop.
Save mfkaptan/eb12cc91ee9d49f348d9 to your computer and use it in GitHub Desktop.
Sample code of vispyjs
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