Skip to content
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

Responsive Resizing #42

Merged
merged 8 commits into from
Mar 25, 2016
Merged

Responsive Resizing #42

merged 8 commits into from
Mar 25, 2016

Conversation

Frencil
Copy link
Contributor

@Frencil Frencil commented Mar 23, 2016

Overview

This branch is built to address #41. In a nutshell, a layout should support making a plot discretely sized with no ability to resize, manually resizable (by way of a UI element), or responsively resizable (in that it expands to fill its available space).

New layout parameters

resizable

The resizable parameter is defined at the instance/plot level. This can be "manual", "responsive", or null/false.

aspect_ratio

For resizable plots, since container width is typically bounded by window width but height is theoretically infinite, an aspect_ratio value can be defined to keep a specific aspect ratio for the plot as it resizes. This is a numerical value defined as width / height. So, for example, a square aspect ratio would be 1 and a 16:9 aspect ratio would be 1.7777777 (16/9).

proportional_origin

Another other major change is that panels now have proportional_origin in addition to proportional_width and proportional_height. In general the proportional geometry values are used whenever a layout is resizable by either method, because at that point predefined discrete dimensions and origins may only be valid when the plot is first loaded (and in the case of a responsive plot, may immediately be overwritten during initialization). The proportional_origin is similar to the origin in that has x and y parameters, but these are expressed as multipliers applied to the dimensions of the plot. So, for example, this:

proportional_origin: { x: 0.25, y: 0.5 }

Would position a panel 1/4 of the plot width from the left edge of the plot and 1/2 of the plot height from the top of the plot. As the plot is resized (by either method) the proportional origin would stay constant while the discrete origin would likely change.

CSS

Responsive plots really only make sense inside a containing element that has the right CSS to expand to fill space. A new namespaced class has been added to make this easier for implementers: lz-container-responsive.

Demo Responsive

Finally, I reworked the existing demo.html into a new demo_responsive.html (this exists in addition to the original). This demo page demonstrates how to build a responsive LocusZoom plot and applies some conventions that ultimately would be good to apply to the original demo as well (for example: clear separation of LocusZoom config code from demo-specific logic, illustration of applying a partial layout, etc.)

@@ -43,6 +46,14 @@ LocusZoom.Instance = function(id, datasource, layout, state) {

LocusZoom.Instance.prototype.initializeLayout = function(){

// If this is a responsive layout then set a namespaced/unique onresize event listener on the window
if (this.layout.resizable == "responsive"){
this.window_onresize = d3.select(window).on("resize.lz-"+this.id, function(){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a "namespaced" event listener. I didn't even know you could do this until today, but essentially the ".lz-" and the id following the "resize" still ties this method to a resize event on the window but does not affect any other existing resize event listeners.

@Frencil
Copy link
Contributor Author

Frencil commented Mar 24, 2016

UPDATE: this just got some tests added and is essentially complete. A quick review pass would be most helpful but isn't necessary. I'll merge it in later today to make way for Tool Tips (#40) to be on deck for final testing/review/merge early Friday.

@Frencil Frencil merged commit f0d856b into master Mar 25, 2016
@Frencil Frencil deleted the resizable branch April 20, 2016 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant