blob: d30122cf02fc6fc8a8fb1d0123f09b219d96509f [file] [log] [blame]
Matteo Scandoloda19dff2016-02-08 16:55:44 -08001(function () {
2 'use strict';
3
4 angular.module('xos.serviceTopology')
5 .directive('serviceTopology', function(){
6 return {
7 restrict: 'E',
8 scope: {
9 serviceChain: '='
10 },
11 bindToController: true,
12 controllerAs: 'vm',
13 template: '',
14 controller: function($element, $window, $scope, d3, serviceTopologyConfig, ServiceRelation, Slice, Instances, Subscribers, TreeLayout){
15
16 const el = $element[0];
17
18 this.instances = [];
19 this.slices = [];
20
21 const width = el.clientWidth - (serviceTopologyConfig.widthMargin * 2);
22 const height = el.clientHeight - (serviceTopologyConfig.heightMargin * 2);
23
24 const treeLayout = d3.layout.tree()
25 .size([height, width]);
26
27 const svg = d3.select($element[0])
28 .append('svg')
29 .style('width', `${el.clientWidth}px`)
30 .style('height', `${el.clientHeight}px`)
31
32 const treeContainer = svg.append('g')
33 .attr('transform', `translate(${serviceTopologyConfig.widthMargin * 4},${serviceTopologyConfig.heightMargin})`);
34
35 var root;
36
37 const draw = (tree) => {
38 root = tree;
39 root.x0 = height / 2;
40 root.y0 = width / 2;
41
42 TreeLayout.updateTree(treeContainer, treeLayout, root);
43 };
44
45 TreeLayout.drawLegend(svg);
46
47 this.getInstances = (slice) => {
48 Instances.query({slice: slice.id}).$promise
49 .then((instances) => {
50 this.selectedSlice = slice;
51 this.instances = instances;
52 })
53 };
54
55 $scope.$watch(() => this.serviceChain, (chain) => {
56 if(chain){
57 draw(chain);
58 }
59 });
60 }
61 }
62 });
63
64}());