Skip to content

Commit

Permalink
Do not reset the viewer when initializing the atoms (#22)
Browse files Browse the repository at this point in the history
Add a `updateAtoms` method to update the atoms without resetting the viewer. When initializing the atoms, only need to update the atoms, without resetting the viewer.
  • Loading branch information
superstar54 authored Sep 18, 2024
1 parent 6285924 commit d97ecc8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/atoms/AtomsViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ class AtomsViewer {
}

init(atoms) {
this.reset();
this.selectedAtomsLabelElement = document.createElement("div");
this.selectedAtomsLabelElement.id = "selectedAtomSymbol";
this.tjs.containerElement.appendChild(this.selectedAtomsLabelElement);
// update the atoms
this.atoms = atoms;
// only need to update the atoms, without reset the viewer
this.updateAtoms(atoms);
this.logger.debug("init AtomsViewer successfully");
}

Expand Down Expand Up @@ -176,10 +175,16 @@ class AtomsViewer {
}

set atoms(atoms) {
// Set a new atoms object
// This will dispose the current objects, reset the viewer, and update the new atoms
this.ready = false;
this.dispose();
this.reset();
this.logger.debug("set atoms: ");
this.updateAtoms(atoms);
}

updateAtoms(atoms) {
// Update the trajectory, managers, and draw the models
// if atoms is a array, which means it is a trajectory data
// only the first frame is used to initialize the viewer
// but keep the trajectory data for the future use
Expand Down

0 comments on commit d97ecc8

Please sign in to comment.