D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
bmershon
Full window
Github gist
Sieve of Eratosthenes
See
From Mathematics to Generic Programming
.
<!DOCTYPE html> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <body> <p id="time"></p> </body> <script> // From Mathematics to Generic Programming, p. 27. var worker = new Worker("./worker.js"); // Compute prime less than 100,000. worker.postMessage({ n: 100000}); worker.onmessage = function(event) { switch (event.data.type) { case "end": return ended(event.data); } }; // Render computed primes when the Web Worker is done. function ended(data) { d3.select("#time") .style("margin-left", "5px") .style("font-size", "14px") .style("color", "#aaa") .style("font-family", "helvetica") .html("Sifted " + d3.format(",")(data.values.length) + " primes in " + data.elapsed + " ms"); d3.select("body").append("p") .datum(data.values) .html(function(d) { return d.join(" "); }) .style("margin", "0 auto") .style("font-size", "18px") .style("font-family", "helvetica") .style("line-height", "1.4em") .style("width", "720px"); } </script>
https://d3js.org/d3.v4.min.js