ethstats-server/public/js/directives.js

78 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-01-20 19:29:31 +01:00
'use strict';
/* Directives */
angular.module('netStatsApp.directives', []).
directive('appVersion', ['version', function(version) {
return function(scope, elm, attrs) {
elm.text(version);
};
2015-02-08 16:03:05 +01:00
}]).
directive('nodemap', ['$compile', function($compile) {
return {
restrict: 'EA',
scope: {
data: '='
},
link: function(scope, element, attrs) {
2015-04-17 02:12:15 +02:00
var bubbleConfig = {
borderWidth: 0,
highlightOnHover: false,
popupOnHover: true,
popupTemplate: function(geo, data) {
return ['<div class="tooltip-arrow"></div><div class="hoverinfo ' + data.fillClass + '"><div class="propagationBox"></div><strong>',
data.nodeName,
'</strong></div>'].join('');
}
};
2015-02-08 16:20:43 +01:00
scope.init = function() {
element.empty();
scope.map = new Datamap({
element: element[0],
scope: 'world',
responsive: true,
fills: {
2015-04-17 02:12:15 +02:00
success: '#7BCC3A',
info: '#10A0DE',
2015-02-08 16:20:43 +01:00
warning: '#FFD162',
2015-04-17 02:12:15 +02:00
orange: '#FF8A00',
2015-02-08 16:20:43 +01:00
danger: '#F74B4B',
defaultFill: '#282828'
},
geographyConfig: {
borderWidth: 0,
borderColor: '#000',
highlightOnHover: false,
popupOnHover: false
},
bubblesConfig: {
borderWidth: 0,
2015-04-17 02:12:15 +02:00
highlightOnHover: false,
popupOnHover: true
2015-02-08 16:20:43 +01:00
}
});
2015-04-17 02:12:15 +02:00
scope.map.bubbles(scope.data, bubbleConfig);
2015-02-08 16:20:43 +01:00
}
scope.init();
2015-02-08 16:03:05 +01:00
2015-02-08 16:20:43 +01:00
window.onresize = function() {
scope.$apply();
};
2015-02-08 16:03:05 +01:00
scope.$watch('data', function() {
2015-04-17 02:12:15 +02:00
scope.map.bubbles(scope.data, bubbleConfig);
2015-02-08 16:03:05 +01:00
}, true);
2015-02-08 16:20:43 +01:00
scope.$watch(function() {
return angular.element(window)[0].innerWidth;
}, function() {
scope.init();
});
2015-02-08 16:03:05 +01:00
}
};
}]);