Built with blockbuilder.org
Created
October 13, 2018 22:53
-
-
Save jwilber/4c16eacc7cb198312067b88dddf47f04 to your computer and use it in GitHub Desktop.
Vertical Grid Lines
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
license: mit |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
path:nth-child(even) { | |
fill: none; | |
stroke: coral; | |
stroke-width: 3; | |
} | |
path:nth-child(odd) { | |
fill: none; | |
stroke: skyblue; | |
stroke-width: 4; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v4.js"></script> | |
<script src="http://romsson.github.io/d3-gridding/build/d3-gridding.js"></script> | |
<script> | |
var width = 600, | |
height = 400, | |
n = 3050, | |
j = 4, | |
l = 5, | |
o = 1; | |
var gridding = d3.gridding() | |
.size([width, height]) | |
.mode("brick"); | |
var line = d3.line() | |
.x(function(d) { | |
return d.x + Math.random() * j ; | |
}) | |
.y(function(d) { | |
return d.y + Math.random() * j; | |
}) | |
.curve(d3.curveBasis); | |
var data = d3.range(n).map(function(d, i) { | |
return {index: i}; | |
}); | |
var svgSquares = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g"); | |
svgSquares.selectAll(".line") | |
.data(gridding(data)).enter() | |
.append("path") | |
.attr("class", "line") | |
.attr("d", function(d) { | |
var offset = o * Math.random(); | |
var points = d3.range(l).map(function(e) { | |
var res = {}; | |
res.x = d.cx + offset; | |
res.y = d.cy + (e * (d.height + 20 ) / l); | |
return res; | |
}); | |
return line(points); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment