-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
192 lines (172 loc) · 6.54 KB
/
app.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// create module for custom directives
var d3DemoApp = angular.module('d3DemoApp', []);
// controller business logic
d3DemoApp.controller('AppCtrl', function AppCtrl ($scope, $http) {
// initialize the model
$scope.user = 'GDPKYPW5A2PYCC2FPBCO7R2G5FHXMQBG6TX6IQYYYMXKCHXF2YNM3BOX';
$scope.accounts = [];
$scope.dataMatching = [];
$scope.msg = "[";
var hey = [];
// $scope.udpateJson = function () {
// helper for reformatting the Github API response into a form we can pass to D3
var reformatAccountData = function (data) {
// build up the data to be passed to our d3 visualization
var formattedData = [];
var formattedToken = [];
var records = data._embedded.records;
var i;
for (i = 0; i < records.length; i++) {
formattedData.push(records[i].id);
formattedToken.push(records[i].paging_token);
}
return [formattedData, formattedToken];
};
$scope.appendAccountEntry = function(key, entry){
$scope.dataMatching.push({
'name': key,
'size': 1,
'inputs': [entry]
});
hey.push({
'name': key,
'size': 1,
'inputs': [entry]
});
// console.log(hey);
$scope.msg = $scope.msg + JSON.stringify({
'name': key,
'size': 1,
'inputs': [entry]
}) + ',';
}
$scope.getCommitData = function () {
$http({
method: 'GET',
url:'https://horizon-testnet.stellar.org/accounts?limit=200&order=desc'
}).
success(function (data) {
// attach this data to the scope
$scope.data = reformatAccountData(data)[0];
$scope.accounts = reformatAccountData(data)[1];
var m;
for (m=1; m<$scope.accounts.length; m+=1) {
$http({
method: 'GET',
url:'https://horizon-testnet.stellar.org/accounts/' + $scope.data[m] + '/operations'
}).
success(function (data) {
// attach this data to the scope
var funder = data._embedded.records[0].funder;
var key = data._embedded.records[0].account;
$scope.appendAccountEntry(key, funder);
}).
error(function (data, status) {
if (status === 404) {
$scope.error = 'That account does not exist';
} else {
$scope.error = 'Error: ' + status;
}
});
}
// clear the error messages
$scope.error = '';
}).
error(function (data, status) {
if (status === 404) {
$scope.error = 'The account does not exist.';
} else {
$scope.error = 'Error: ' + status;
}
});
var stateChange = function(newState) {
setTimeout(function () {
$scope.msg = $scope.msg + "]";
console.log($scope.msg);
var diameter = 960,
radius = diameter / 2,
innerRadius = radius - 120;
var cluster = d3.layout.cluster()
.size([360, innerRadius])
.sort(null)
.value(function(d) { return d.size; });
var bundle = d3.layout.bundle();
var line = d3.svg.line.radial()
.interpolate("bundle")
.tension(.85)
.radius(function(d) { return d.y; })
.angle(function(d) { return d.x / 180 * Math.PI; });
var svg = d3.select("body").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(" + radius + "," + radius + ")");
d3.json("accountcreation.json", function(error, classes) {
if (error) throw error;
console.log(classes);
var nodes = cluster.nodes(packageHierarchy(classes)),
links = packageImports(nodes);
svg.selectAll(".link")
.data(bundle(links))
.enter().append("path")
.attr("class", "link")
.attr("d", line);
svg.selectAll(".node")
.data(nodes.filter(function(n) { return !n.children; }))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
.append("text")
.attr("dx", function(d) { return d.x < 180 ? 8 : -8; })
.attr("dy", ".31em")
.attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
.attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; })
.text(function(d) { return d.key; });
});
d3.select(self.frameElement).style("height", diameter + "px");
// Lazily construct the package hierarchy from class names.
function packageHierarchy() {
var map = {};
function find(name, data) {
var node = map[name], i;
if (!node) {
node = map[name] = data || {name: name, children: []};
if (name.length) {
node.parent = find(name.substring(0, i = name.lastIndexOf(".")));
node.parent.children.push(node);
node.key = name.substring(i + 1);
}
}
return node;
}
angular.forEach(function(d) {
find(d.name, d);
});
return map[""];
}
// Return a list of imports for the given array of nodes.
function packageImports(nodes) {
var map = {},
imports = [];
// Compute a map from name to node.
nodes.forEach(function(d) {
map[d.name] = d;
});
// For each import, construct a link from the source to target node.
nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
imports.push({source: map[d.name], target: map[i]});
});
});
return imports;
}
}, 5000);
};
stateChange();
};
// }();
// get the commit data immediately
$scope.getCommitData();
// console.log($scope.msg);
// $scope.$watch(function(){return $scope.msg;}, function(newValue, oldValue){console.log(newValue)});
});