Skip to content

Commit

Permalink
show/hide all labels convenience functions
Browse files Browse the repository at this point in the history
Issue #808
  • Loading branch information
dkoes committed Sep 10, 2024
1 parent 13d8fc5 commit b54feaf
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/GLShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ export interface CylinderSpec extends ShapeSpec {
dashLength?: number;
/** Length of gaps (default 0.25) */
gapLength?: number;
/** hidden */
hidden?: boolean;
};

/**
Expand Down
49 changes: 49 additions & 0 deletions src/GLViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,55 @@ export class GLViewer {
return this;
};

/**
* Hide all labels in viewer
*
* @example
$3Dmol.download("pdb:1ubq",viewer,{},function(){
viewer.addResLabels();
viewer.setStyle({},{stick:{}});
viewer.render( ); //show labels
viewer.hideAllLabels();
viewer.render(); //hide labels
});
*/
public hideAllLabels() {
for (var i = 0; i < this.labels.length; i++) {
if (this.labels[i]) {
this.labels[i].hide();
}
}
this.show();
return this;
};

/**
* Show all labels in viewer
*
* @example
$3Dmol.download("pdb:1ubq",viewer,{},function(){
viewer.addResLabels();
viewer.setStyle({},{stick:{}});
viewer.render( ); //show labels
viewer.hideAllLabels();
viewer.showAllLabels();
viewer.render(); //hide labels
});
*/
public showAllLabels() {
for (var i = 0; i < this.labels.length; i++) {
if (this.labels[i]) {
this.labels[i].show();
}
}
this.show();
return this;
};

// Modify label style
/**
* Modify existing label's style
Expand Down
9 changes: 6 additions & 3 deletions src/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,16 @@ export class Label {

/** Hide this label. */
public hide() {
this.sprite.visible = false;
if(this.sprite) {
this.sprite.visible = false;
}
}

/** Show a hidden label. */
public show() {

this.sprite.visible = true;
if(this.sprite) {
this.sprite.visible = true;
}
}

setContext() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b54feaf

Please sign in to comment.