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