Created
December 20, 2016 05:19
-
-
Save NPashaP/81a2c102a5060ba5c4bf83c1776adab3 to your computer and use it in GitHub Desktop.
lg - draw- line
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: gpl-3.0 |
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> | |
rect, line{ | |
fill:#3F51B5; | |
stroke:black; | |
} | |
line{ | |
stroke-width:3px; | |
} | |
</style> | |
<body> | |
<svg width="960" height="500"> | |
<g id="g1" transform="translate(200, 50)"></g> | |
<g id="g2" transform="translate(600, 50)"></g> | |
</svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="http://vizjs.org/viz.v1.1.8.min.js"></script> | |
<script> | |
var browsers = { | |
'Chrome':'#F44336','Edge':'#9C27B0','Netscape':'#3F51B5','Firefox':'#673AB7','Safari':'#2196F3' | |
,'Vivaldi':'#009688', 'Opera':'#795548', 'Dooble':'#607D8B' | |
}; | |
//default | |
var lg = viz.lg().data(d3.keys(browsers)).fill(function(d){ return browsers[d.key];}); | |
d3.select("#g1").call(lg); | |
//custom | |
function line(d){ | |
d3.select(this).append("line") | |
.attr("class",'legend-icon') | |
.attr("x1",0) | |
.attr("y1",function(d){ return d.height/2;}) | |
.attr("x2",function(d){ return d.width; }) | |
.attr("y2",function(d){ return d.height/2; }) | |
.style("stroke",function(d){ return browsers[d.key];}) | |
; | |
} | |
var lg = viz.lg().data(d3.keys(browsers)) | |
.size(50) | |
.draw(line); | |
d3.select("#g2").call(lg); | |
// adjust the bl.ocks frame dimension. Not part of example. | |
d3.select(self.frameElement).style("height", "500px").style("width", "960px"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment