Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
How to reduce function call count for a function that is run after animation completion with Cytoscape

I have an animation on a collection of nodes. However, after completion of the animation I want it to call a function just once, but the function is apparently called as many times as there are nodes in the collection. Is there a way to stop this? I just want it to run once. Fairly new to Javascript, appreciate any help.

  collection.animate({
    style: {
      'line-color': 'red',
      'target-arrow-color': 'red',
      'border-width': 20,
      'border-color': 'red'
    }
  }, {
    'duration': 3000,
    'complete': () => "hello world";
  });

Prints 9x "hello world" since my collection of nodes and edges is of length 9 (subbranch of nodes & edges in a directed graph)

https://i.imgur.com/K3yyMv7.gif

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This should be easy. Just put a boolean variable to check if is already executed.

let isExecuted = false;

collection.animate({
  style: {
    'line-color': 'red',
    'target-arrow-color': 'red',
    'border-width': 20,
    'border-color': 'red'
  }
}, {
  'duration': 3000,
  'complete': () => {
    if (isExecuted) {
      return;
    }
    console.log("hello world");
    isExecuted = true;
  };
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!