goBlockchainDataAnalysis/web/views/network/network.js
web/views/network/network.jsRaw
1'use strict';
2
3angular.module('app.network', ['ngRoute'])
4
5 .config(['$routeProvider', function($routeProvider) {
6 $routeProvider.when('/network', {
7 templateUrl: 'views/network/network.html',
8 controller: 'NetworkCtrl'
9 });
10 }])
11
12 .controller('NetworkCtrl', function($scope, $http, $routeParams) {
13 $scope.data = [];
14 $scope.nodes = [];
15 $scope.edges = [];
16 $scope.selectedNode = {};
17 var nodes, edges, container, network;
18 var options = {
19 layout: {
20 improvedLayout: false
21 },
22 interaction: {
23 hover: true
24 },
25 physics: {
26 stabilization: false,
27 //enabled: false
28 }
29 };
30
31
32 $scope.showMap = function() {
33 var nodes = $scope.nodes;
34 var edges = $scope.edges;
35
36 var container = document.getElementById('mynetwork');
37 var data = {
38 nodes: nodes,
39 edges: edges
40 };
41 network = new vis.Network(container, data, options);
42 network.on("click", function(params) {
43 params.event = "[original event]";
44 //$scope.selectedNode = JSON.stringify(params, null, 4);
45 $scope.selectedNode = params;
46 console.log($scope.selectedNode);
47 console.log($scope.selectedNode.nodes);
48 var options = {
49 // position: {x:positionx,y:positiony}, // this is not relevant when focusing on nodes
50 scale: 1,
51 offset: {
52 x: 0,
53 y: 0
54 },
55 animation: {
56 duration: 500,
57 easingFunction: "easeInOutQuad"
58 }
59 };
60 network.focus($scope.selectedNode.nodes[0], options);
61 //console.log('click event, getNodeAt returns: ' + this.getNodeAt(params.pointer.DOM));
62 });
63 };
64
65 $http.get(urlapi + 'map')
66 .then(function(data, status, headers, config) {
67 console.log('data success');
68 console.log(data);
69
70 $scope.nodes = data.data.nodes;
71 $scope.edges = data.data.edges;
72 $scope.showMap();
73 }, function(data, status, headers, config) {
74 console.log('data error');
75 });
76
77
78 $scope.focusNode = function(node) {
79 var options = {
80 // position: {x:positionx,y:positiony}, // this is not relevant when focusing on nodes
81 scale: 1,
82 offset: {
83 x: 0,
84 y: 0
85 },
86 animation: {
87 duration: 500,
88 easingFunction: "easeInOutQuad"
89 }
90 };
91 network.focus(node.id, options);
92 };
93 });