var row_length = 5; var col_length = 5; var total_width = 900; var cell_padding = 20; var cell_border = 1; var cell_width = (total_width / row_length) - ((cell_padding * 2) + (2 * cell_border)); var google_url = "https://docs.google.com/spreadsheets/u/1/d/1mcxBgRGG7X9uU6ttSMEl8ZBQ8A3wWcyjPymEpuW85Vw/pubhtml" // call to kick off process function init() { Tabletop.init({key: google_url, callback: createBingoCard, simpleSheet: true, debug:false}); } // main function function createBingoCard(data, tabletop) { var bData = prepareData(data); createCard(bData); } // create the card function createCard(data) { var card = d3.select('#card'); card .style('width', (total_width) + 'px'); var cell = card.selectAll('.cell') .data(data); cell.enter() .append('div') .classed('cell', true) .style('width', (cell_width) + 'px') .style('height', (cell_width) + 'px') // .style('line-height', cell_width + 'px') .style('padding', cell_padding + 'px') // .style('padding-top', (cell_padding * 2) + 'px') .style('border-width', cell_border + 'px') .text(function(d) { return d.text; }); } // shuffle rows, add in free space function prepareData(data) { var bingoData = shuffle(data); bingoData = bingoData.slice(0, (row_length * col_length) - 1); // middle of middle row var free_index = Math.floor(row_length / 2) + (row_length * Math.floor(col_length / 2)); var free_space = {"text": "FREE SPACE"}; console.log(free_index) bingoData.splice(free_index, 0, free_space) return bingoData; } // from: https://bost.ocks.org/mike/shuffle/ function shuffle(array) { var m = array.length, t, i; // While there remain elements to shuffle… while (m) { // Pick a remaining element… i = Math.floor(Math.random() * m--); // And swap it with the current element. t = array[m]; array[m] = array[i]; array[i] = t; } return array; } init();