-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.js
112 lines (93 loc) · 2.78 KB
/
core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// public/core.js
var ghmapApp = angular.module('ghmapApp', ['d3']);
ghmapApp.controller('mainController', function ($scope, $http) {
$scope.gh_user = '';
$scope.data = '';
$scope.setUser = function() {
console.log('Attempting setUser');
$http.post('/api/githubmap/' + $scope.gh_user)
.success(function(data) {
$scope.data = data
})
.error(function(data) {
console.log('Error setUser: ' +
data);
});
}
});
ghmapApp.directive('d3Bars', ['$window', '$timeout', 'd3Service',
function($window, $timeout, d3Service) {
return {
restrict: 'A',
scope: {
data: '=',
label: '@',
onClick: '&'
},
link: function(scope, ele, attrs) {
d3Service.d3().then(function(d3) {
var renderTimeout;
var diameter = 1024;
var tree = d3.layout.tree()
.size([360, diameter / 2 - 120])
.separation(function(a, b) {
return (a.parent == b.parent ? 1 : 2) / a.depth; });
var diagonal = d3.svg.diagonal.radial()
.projection(function(d) {
return [d.y, d.x / 180 * Math.PI]; });
var svg = d3.select(ele[0])
.append("svg")
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(" +
diameter / 2 + "," + diameter / 2 + ")");
$window.onresize = function() {
scope.$apply();
};
scope.$watch(function() {
return angular.element($window)[0].innerWidth;
}, function() {
scope.render(scope.data);
});
scope.$watch('data', function(newData) {
scope.render(newData);
}, true);
scope.render = function(data) {
svg.selectAll('*').remove();
if (!data) return;
if (renderTimeout) clearTimeout(renderTimeout);
renderTimeout = $timeout(function() {
var nodes = tree.nodes(data),
links = tree.links(nodes);
var link = svg.selectAll(".link")
.data(links)
.enter().append("path")
.attr("class", "link")
.attr("d", diagonal);
var node = svg.selectAll(".node")
.data(nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) {
return "rotate(" + (d.x - 90) +
")translate(" + d.y + ")"; })
node.append("circle")
.attr("r", 4.5);
node.append("text")
.attr("dy", ".31em")
.attr("text-anchor", function(d) {
return d.x < 180 ? "start" : "end";
})
.attr("transform", function(d) {
return d.x < 180 ?
"translate(8)" :
"rotate(180)translate(-8)"; })
.text(function(d) { return d.name; });
d3.select(self.frameElement).style("height",
diameter - 150 + "px");
}, 200);
};
});
}}
}]);