-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7beca0a
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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); | ||
}) |
This file contains 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
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> |