Created
June 18, 2014 10:25
-
-
Save anonymous/b14d0e88ac38a84632a0 to your computer and use it in GitHub Desktop.
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="http:////cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div> | |
<svg id="threat" height="200" width="200"></svg> | |
</div> | |
<script> | |
var twoPi = 2 * Math.PI; | |
var width = 200; | |
var height = 200; | |
var progress = 0; | |
var total = 100; | |
var formatPercent = d3.format(".0%"); | |
var arc = d3.svg.arc() | |
.startAngle(0) | |
.innerRadius(65) | |
.outerRadius(95); | |
var svg = d3.select("#threat"); | |
var threatDial = svg.append("g").attr("class", "threat-dial"); | |
threatDial.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); | |
threatDial.append("path") | |
.attr("class", "background") | |
.attr("d", arc.endAngle(twoPi)); | |
var foreground = threatDial.append("path") | |
.attr("class", "foreground"); | |
var animate = function(score){ | |
var s = score; | |
var percentage = score / 100; | |
var i = d3.interpolate(progress, percentage); | |
d3.transition().duration(1200).tween("progress", function () { | |
return function (t) { | |
progress = i(t); | |
var severityClass = "foreground" | |
if (score > 0 && score < 25) { | |
} | |
foreground.attr("class", severityClass); | |
foreground.attr("d", arc.endAngle(twoPi * progress)); | |
//text.text(formatPercent(progress)); | |
}; | |
}); | |
}; | |
setTimeout(function () { | |
animate(22); | |
setTimeout(function () { | |
animate(45); | |
setTimeout(function () { | |
animate(60); | |
setTimeout(function () { | |
animate(85); | |
}, 1000); | |
}, 1000); | |
}, 1000); | |
}, 1000); | |
</script> | |
</body> | |
</html> |
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
.threat-dial { | |
.background { | |
fill: #E1E1E1; | |
stroke: #CCCCCC; | |
stroke-width: 1px; | |
} | |
.foreground { | |
fill: #FF0000; | |
} | |
.low { | |
fill: #3ADF00 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment