Last active
December 17, 2015 16:59
-
-
Save pjsvis/5642380 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
// AngularJS Directive for jQuery Sparklines | |
// Dependencies: jquery and http://omnipotent.net/jquery.sparkline/ | |
angular.module('sparkline',[]) | |
angular.module('sparkline') | |
.directive('jqSparkline', [function () { | |
'use strict'; | |
return { | |
restrict: 'E,A', | |
require: 'ngModel', | |
link: function (scope, elem, attrs, ngModel) { | |
var sparkline = null; | |
var opts = { | |
type: attrs.type, | |
width: attrs.width || '100%', | |
height: attrs.height || attrs.width * 3 / 4, | |
lineColor: attrs.lineColor, | |
fillColor: attrs.fillColor, | |
disableHiddenCheck: true | |
}; | |
scope.$watch(attrs.ngModel, function () { | |
render(); | |
}); | |
var render = function () { | |
sparkline=null; | |
var data = ngModel.$viewValue; | |
sparkline = $(elem).sparkline(data, opts); | |
}; | |
$(window).resize(function(){ | |
render(); | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment