A Pen by Daniele Moraschi on CodePen.
Created
March 10, 2014 12:35
-
-
Save anonymous/9464234 to your computer and use it in GitHub Desktop.
A Pen by Daniele Moraschi.
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
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
<div ng-app="myApp"> | |
<bars data="40,4,55,15,16,33,52,20"></bars> | |
</div> |
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
angular.module('myApp', []). | |
directive('bars', function ($parse) { | |
return { | |
restrict: 'E', | |
replace: true, | |
template: '<div id="chart"></div>', | |
link: function (scope, element, attrs) { | |
var data = attrs.data.split(','), | |
chart = d3.select('#chart') | |
.append("div").attr("class", "chart") | |
.selectAll('div') | |
.data(data).enter() | |
.append("div") | |
.transition().ease("elastic") | |
.style("width", function(d) { return d + "%"; }) | |
.text(function(d) { return d + "%"; }); | |
} | |
}; | |
}); |
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
.chart { | |
background: #eee; | |
padding: 3px; | |
} | |
.chart div { | |
width: 0; | |
transition: all 1s ease-out; | |
-moz-transition: all 1s ease-out; | |
-webkit-transition: all 1s ease-out; | |
} | |
.chart div { | |
font: 10px sans-serif; | |
background-color: steelblue; | |
text-align: right; | |
padding: 3px; | |
margin: 5px; | |
color: white; | |
box-shadow: 2px 2px 2px #666; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment