Circle Gradient with Linear scale
Last active
July 22, 2016 19:13
-
-
Save EfratVil/34aedb6c55cd255771f87a9f40057d04 to your computer and use it in GitHub Desktop.
Circle Gradient II
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> | |
<meta charset="utf-8"> | |
<body> | |
<script src="//d3js.org/d3.v4.min.js"></script> | |
<script> | |
var margin = 0, | |
width = 960 - margin, | |
height = 250 - margin; | |
var colorRange = ['#d73027', '#e0e0e0', '#4575b4'] | |
var color = d3.scaleLinear().range(colorRange).domain([-1, 0, 1]); | |
var svg = d3.select('body') | |
.append('svg') | |
.attr("width", width + (margin * 2)) | |
.attr("height", height + (margin * 2)) | |
.append("g") | |
.attr("transform", "translate(" + (margin) + "," + (margin) + ")"); | |
var radialGradient = svg.append("defs") | |
.append("radialGradient") | |
.attr("id", "radial-gradient"); | |
radialGradient.append("stop") | |
.attr("offset", "0%") | |
.attr("stop-color", color(-1)); | |
radialGradient.append("stop") | |
.attr("offset", "50%") | |
.attr("stop-color", color(0)); | |
radialGradient.append("stop") | |
.attr("offset", "100%") | |
.attr("stop-color", color(1)); | |
svg.append("circle") | |
.attr("cx", width * 0.5) | |
.attr("cy", height * 0.5) | |
.attr("r", height * 0.3) | |
.style("opacity", 1.0) | |
.style("fill", "url(#radial-gradient)"); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment