Test of continuously updating rows in a Zambezi Grid.
-
-
Save cristiano-belloni/48eafad516255d71304056c2ab32a269 to your computer and use it in GitHub Desktop.
Updating rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<head><meta charset="utf-8" /></head> | |
<body> | |
<h2>updating grid example</h2> | |
<button id="start-updates">Start updates</button> | |
<button id="stop-updates">Stop updates</button> | |
<div class="grid-target"></div> | |
<link rel="stylesheet" type="text/css" href="https://npmcdn.com/[email protected]"> | |
<script src="https://npmcdn.com/[email protected]"></script> | |
<script src="https://npmcdn.com/[email protected]/faker.js"></script> | |
<script src="https://npmcdn.com/@zambezi/[email protected]"></script> | |
<script src="https://d3js.org/d3.v4.js"></script> | |
<script src="https://npmcdn.com/@zambezi/[email protected]"></script> | |
<script src="https://npmcdn.com/@zambezi/[email protected]"></script> | |
<script> | |
var table = grid.createGrid() | |
, rows = _.shuffle(_.range(1, 1000).map(_.compose(_.partial(_.pick, _, 'name', 'username', 'email'), faker.Helpers.createCard)).map(function(row, i) { | |
row.id = 'row' + i | |
return row | |
})) | |
var grid = d3.select('.grid-target') | |
.style('height', '500px') | |
.datum(rows) | |
.call(table) | |
d3.select('#start-updates') | |
.on('click', startUpdates) | |
d3.select('#stop-updates') | |
.on('click', stopUpdates) | |
var updates | |
function stopUpdates() { | |
updates && updates.forEach(clearInterval) | |
} | |
function startUpdates() { | |
updates = rows.map(function(n, i) { | |
var id = 'row' + i | |
return setInterval(function() { | |
rows.some(function(row) { | |
if (row.id === id) { | |
row.username = Math.random().toString(16) | |
grid.call(table) | |
return true | |
} | |
}) | |
}, 1000 + Math.floor(Math.random() * 100)) | |
}) | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment