-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resize to Renderable.js #374
Conversation
Codecov Report
@@ Coverage Diff @@
## master #374 +/- ##
==========================================
+ Coverage 70.86% 70.96% +0.10%
==========================================
Files 23 23
Lines 834 837 +3
==========================================
+ Hits 591 594 +3
Misses 243 243
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
Hi @vidartf, This is ready for review. This repo has been a bit light as of late in regards to commits and PR merges. I'm at a point that I'd like to take up maintenance of this repo if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! I've added some comments below about specific parts, but the large points of the logic looks correct 👍
scene = Instance(Scene).tag(sync=True, **widget_serialization) | ||
camera = Instance(Camera).tag(sync=True, **widget_serialization) | ||
controls = List(Instance(Controls)).tag(sync=True, **widget_serialization) | ||
#effect = Instance(Effect, allow_none=True).tag(sync=True, **widget_serialization) | ||
background = Color('black', allow_none=True).tag(sync=True) | ||
background_opacity = Float(1.0, min=0.0, max=1.0).tag(sync=True) | ||
|
||
def __init__(self, scene, camera, controls=None, antialias=False, alpha=False, webgl_version=2, **kwargs): | ||
def __init__(self, scene, camera, controls=None, antialias=False, alpha=False, webgl_version=2, auto_resize=False, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, scene, camera, controls=None, antialias=False, alpha=False, webgl_version=2, auto_resize=False, **kwargs): |
The users can pass autoResize
here, and it will be passed along to the super's init method via the kwargs. The other args that are listed here explicitly are there because:
- They are required (scene and camera)
- They are hidden traits (name start with an underscore).
The autoResize trait does not need the same logic.
super(Renderer, self).__init__( | ||
scene=scene, | ||
camera=camera, | ||
controls=controls or [], | ||
_antialias=antialias, | ||
_alpha=alpha, | ||
_webgl_version=webgl_version, | ||
auto_resize=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto_resize=False, |
**kwargs) | ||
link((self, 'width'), (self, '_width')) | ||
link((self, 'height'), (self, '_height')) | ||
self.autoResize = auto_resize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we pass along the trait to the super's init, we won't need to set it here.
self.autoResize = auto_resize |
@@ -18,6 +18,7 @@ class WebGLRenderer(RenderableWidget): | |||
|
|||
width = CInt(200) | |||
height = CInt(200) | |||
autoResize = Bool(False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already declared on the base class, so should not need to be redeclared here.
autoResize = Bool(False) |
@@ -2,6 +2,7 @@ var _ = require('underscore'); | |||
var widgets = require('@jupyter-widgets/base'); | |||
var $ = require('jquery'); | |||
var Promise = require('bluebird'); | |||
var THREE = require('three'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import isn't used, so is probably not needed here.
var THREE = require('three'); |
// Get the size of the container, or if that doesn't exist, the window | ||
getSize: function() { | ||
try { | ||
const { width, height } = this.el.getBoundingClientRect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also use window.getComputedStyle()
for both the container (this.el
) and the rendered element (this.renderer.domElement
and or this.$frozenRenderer
if this.isFrozen
is true) to substract the margins and paddings from these sizes. That should hopefully avoid the magic "4.4" below, as the actual size of this padding will depend on the context (e.g. the margin is a CSS variable set by the theme in JupyterLab).
if (width === 0){ | ||
return; | ||
} | ||
this.renderer.setSize(width, height - 4.4); // Seems to grow by 4.4 px on each resize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you set the size on the model (this.model.set({"_width": width, "_height": height})
), then the update would happen automatically via the existing updateSize
method, and the sizes would also persist through a freeze/thaw cycle.
console.log("bounding client size"); | ||
return [width, height]; | ||
} catch (error) { | ||
// Not using a container for the renderer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about this. When does this happen?
Automatically resizes the pythreejs Renderer.
Resolves #362.