latency-graph.js 904 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. angular.module('etcd.ui').directive('coLatencyGraph', function(etcdApiSvc,
  3. $, d3, _, graphConfig) {
  4. return {
  5. templateUrl: '/ui/latency-graph.html',
  6. restrict: 'E',
  7. replace: true,
  8. scope: {
  9. peerData: '='
  10. },
  11. link: function postLink(scope, elem, attrs) {
  12. var padding = 60;
  13. function updateGraph() {
  14. var width = elem.width() - padding,
  15. height = 300;
  16. vg.parse.spec(graphConfig, function(chart) {
  17. chart({
  18. el: elem[0],
  19. data: {
  20. 'stats': scope.peerData
  21. }
  22. })
  23. .width(width)
  24. .height(height)
  25. .update();
  26. });
  27. }
  28. scope.$watch('peerData', function(peerData) {
  29. if (!_.isEmpty(peerData)) {
  30. updateGraph();
  31. }
  32. });
  33. elem.on('$destroy', function() {
  34. });
  35. }
  36. };
  37. });