Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active December 22, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/6438532 to your computer and use it in GitHub Desktop.
Save joyrexus/6438532 to your computer and use it in GitHub Desktop.
DIY DOM W/ D3
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.6.3/coffee-script.min.js"></script>
<style>
body {
margin: 80px;
font-family: "Helvetica Neue";
font-weight: 100;
font-size: 400px;
color: #333;
}
</style>
<body>
<script type="text/coffeescript">
say = (msg) ->
event = d3.dispatch 'click'
clickable = (selection) -> selection.append('div').text(msg)
.on('click', -> event.click(msg))
d3.rebind clickable, event, 'on'
d3.select('body').call say('hi!').on('click', (msg) -> alert msg)
</script>
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
body {
margin: 80px;
font-family: "Helvetica Neue";
font-weight: 100;
font-size: 400px;
color: #333;
}
</style>
<body>
<script>
function say(msg) {
var event = d3.dispatch('click');
return d3.rebind(function(selection) {
selection.append('div').text(msg)
.on('click', function() {
event.click(msg);
});
}, event, 'on');
}
d3.select('body').call(say('hi!')
.on('click', function(msg) {
alert(msg);
}));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment