Skip to content

Instantly share code, notes, and snippets.

@danharr
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danharr/10506849 to your computer and use it in GitHub Desktop.
Save danharr/10506849 to your computer and use it in GitHub Desktop.
slider to control a circle size
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
input {
position:absolute;
left:200px;
top:20px;
}
</style>
</head>
<body ng-app="myApp" ng-init="chart=[10]">
<input type="range" ng-model="chart[0]">
<my-circle data="chart"></my-circle>
<script>
var myApp = angular.module('myApp', []);
myApp.directive('myCircle', function(){
function link(scope, el, attr){
var color = d3.scale.category10();
var data = scope.data;
var width = 800;
var height = 800;
var min = Math.min(width, height);
var svg = d3.select(el[0]).append('svg');
svg.attr({width: width, height: height});
var g = svg.append('g')
// center the donut chart
.attr('transform', 'translate( 100 , 100 )');
// add the <path>s for each arc slice
var arcs = g.selectAll('circle').data(data)
.enter().append('circle')
.style('stroke', 'white')
.attr("cx",50)
.attr("cy",50)
.attr("r",function(d,i) {return d;})
.attr('fill', function(d,i) {return color(d);});
scope.$watch('data', function(){
arcs.data(data)
.attr("r",function(d,i) {return d;})
.attr('fill', function(d,i) {return color(d);})
.style("stroke","black")
.style("stroke-width",function(d,i) {return d/10;});
}, true);
}
return {
link: link,
restrict: 'E',
scope: { data: '=' }
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment