Skip to content

Commit 8bc1917

Browse files
authored
Merge pull request #62 from SylvainCorlay/jlab
Jupyterlab extension
2 parents 26cf437 + 2027a3d commit 8bc1917

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules/
77

88
# Compiled javascript
99
pythreejs/static/
10+
pythreejs/staticlab/
1011

1112
# OS X
1213
.DS_Store

js/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyter-threejs",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "jupyter - threejs bridge",
55
"author": "Jupyter-Threejs development team",
66
"license": "BSD",
@@ -15,12 +15,15 @@
1515
},
1616
"devDependencies": {
1717
"json-loader": "^0.5.4",
18+
"@jupyterlab/extension-builder": "^0.7.0",
1819
"rimraf": "^2.4.1",
1920
"webpack": "^1.12.14"
2021
},
2122
"dependencies": {
2223
"jquery": "^2.1.4",
23-
"jupyter-js-widgets": "^1.0.0",
24+
"jupyter-js-widgets": "^2.0.4",
25+
"jupyterlab" : "^0.5.1",
26+
"@jupyterlab/nbwidgets": "^0.4.0",
2427
"three": "^0.75.0",
2528
"underscore": "^1.8.3"
2629
}

js/src/jupyter-threejs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ define(["jupyter-js-widgets", "underscore", "three"],
3333
this.renderer = new THREE.CanvasRenderer();
3434
}
3535
this.el.className = "jupyter-widget jupyter-threejs";
36-
this.$el.empty().append(this.renderer.domElement);
36+
this.el.innerHTML = '';
37+
this.el.appendChild(this.renderer.domElement);
3738
var that = this;
3839
var view_promises = [];
3940
view_promises.push(this.create_child_view(this.model.get('camera'), render_loop).then(
@@ -494,9 +495,8 @@ define(["jupyter-js-widgets", "underscore", "three"],
494495
this.model.on('change:root', this.change_root, this);
495496
this.change_root(this.model, this.model.get('root'));
496497
this.options.dom.addEventListener(this.model.get('event'), function(event) {
497-
var offset = $(this).offset();
498-
var mouseX = ((event.pageX - offset.left) / $(that.options.dom).width()) * 2 - 1;
499-
var mouseY = -((event.pageY - offset.top) / $(that.options.dom).height()) * 2 + 1;
498+
var mouseX = ((event.pageX - this.offsetLeft) / that.options.dom.getBoundingClientRect().width) * 2 - 1;
499+
var mouseY = -((event.pageY - this.offsetTop) / that.options.dom.getBoundingClientRect().height) * 2 + 1;
500500
var vector = new THREE.Vector3(mouseX, mouseY, that.options.renderer.camera.obj.near);
501501

502502
vector.unproject(that.options.renderer.camera.obj);
@@ -997,7 +997,7 @@ define(["jupyter-js-widgets", "underscore", "three"],
997997
var img = new Image();
998998
//img.crossOrigin='anonymous';
999999
img.src = this.model.get('imageuri');
1000-
img.onload = $.proxy(this.needs_update, this);
1000+
img.onload = _.bind(this.needs_update, this);
10011001
this.replace_obj(new THREE.Texture(img));
10021002
ThreeView.prototype.update.call(this);
10031003
},

js/src/labplugin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var jupyter_threejs = require('./index');
2+
3+
var jupyterlab_widgets = require('@jupyterlab/nbwidgets');
4+
5+
module.exports = {
6+
id: 'jupyter.extensions.jupyter-threejs',
7+
requires: [jupyterlab_widgets.INBWidgetExtension],
8+
activate: function(app, widgets) {
9+
widgets.registerWidget({
10+
name: 'jupyter-threejs',
11+
version: jupyter_threejs.version,
12+
exports: jupyter_threejs
13+
});
14+
},
15+
autoStart: true
16+
};

js/webpack.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ var loaders = [
22
{ test: /\.json$/, loader: "json-loader" },
33
];
44

5+
var buildExtension = require('@jupyterlab/extension-builder/lib/builder').buildExtension;
6+
7+
buildExtension({
8+
name: 'jupyter-threejs',
9+
entry: './src/labplugin',
10+
outputDir: '../pythreejs/staticlab',
11+
config: {
12+
module: {
13+
loaders: []
14+
}
15+
}
16+
});
17+
518
module.exports = [
619
{// Notebook extension
720
entry: './src/extension.js',

pythreejs/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ def _jupyter_nbextension_paths():
143143
'dest': npm_pkg_name,
144144
'require': npm_pkg_name + '/extension'
145145
}]
146+
147+
def _jupyter_labextension_paths():
148+
return [{
149+
'name': npm_pkg_name,
150+
'src': 'staticlab'
151+
}]

0 commit comments

Comments
 (0)