github.com/sym3tri/etcd@v0.2.1-0.20140422215517-a563d82f95d6/mod/dashboard/app/ui/latency-graph.js (about)

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