Last active
December 17, 2015 16:59
-
-
Save pjsvis/5642407 to your computer and use it in GitHub Desktop.
jquery.flot.pie directive
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('flot') | |
.directive('flotPie', [function () { | |
'use strict'; | |
return { | |
restrict: 'E,A', | |
require: 'ngModel', | |
link: function (scope, elem, attrs, ngModel) { | |
var chart = null, | |
opts = { | |
series: { | |
pie: { | |
innerRadius: 0.25, | |
show: true, | |
combine: { | |
color: '#999', | |
threshold: 0.1 | |
}, | |
label: { | |
radius:8/18, | |
formatter: function(label, series){ | |
return '<div style="font-size:9pt;text-align:center;padding:2px;color:black;">'+label+'<br/>'+Math.round(series.percent)+'%</div>'; | |
}, | |
show: true, | |
background: {opacity:0, color: '#999' } | |
} | |
} | |
}, | |
legend: {show: false} | |
}; | |
var render=function(){ | |
var data = ngModel.$viewValue; | |
if(angular.isUndefined(data)){ | |
return; | |
} | |
chart = $.plot(elem, data, opts); | |
elem.show(); | |
}; | |
scope.$watch(attrs.ngModel, function (v) { | |
render(); | |
}); | |
// No need to re-render on window resize as we keep the donuts the same size | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment