let N_CLICKS_SINGLE = 0;

(function initSingleRowPlot() {

    let svg_dy = 20,
        n_rows = 1,
        cells = constructCells(n_rows);

    // initialize plot
    addSVG("single", svg_dy);
    plotRects("single", cells);
})();

function clickSingleRow() {

    N_CLICKS_SINGLE++;

    if (N_CLICKS_SINGLE % 2 == 1) {

        // revert to original states if previously run
        if (N_CLICKS_SINGLE > 1) { 
            clearStates("single"); 
        }

        // run animation
        timerSingleRow = d3.interval(updateSingleRow, 125);

        // update button text
        d3.select("#button_single")
          .attr("value", "Stop");
    } else  {
        // stop animation
        timerSingleRow.stop(); 

        // update button text
        d3.select("#button_single")
          .attr("value", "Rerun");
    } 
}

function updateSingleRow() {
    d3.select("#plot_single")
      .selectAll(".row_0")
      .call(updateRow, "single", 0); 
}