|
@@ -33,11 +33,16 @@ angular.module('Qfe7')
|
|
|
return db.destroy();
|
|
|
}
|
|
|
})
|
|
|
- .controller("RootController", function ($scope, $state, VisDataSet, AgentService, AgentBuilder, LinkBuilder) {
|
|
|
+ .controller("RootController", function ($scope, $state, VisDataSet, AgentService, Agent, Link) {
|
|
|
$scope.err = undefined;
|
|
|
function errorFn(err) {
|
|
|
$scope.err = err;
|
|
|
}
|
|
|
+
|
|
|
+ $scope.settings = {
|
|
|
+ self: true,
|
|
|
+ };
|
|
|
+
|
|
|
$scope.options = {
|
|
|
interaction: {
|
|
|
hover: true
|
|
@@ -49,19 +54,17 @@ angular.module('Qfe7')
|
|
|
},
|
|
|
"physics": {
|
|
|
"barnesHut": {
|
|
|
+ "gravitationalConstant": -10000,
|
|
|
"centralGravity": 0.1,
|
|
|
- "springLength": 100,
|
|
|
- "springConstant": 0.03,
|
|
|
- "damping": 0.05,
|
|
|
- "avoidOverlap": 0.1
|
|
|
+ "springLength": 400,
|
|
|
+ "springConstant": 0.05,
|
|
|
+ "damping": 0.4,
|
|
|
+ "avoidOverlap": 0
|
|
|
},
|
|
|
- "maxVelocity": 10,
|
|
|
- "minVelocity": 0.5,
|
|
|
- "timestep": 0.25
|
|
|
+ "minVelocity": 0.75
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-
|
|
|
$scope.data = {
|
|
|
nodes: new VisDataSet(),
|
|
|
edges: new VisDataSet(),
|
|
@@ -77,7 +80,6 @@ angular.module('Qfe7')
|
|
|
}
|
|
|
|
|
|
$scope.events = {
|
|
|
-
|
|
|
selectNode: eventHandler(function (x) {
|
|
|
let node = $scope.data.nodes.get(x.nodes[0]);
|
|
|
$scope.data.description = JSON.stringify(node.agent);
|
|
@@ -90,24 +92,46 @@ angular.module('Qfe7')
|
|
|
const shapes = {
|
|
|
'male': 'triangleDown',
|
|
|
'female': 'triangle',
|
|
|
- 'organization': 'database'
|
|
|
+ 'organization': 'dot'
|
|
|
};
|
|
|
|
|
|
const sizes = {
|
|
|
'child': {size: 15},
|
|
|
'mature': {size: 30},
|
|
|
- 'monster': {font: {size: 60}}
|
|
|
+ 'monster': {size: 100}
|
|
|
};
|
|
|
|
|
|
const links = {
|
|
|
'life': {
|
|
|
color: 'red',
|
|
|
arrows: 'from'
|
|
|
+ },
|
|
|
+ 'food': {
|
|
|
+ color: 'green',
|
|
|
+ arrows: 'to'
|
|
|
+ },
|
|
|
+ 'eat': {
|
|
|
+ color: 'green',
|
|
|
+ arrows: 'to'
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- function doNodes() {
|
|
|
+ function getValueOf(link) {
|
|
|
+ switch (link.type) {
|
|
|
+ case 'life':
|
|
|
+ return (link.value / 2500);
|
|
|
+ case 'food':
|
|
|
+ return link.value;
|
|
|
+ case 'eat':
|
|
|
+ return link.value;
|
|
|
+ default:
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let doNodes = $scope.doNodes = function (x) {
|
|
|
$scope.data.nodes.clear();
|
|
|
+ $scope.data.edges.clear();
|
|
|
AgentService.load().then(al => {
|
|
|
Array.from(al).forEach(a => {
|
|
|
let node = {
|
|
@@ -123,41 +147,59 @@ angular.module('Qfe7')
|
|
|
$scope.data.nodes.add(node);
|
|
|
});
|
|
|
Array.from(al).forEach(a => {
|
|
|
- Array.from(a.links).forEach(l => {
|
|
|
+ Array.from(a.links)
|
|
|
+ .filter(l => {
|
|
|
+ return $scope.settings.self || !(l.type == 'life' || l.type == 'eat');
|
|
|
+ }).forEach(l => {
|
|
|
let link = {
|
|
|
id: l._id,
|
|
|
- from: l.from,
|
|
|
- to: l.to,
|
|
|
+ from: l.from.id,
|
|
|
+ to: l.to.id,
|
|
|
+ value: getValueOf(l)
|
|
|
};
|
|
|
_.extend(link, links[l.type]);
|
|
|
$scope.data.edges.add(link)
|
|
|
})
|
|
|
- })
|
|
|
+ });
|
|
|
}, errorFn)
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
doNodes();
|
|
|
|
|
|
$scope.initAgents = function () {
|
|
|
- let m = AgentBuilder.get().male().build();
|
|
|
- LinkBuilder.for(m).life().build();
|
|
|
+ let m = Agent.is().male().build();
|
|
|
+ Link.for(m).life().build();
|
|
|
+ Link.for(m).eat().build();
|
|
|
+
|
|
|
+ let f = Agent.is().female().build();
|
|
|
+ Link.for(f).life().build();
|
|
|
+ Link.for(f).eat().build();
|
|
|
|
|
|
- let f = AgentBuilder.get().female().build();
|
|
|
- LinkBuilder.for(f).life().build();
|
|
|
+ let cm = Agent.is().male().child().build();
|
|
|
+ Link.for(cm).life().build();
|
|
|
+ Link.for(cm).eat().build();
|
|
|
|
|
|
- let cm = AgentBuilder.get().male().child().build();
|
|
|
- LinkBuilder.for(cm).life().build();
|
|
|
+ let cf = Agent.is().female().child().build();
|
|
|
+ Link.for(cf).life().build();
|
|
|
+ Link.for(cf).eat().build();
|
|
|
|
|
|
- let cf = AgentBuilder.get().female().child().build();
|
|
|
- LinkBuilder.for(cf).life().build();
|
|
|
+ Link.for(m).food(0.5).to(cm).build();
|
|
|
+ Link.for(m).food(0.5).to(cf).build();
|
|
|
+ Link.for(f).food(0.5).to(cm).build();
|
|
|
+ Link.for(f).food(0.5).to(cf).build();
|
|
|
|
|
|
- let o = AgentBuilder.get().organization().build();
|
|
|
+ let o = Agent.is().organization().build();
|
|
|
|
|
|
- AgentService.create([m, f, cm, cf, o]).then(doNodes, errorFn);
|
|
|
+ let l = Agent.is().organization().has('food').build();
|
|
|
+ Link.for(l).food(2).to(m).build();
|
|
|
+ Link.for(l).food(2).to(f).build();
|
|
|
+
|
|
|
+ AgentService.create([m, f, cm, cf, o, l]).then(doNodes, errorFn);
|
|
|
};
|
|
|
|
|
|
$scope.resetAgents = function () {
|
|
|
AgentService.reset();
|
|
|
window.location.reload();
|
|
|
};
|
|
|
+
|
|
|
});
|