Skip to content

Commit

Permalink
rename viewer atomClick/atomDoubleClick options
Browse files Browse the repository at this point in the history
The two have been renamed to atomDoubleClicked and atomClicked to make
the names consistent with the actual event names. It's still possible
to use atomDoubleClick/atomClick in the viewer constructor for now,
but we issue an error and say that atomClicked/atomDoubleClicked is
the way to go.
  • Loading branch information
biasmv committed Jan 20, 2015
1 parent 0a3b593 commit 00d47d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions doc/viewer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Initialization and Configuration
* *quality* the level of detail for the geometry. Accepted values are *low*, *medium*, and *high*. See :func:`~pv.Viewer.quality` for a description of these values. Defaults to *low*.
* *slabMode* sets the default slab mode for the viewer. See :func:`~pv.Viewer.slabMode` for possible values. Defaults to 'auto'.
* *background* set the default background color of the viewer. Defaults to 'white'. See :ref:`pv.color.notation`
* *atomDoubleClick* set the event handler for an atom double clicked event. When the parameter is a function it is added as a new 'atomDoubleClicked' event handler. See :func:`~pv.Viewer.addListener` for details. If it is set to the special value 'center', an event listener is installed that centers the viewer on the double clicked atom, residue. The default is 'center'.
* *atomClicked* set the event handler for an atom double clicked event (see *atomDoubleClick*). The default is null (no listener).
* *atomDoubleClicked* set the event handler for an atom double clicked event. When the parameter is a function it is added as a new 'atomDoubleClicked' event handler. See :func:`~pv.Viewer.addListener` for details. If it is set to the special value 'center', an event listener is installed that centers the viewer on the double clicked atom, residue. The default is 'center'.
* *atomClicked* set the event handler for an atom double clicked event (see *atomDoubleClicked*). The default is null (no listener).
* *animateTime* controls the default animation duration in milliseconds. By default, the animation is set to 0 (no animation). By setting it to higher values, rotation, zoom and shift are animated. Note that enabling this can have negative impact on performance, especially with large molecules and on low-end devices.
* *fog* whether depth-cue ('fog') should be enabled. By default, fog is enabled. Pass false to disable fog.

Expand Down
24 changes: 15 additions & 9 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ function PV(domElement, opts) {

this.quality(this._options.quality);

if (this._options.atomDoubleClick !== null) {
this.addListener('atomDoubleClicked', this._options.atomDoubleClick);
if (this._options.atomDoubleClicked !== null) {
this.addListener('atomDoubleClicked', this._options.atomDoubleClicked);
}
if (this._options.atomClick !== null) {
this.addListener('atomClicked', this._options.atomClick);
Expand All @@ -148,7 +148,7 @@ function PV(domElement, opts) {
}
}

function getOptOrDefault(opts, name, defaultValue) {
function optValue(opts, name, defaultValue) {
if (name in opts) {
return opts[name];
}
Expand All @@ -164,15 +164,21 @@ PV.prototype = {
height : (opts.height || 500),
animateTime : (opts.animateTime || 0),
antialias : opts.antialias,
quality : getOptOrDefault(opts, 'quality', 'low'),
style : getOptOrDefault(opts, 'style', 'hemilight'),
quality : optValue(opts, 'quality', 'low'),
style : optValue(opts, 'style', 'hemilight'),
background : forceRGB(opts.background || 'white'),
slabMode : slabModeToStrategy(opts.slabMode),
atomClick: opts.atomClick || null,
outline : getOptOrDefault(opts, 'outline', true),
atomDoubleClick : getOptOrDefault(opts, 'atomDoubleClick', 'center'),
fog : getOptOrDefault(opts, 'fog', true)
atomClick: opts.atomClicked || opts.atomClick || null,
outline : optValue(opts, 'outline', true),
// for backwards compatibility
atomDoubleClicked : optValue(opts, 'atomDoubleClicked',
optValue(opts, 'atomDoubleClick', 'center')),
fog : optValue(opts, 'fog', true)
};
if ('atomDoubleClick' in opts || 'atomClick' in opts) {
console.warn('use of atomDoubleClick/atomClick is deprecated. ',
'use atomDoubleClicked/atomClicked instead');
}
var parentRect = domElement.getBoundingClientRect();
if (options.width === 'auto') {
options.width = parentRect.width;
Expand Down

0 comments on commit 00d47d8

Please sign in to comment.