Incorporate code review feedback for Openseadragon isue 127. Added appropriate default values and docs to openseadragon.js; restored a blank line that I accidentally deleted.

This commit is contained in:
nein09 2014-09-12 10:33:48 -07:00
parent 2e4e187b21
commit 741978caf9
2 changed files with 28 additions and 26 deletions

View File

@ -908,6 +908,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
defaultZoomLevel: 0, defaultZoomLevel: 0,
minZoomLevel: null, minZoomLevel: null,
maxZoomLevel: null, maxZoomLevel: null,
homeFillsViewer: false,
//UI RESPONSIVENESS AND FEEL //UI RESPONSIVENESS AND FEEL
clickTimeThreshold: 300, clickTimeThreshold: 300,

View File

@ -174,6 +174,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
var center = this.homeBounds.getCenter( ), var center = this.homeBounds.getCenter( ),
width = 1.0 / this.getHomeZoom( ), width = 1.0 / this.getHomeZoom( ),
height = width / this.getAspectRatio(); height = width / this.getAspectRatio();
return new $.Rect( return new $.Rect(
center.x - ( width / 2.0 ), center.x - ( width / 2.0 ),
center.y - ( height / 2.0 ), center.y - ( height / 2.0 ),
@ -325,7 +326,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
return this.zoomSpring.target.value; return this.zoomSpring.target.value;
} }
}, },
/** /**
* @function * @function
* @private * @private
@ -348,7 +349,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
bounds.width, bounds.width,
bounds.height bounds.height
); );
horizontalThreshold = this.visibilityRatio * newBounds.width; horizontalThreshold = this.visibilityRatio * newBounds.width;
verticalThreshold = this.visibilityRatio * newBounds.height; verticalThreshold = this.visibilityRatio * newBounds.height;
@ -393,7 +394,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
newBounds.y = this.contentAspectY/2 - newBounds.height/2; newBounds.y = this.contentAspectY/2 - newBounds.height/2;
} }
} }
if( this.viewer ){ if( this.viewer ){
/** /**
* Raised when the viewport constraints are applied (see {@link OpenSeadragon.Viewport#applyConstraints}). * Raised when the viewport constraints are applied (see {@link OpenSeadragon.Viewport#applyConstraints}).
@ -409,10 +410,10 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
immediately: immediately immediately: immediately
}); });
} }
return newBounds; return newBounds;
}, },
/** /**
* @function * @function
* @return {OpenSeadragon.Viewport} Chainable. * @return {OpenSeadragon.Viewport} Chainable.
@ -426,7 +427,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
), ),
bounds, bounds,
constrainedBounds; constrainedBounds;
if ( actualZoom != constrainedZoom ) { if ( actualZoom != constrainedZoom ) {
this.zoomTo( constrainedZoom, this.zoomPoint, immediately ); this.zoomTo( constrainedZoom, this.zoomPoint, immediately );
} }
@ -434,11 +435,11 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
bounds = this.getBounds(); bounds = this.getBounds();
constrainedBounds = this._applyBoundaryConstraints( bounds, immediately ); constrainedBounds = this._applyBoundaryConstraints( bounds, immediately );
if ( bounds.x !== constrainedBounds.x || bounds.y !== constrainedBounds.y || immediately ){ if ( bounds.x !== constrainedBounds.x || bounds.y !== constrainedBounds.y || immediately ){
this.fitBounds( constrainedBounds, immediately ); this.fitBounds( constrainedBounds, immediately );
} }
return this; return this;
}, },
@ -449,7 +450,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
ensureVisible: function( immediately ) { ensureVisible: function( immediately ) {
return this.applyConstraints( immediately ); return this.applyConstraints( immediately );
}, },
/** /**
* @function * @function
* @private * @private
@ -461,7 +462,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
options = options || {}; options = options || {};
var immediately = options.immediately || false; var immediately = options.immediately || false;
var constraints = options.constraints || false; var constraints = options.constraints || false;
var aspect = this.getAspectRatio(), var aspect = this.getAspectRatio(),
center = bounds.getCenter(), center = bounds.getCenter(),
newBounds = new $.Rect( newBounds = new $.Rect(
@ -476,7 +477,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
referencePoint, referencePoint,
newBoundsAspectRatio, newBoundsAspectRatio,
newConstrainedZoom; newConstrainedZoom;
if ( newBounds.getAspectRatio() >= aspect ) { if ( newBounds.getAspectRatio() >= aspect ) {
newBounds.height = bounds.width / aspect; newBounds.height = bounds.width / aspect;
newBounds.y = center.y - newBounds.height / 2; newBounds.y = center.y - newBounds.height / 2;
@ -484,24 +485,24 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
newBounds.width = bounds.height * aspect; newBounds.width = bounds.height * aspect;
newBounds.x = center.x - newBounds.width / 2; newBounds.x = center.x - newBounds.width / 2;
} }
if ( constraints ) { if ( constraints ) {
newBoundsAspectRatio = newBounds.getAspectRatio(); newBoundsAspectRatio = newBounds.getAspectRatio();
} }
this.panTo( this.getCenter( true ), true ); this.panTo( this.getCenter( true ), true );
this.zoomTo( this.getZoom( true ), null, true ); this.zoomTo( this.getZoom( true ), null, true );
oldBounds = this.getBounds(); oldBounds = this.getBounds();
oldZoom = this.getZoom(); oldZoom = this.getZoom();
newZoom = 1.0 / newBounds.width; newZoom = 1.0 / newBounds.width;
if ( constraints ) { if ( constraints ) {
newConstrainedZoom = Math.max( newConstrainedZoom = Math.max(
Math.min(newZoom, this.getMaxZoom() ), Math.min(newZoom, this.getMaxZoom() ),
this.getMinZoom() this.getMinZoom()
); );
if (newZoom !== newConstrainedZoom) { if (newZoom !== newConstrainedZoom) {
newZoom = newConstrainedZoom; newZoom = newConstrainedZoom;
newBounds.width = 1.0 / newZoom; newBounds.width = 1.0 / newZoom;
@ -509,14 +510,14 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
newBounds.height = newBounds.width / newBoundsAspectRatio; newBounds.height = newBounds.width / newBoundsAspectRatio;
newBounds.y = center.y - newBounds.height / 2; newBounds.y = center.y - newBounds.height / 2;
} }
newBounds = this._applyBoundaryConstraints( newBounds, immediately ); newBounds = this._applyBoundaryConstraints( newBounds, immediately );
} }
if ( newZoom == oldZoom || newBounds.width == oldBounds.width ) { if ( newZoom == oldZoom || newBounds.width == oldBounds.width ) {
return this.panTo( constraints ? newBounds.getCenter() : center, immediately ); return this.panTo( constraints ? newBounds.getCenter() : center, immediately );
} }
referencePoint = oldBounds.getTopLeft().times( referencePoint = oldBounds.getTopLeft().times(
this.containerSize.x / oldBounds.width this.containerSize.x / oldBounds.width
).minus( ).minus(
@ -527,10 +528,10 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
this.containerSize.x / oldBounds.width - this.containerSize.x / oldBounds.width -
this.containerSize.x / newBounds.width this.containerSize.x / newBounds.width
); );
return this.zoomTo( newZoom, referencePoint, immediately ); return this.zoomTo( newZoom, referencePoint, immediately );
}, },
/** /**
* @function * @function
* @param {OpenSeadragon.Rect} bounds * @param {OpenSeadragon.Rect} bounds
@ -543,7 +544,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
constraints: false constraints: false
} ); } );
}, },
/** /**
* @function * @function
* @param {OpenSeadragon.Rect} bounds * @param {OpenSeadragon.Rect} bounds
@ -556,7 +557,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
constraints: true constraints: true
} ); } );
}, },
/** /**
* @function * @function
* @param {Boolean} immediately * @param {Boolean} immediately
@ -737,7 +738,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
} }
this.degrees = degrees; this.degrees = degrees;
this.viewer.forceRedraw(); this.viewer.forceRedraw();
/** /**
* Raised when rotation has been changed. * Raised when rotation has been changed.
* *
@ -1089,7 +1090,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
return viewerCoordinates.plus( return viewerCoordinates.plus(
OpenSeadragon.getElementPosition( this.viewer.element )); OpenSeadragon.getElementPosition( this.viewer.element ));
}, },
/** /**
* Convert a viewport zoom to an image zoom. * Convert a viewport zoom to an image zoom.
* Image zoom: ratio of the original image size to displayed image size. * Image zoom: ratio of the original image size to displayed image size.
@ -1107,7 +1108,7 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{
var viewportToImageZoomRatio = containerWidth / imageWidth; var viewportToImageZoomRatio = containerWidth / imageWidth;
return viewportZoom * viewportToImageZoomRatio; return viewportZoom * viewportToImageZoomRatio;
}, },
/** /**
* Convert an image zoom to a viewport zoom. * Convert an image zoom to a viewport zoom.
* Image zoom: ratio of the original image size to displayed image size. * Image zoom: ratio of the original image size to displayed image size.