Skip to content

Instantly share code, notes, and snippets.

@pjsvis
Last active December 17, 2015 16:59
Show Gist options
  • Save pjsvis/5642417 to your computer and use it in GitHub Desktop.
Save pjsvis/5642417 to your computer and use it in GitHub Desktop.
flot.line.js
angular.module('flot')
.directive('flotLine', [function () {
'use strict';
return {
restrict: 'EA',
require: 'ngModel',
link: function (scope, elem, attrs, ngModel) {
var chart = null,
opts = {
xaxis: { mode: "time" },
legend:{position: "nw"}
};
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();
});
// If we have underscore/lodash then re-render on window resize
typeof _ !== 'undefined' ? $(window).resize(_.debounce(render, 500)) : angular.noop();
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment