Built with blockbuilder.org
Last active
January 29, 2020 14:28
-
-
Save marijer/377b16deed2d4b1f6e01d4c108955f31 to your computer and use it in GitHub Desktop.
fresh block
This file contains hidden or 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 hidden or 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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<div id='chart'></div> | |
<script> | |
const numPerRow = 20; | |
// const size= 20; | |
let width = 800; | |
let height = 400; | |
let size = Math.round(width / numPerRow); | |
const scale = d3.scaleLinear() // <-A | |
.domain([0, numPerRow -1]) | |
.range([0, size * numPerRow]) | |
let sel = d3.select('#chart') | |
.append('svg') | |
.attr('width', height) | |
.attr('height', width); | |
sel.selectAll('rect') | |
.data(d3.range(220)) // <-B | |
.enter().append('rect') | |
.attr('x', (d, i) => { | |
const n = i % numPerRow // <-C | |
return scale(n) | |
}) | |
.attr('y', (d, i) => { | |
const n = Math.floor(i / 10) // <-D | |
return scale(n) | |
}) | |
.attr('width', size) | |
.attr('height', size) | |
.attr('fill', 'tomato') | |
.attr('stroke-width', 2) | |
.attr('stroke', 'white') | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment