Skip to content

Instantly share code, notes, and snippets.

@chooban
Last active December 13, 2016 12:01
Show Gist options
  • Save chooban/34a007f1b7d474e88a254720d444e7ce to your computer and use it in GitHub Desktop.
Save chooban/34a007f1b7d474e88a254720d444e7ce to your computer and use it in GitHub Desktop.
Dice result table generator

Create an exportable table of results from a dice roll.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
<script>
var dice = [
"d4",
"d6",
"d10",
"d12",
"d20",
"d100"
];
var root = d3.select('body').append('div').classed('roller', true);
var controlsContainer = root.append('div').classed('controls', true),
controlsFieldSet = controlsContainer.append('fieldset');
controlsFieldSet.append('label').attr('for', 'diceselect').text('Dice');
var diceSelect = controlsFieldSet.append('select').attr('id', 'diceselect');
var options = diceSelect.selectAll('option').data(dice);
options.enter()
.append('option')
.attr('value', function(d) { return d; })
.text(function(d) { return d;} );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment