You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.6 KiB

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