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.

75 lines
2.4 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. var nodes, edges, container;
  14. var options = {
  15. layout: {
  16. improvedLayout: false
  17. },
  18. interaction: {
  19. hover: true
  20. },
  21. physics: {
  22. stabilization: false,
  23. //enabled: false
  24. }
  25. };
  26. $scope.showMap = function() {
  27. var nodes = $scope.nodes;
  28. var edges = $scope.edges;
  29. var container = document.getElementById('mynetwork');
  30. var data = {
  31. nodes: nodes,
  32. edges: edges
  33. };
  34. var network = new vis.Network(container, data, options);
  35. network.on("click", function(params) {
  36. params.event = "[original event]";
  37. //$scope.selectedNode = JSON.stringify(params, null, 4);
  38. $scope.selectedNode = params;
  39. console.log($scope.selectedNode);
  40. console.log($scope.selectedNode.nodes);
  41. var options = {
  42. // position: {x:positionx,y:positiony}, // this is not relevant when focusing on nodes
  43. scale: 1,
  44. offset: {
  45. x: 0,
  46. y: 0
  47. },
  48. animation: {
  49. duration: 500,
  50. easingFunction: "easeInOutQuad"
  51. }
  52. };
  53. network.focus($scope.selectedNode.nodes[0], options);
  54. });
  55. };
  56. $http.get(urlapi + 'admin/network')
  57. .then(function(data, status, headers, config) {
  58. console.log('data success');
  59. console.log(data);
  60. $scope.nodes = data.data.nodes;
  61. $scope.edges = data.data.edges;
  62. $scope.showMap();
  63. }, function(data, status, headers, config) {
  64. console.log('data error');
  65. });
  66. });