Built with blockbuilder.org
Created
October 15, 2019 18:52
-
-
Save mforando/9a465992d96989f4333ab2235f18a0c6 to your computer and use it in GitHub Desktop.
Legend Component Mock Up
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> | |
<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> | |
<script> | |
var randvals = [10,20,50]; | |
var width = 200; | |
var pad = 40; | |
var radiusScale = d3.scaleLinear() | |
.domain([Math.sqrt(5),Math.sqrt(50)]) | |
.range([2,width/2 - pad]); | |
// Feel free to change or delete any of the code you see in this editor! | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", width) | |
svg.append("text") | |
.attr("dx",width/2) | |
.attr("dy",pad/2) | |
.style("font-family","Franklin Gothic Medium") | |
.style("text-anchor","middle") | |
.text('Legend') | |
svg.selectAll("circle") | |
.data(randvals) | |
.enter() | |
.append("circle") | |
.attr("r",(d)=>{return radiusScale(Math.sqrt(d))}) | |
.attr("fill","none") | |
.attr("stroke","rgba(0,0,0,.5)") | |
.attr("cy", (d)=>{return width - pad - radiusScale(Math.sqrt(d))}) | |
.attr("cx", width/2) | |
svg.selectAll(".labels") | |
.data(randvals) | |
.enter() | |
.append("text") | |
.attr("class","labels") | |
.text((d)=>{return d}) | |
.attr("fill","black") | |
.style("text-anchor","middle") | |
.style("dominant-baseline","text-before-edge") | |
.style("font-size","11px") | |
.attr("y", (d)=>{return width - pad - radiusScale(Math.sqrt(d))*2}) | |
.attr("x", width/2) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment