Built with blockbuilder.org
Created
August 24, 2019 05:52
-
-
Save jwilber/af4caa65ce4b5ff0789e014918914f90 to your computer and use it in GitHub Desktop.
rough circles
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> | |
<html> | |
<head> | |
<script src="https://cdn.rawgit.com/pshihn/rough/master/dist/rough.js"></script> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
</head> | |
<body> | |
<!-- Create a div where the graph will take place --> | |
<div id="vis"></div> | |
<script> | |
const data = [1,5,3,4,7,1] | |
const margin = { top: 40, right: 20, bottom: 50, left: 100 } | |
const width = 920 - margin.left - margin.right; | |
const height = 420 - margin.top - margin.bottom; | |
let svg = d3.select('#vis') | |
.append('svg') | |
.attr('width', width + margin.left + margin.right) | |
.attr('height', height + margin.top + margin.bottom) | |
.append("g") | |
.attr('id', 'new') | |
.attr("transform", | |
"translate(" + margin.left + "," + margin.top + ")") | |
const roughSvg = document.getElementById('new'); | |
const rc = rough.svg(roughSvg, { | |
options: { | |
fill: 'chocolate', | |
stroke: 'chocolate' | |
} | |
}); | |
var max = d3.max(data); | |
var pix = 10; | |
data.forEach((d,i)=>{ | |
let node = rc.circle( | |
i*60+20, | |
40, | |
d*pix, | |
{ | |
fill:'green', | |
fillWeight: 0.5 // thicker lines for hachure | |
}) | |
let bar = roughSvg.appendChild(node); | |
bar.setAttribute('class', 'bar'); | |
}) | |
d3.selectAll('g.bar') | |
.on('mouseover', function() { | |
d3.select(this).selectAll('path').style('stroke', 'red') | |
}) | |
d3.selectAll('g.bar') | |
.on('mouseout', function() { | |
d3.select(this).selectAll('path').style('stroke', 'green') | |
d3.select(this).selectAll('path').attr('fill', 'orange') | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment