Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNeuralBit committed Oct 9, 2015
0 parents commit 7beca0a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
64 changes: 64 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
var panel = d3.select('#panel')
var w = 300;
var h = 100;
var svg = panel.append('svg:svg').attr('width', w).attr('height', h)
var str1 = strParse('the neural bit');
var str2 = strParse('brian hulette');

function strParse(str) {
var rtrn = []
var char_count = {};
for (var i = 0; i < str.length; i++) {
if (typeof char_count[str[i]] !== 'undefined') {
char_count[str[i]] += 1;
} else {
char_count[str[i]] = 0;
}
rtrn.push({
c: str[i],
count: char_count[str[i]]
});
}
return rtrn;
}

function key(d) {
return d.c + d.count;
}

svg.selectAll('text')
.data(str1)
.enter()
.append('text')
.attr('x', function (d, i) {
return i * 10;
})
.attr('y', h/2)
.attr('fill', 'black')
.text(function (d) {
return d.c;
});


function toggle(str) {
return svg.selectAll('text')
.data(str, key)
.transition()
.duration(1000)
.attr('x', function (d, i) {
return i * 10;
})
.attrTween('y', function (d, i) {
var peak = Math.random() * h - h/2;
return function (t) {
return h/2 - (-4 * peak * Math.pow(t, 2) + 4 * peak * t);
}
});
}

var active = false;

svg.on('mouseover', function() {
toggle(str2);
toggle(str1).delay(2000);
})
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<body>
<div id="panel"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script type="text/javascript" src="./app.js"></script>
</body>
</html>

0 comments on commit 7beca0a

Please sign in to comment.