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

Interact with chemViewer objects/molecules #314

Open
cleblond opened this issue Dec 28, 2023 · 2 comments
Open

Interact with chemViewer objects/molecules #314

cleblond opened this issue Dec 28, 2023 · 2 comments

Comments

@cleblond
Copy link

I want to hover over a molecule in a chemViewer, have it highlighted and then run some code based on the molecule hovered over. I have been playing with hot tracking event but it seems to focus on atoms and bonds, not molecules.

Kekule.X.Event.addListener(chemViewer, 'hotTrackOnObjects', function(e) {
console.log(e]);
// if molecule A is selected run code
});

Thank you for your help!
Carl

@partridgejiang
Copy link
Owner

The molecule can be retrieved by accessing the parent property recursively on atom or bond, or by calling the getStandaloneAncestor() function e.g.:

chemViewer.addEventListener('hotTrackOnObjects', e => {
  let hotTrackedMolecules = [];
  e.objects.forEach(obj => {
    if (obj.getStandaloneAncestor)
      Kekule.ArrayUtils.pushUnique(hotTrackedMolecules, obj.getStandaloneAncestor());
  });
  chemViewer.setHotTrackedObjects(hotTrackedMolecules);
});

@cleblond
Copy link
Author

getStandaloneAncestor did the trick. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants