Is is possible to pass on dynamic delay to d3.interval

Is it possible to pass on dynamic delay in d3.interval?

In this Notebook, I am asking d3.interval to run at 1000ms delay. But is there a way I can ask d3.interval to run at 0ms, 1000ms, 2000ms, 3000ms respectively for interval# 1,2,3,4.

I tried like desiredDelay[counterF] but it did not work.

Thank you in advance.

I don’t think that d3.interval can accept a list like that. I’d simply iterate through the list of delays and yield the results after a delay. Perhaps, something like so:

  let delays = [1000, 2000, 3000, 4000];
  let cnt = 0;

  for (let t of delays) {
    await Promises.delay(t);
    yield ++cnt;

There’s a slew of options like this listed in the intro to generators notebook.

1 Like

Works as desired with following

const masterSelection = d3.selectAll('[class^="text"]');
const node = masterSelection.nodes();
const len = node.length - 1;
let counter = 0;
//const del = 1000;
const delay = [0, 1000, 2000, 3000];

function show() {

    const element = masterSelection["_groups"][0][counter];
    const selection =;

    if (counter > len) return
    d3.timeout(show, delay[counter]);

1 Like