Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active August 2, 2017 11:09
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 d3indepth/00bd03fa9ddf292a856a734102e74d9d to your computer and use it in GitHub Desktop.
Save d3indepth/00bd03fa9ddf292a856a734102e74d9d to your computer and use it in GitHub Desktop.
Data join without key function
license: gpl-3.0
height: 130
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Data join without key function</title>
</head>
<style>
body {
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 14px;
color: #333;
}
#content {
position: relative;
height: 40px;
}
#content div {
position: absolute;
margin: 2px;
background-color: orange;
color: white;
padding: 8px;
width: 14px;
height: 14px;
text-align: center;
}
</style>
<body>
<div id="content">
</div>
<div id="menu">
<button onClick="doInsert();">Insert element</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var i = 25;
function doInsert() {
if(i < 0)
return;
var myData = letters.slice(i).split('');
i--;
update(myData);
}
function update(data) {
var u = d3.select('#content')
.selectAll('div')
.data(data);
u.enter()
.append('div')
.merge(u)
.transition()
.style('left', function(d, i) {
return i * 32 + 'px';
})
.text(function(d) {
return d;
});
}
doInsert();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment