Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
d3 syntaxr
<meta charset="utf-8">
<style>body{font-size:28px}</style>
<body></body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script>
var a =
`function readtime(time) {
if (time == 'DNF') { return time; }
time = parseInt(time);
var min = 0;
var sec = (Math.floor(time/1000)%60);
min = Math.floor(time/60000);
if (min!=0&&sec<10) { sec = '0'+sec; }
time = Math.floor(time/10);
time = time.toString().slice(-2);
if (min) return min+':'+sec+'.'+time;
else return sec+'.'+time;
}
function stoptimer() {
end_time = performance.now();
clearInterval(window.timer);
solve_time = end_time - start_time;
get('timer').innerHTML = readtime(solve_time);
times[times.length] = solve_time;
updatetimes();
cubestate = 0;
}`;
d3.select('body')
.append('pre')
.selectAll('div')
.data(a.split('\n').map(d=>d.match(/\W|\w*/g)))
.enter()
.append('div')
.selectAll('span')
.data(d=>d)
.enter()
.append('span')
.html(d=>d==" "?'&nbsp;':d)
.style('color',d=>`#17b #f70 #2a2 #d22 #96b #854 #e7c #777 #bb2`.split(' ')[`functionifvar}return(-.[&><;/)+{]'"=`.indexOf(d)%9])
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment