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.

56 lines
2.0 KiB

  1. 'use strict';
  2. angular.module('app.sankey', ['ngRoute', 'ngSankey'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/sankey', {
  5. templateUrl: 'views/sankey/sankey.html',
  6. controller: 'SankeyCtrl'
  7. });
  8. }])
  9. .controller('SankeyCtrl', function($scope, $http, $routeParams) {
  10. $scope.selectedAddress = "";
  11. $scope.options = {
  12. chart: '#sankeyChart',
  13. width: 800,
  14. height: 500,
  15. margin: {top: 1, right: 1, bottom: 6, left: 1},
  16. node: {width: 15, padding :10, showValue: false},
  17. value: {format: ',.0f', unit : ''},
  18. dynamicLinkColor: true,
  19. trafficInLinks: true
  20. };
  21. $scope.data={
  22. nodes: [],
  23. links: []
  24. };
  25. $http.get(urlapi + 'alladdresses')
  26. .then(function(data, status, headers, config) {
  27. console.log('data success');
  28. console.log(data);
  29. $scope.addresses = data.data;
  30. }, function(data, status, headers, config) {
  31. console.log('data error');
  32. });
  33. $scope.getAddressSankey = function(address) {
  34. console.log(address);
  35. $scope.selectedAddress = address.id;
  36. $scope.data.nodes = [];
  37. $scope.data.links = [];
  38. $http.get(urlapi + 'address/sankey/' + address.id)
  39. .then(function(data, status, headers, config) {
  40. console.log('data success');
  41. console.log(data);
  42. $scope.data.nodes = data.data.nodes;
  43. $scope.data.links = data.data.links;
  44. console.log($scope.data);
  45. d3.selectAll("svg > *").remove();
  46. let chart = new d3.sankeyChart(data.data, $scope.options);
  47. //$scope.data = data.data;
  48. }, function(data, status, headers, config) {
  49. console.log('data error');
  50. });
  51. };
  52. });