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.

93 lines
3.0 KiB

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