Last active
August 29, 2015 14:04
-
-
Save Boggin/33b1500915a25ef66163 to your computer and use it in GitHub Desktop.
AngularJS level-meter directive.
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
.level-meter__content { | |
background: #fff; | |
} | |
.level-meter__box { | |
fill: none; | |
stroke: #7d7d7d; | |
} | |
.level-meter__bar-empty { | |
fill: #7d7d7d; | |
stroke: #7d7d7d; | |
} | |
.level-meter__bar-low { | |
fill: #f06a00; | |
stroke: #f06a00; | |
} | |
.level-meter__bar-med { | |
fill: #3fa6cc; | |
stroke: #3fa6cc; | |
} | |
.level-meter__bar-high { | |
fill: #6dc040; | |
stroke: #6ec040; | |
} |
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> | |
<html ng-app="level-meter"> | |
<head> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script> | |
<script type="text/ng-template" id="level-meter"> | |
<svg | |
xmlns:svg="http://www.w3.org/2000/svg" | |
xmlns="http://www.w3.org/2000/svg" | |
version="1.1" | |
class="level-meter__content" | |
width=83 | |
height=35> | |
<g | |
id="layer-level-meter" | |
style="display:inline"> | |
<rect | |
width="78" | |
height="30" | |
x="2.5" | |
y="2.5" | |
class="level-meter__box" /> | |
<rect | |
width="12" | |
height="24" | |
x="5.5" | |
y="5.5" | |
class="{{low}}" /> | |
<rect | |
width="12" | |
height="24" | |
x="20.5" | |
y="5.5" | |
class="{{med}}" /> | |
<rect | |
width="12" | |
height="24" | |
x="35.5" | |
y="5.5" | |
class="{{med}}" /> | |
<rect | |
width="12" | |
height="24" | |
x="50.5" | |
y="5.5" | |
class="{{high}}" /> | |
<rect | |
width="12" | |
height="24" | |
x="65.5" | |
y="5.5" | |
class="{{high}}" /> | |
</g> | |
</svg> | |
</script> | |
</head> | |
<body> | |
<level-meter level="3"></level-meter> | |
</body> | |
</html> |
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
var meter = angular.module('level-meter', []) | |
.directive( 'levelMeter', function() { | |
return { | |
restrict: 'EA', | |
replace: true, | |
scope: { | |
level: '=' | |
}, | |
templateUrl: 'level-meter', | |
link: function (scope, element, attrs) { | |
scope.high = | |
scope.med = | |
scope.low = "level-meter__bar-empty"; | |
if (scope.level >= 1) { | |
scope.low = "level-meter__bar-low"; | |
} | |
if (scope.level >= 3) { | |
scope.med = "level-meter__bar-med"; | |
} | |
if (scope.level >= 5) { | |
scope.high = "level-meter__bar-high"; | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment