1 Rkns.RemoteModels.RandomData = Rkns.Utils.inherit(Rkns.RemoteModels._Base); |
1 Rkns.randomData = function(_renkan, _opts) { |
2 |
2 _opts = _opts || {}; |
3 Rkns.RemoteModels.RandomData.prototype._init = function() { |
3 _opts.user_count = _opts.user_count || 5; |
4 this._USER_COUNT = 5; |
4 _opts.node_count = _opts.node_count || 20; |
5 this._NODE_COUNT = 50; |
5 _opts.edge_count = _opts.edge_count || 2 * _opts.node_count; |
6 this._EDGE_COUNT = 100; |
6 _opts.user_colors = _opts.user_colors || ["#ff0000", "#008000", "#0000ff", "#808000", "#808080", "#c000c0", "#00c0c0"]; |
7 this.user_colors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"]; |
7 var _proj = _renkan.project |
8 this.load(); |
8 for (var i = 0; i < _opts.user_count; i++) { |
9 } |
9 _proj.addUser({ |
10 |
|
11 Rkns.RemoteModels.RandomData.prototype.load = function() { |
|
12 var _p = this._project; |
|
13 _p.title = "Random Generated Data"; |
|
14 for (var i = 0; i < this._USER_COUNT; i++) { |
|
15 _p.users.push(new Rkns.ViewModel.User(_p, { |
|
16 id: "user-"+i, |
10 id: "user-"+i, |
17 title: "User #"+(1+i), |
11 title: "User #"+(1+i), |
18 color: this.user_colors[i] |
12 color: _opts.user_colors[i] |
19 })); |
13 }); |
20 } |
14 } |
21 for (var i = 0; i < this._NODE_COUNT; i++) { |
15 for (var i = 0; i < _opts.node_count; i++) { |
22 _p.nodes.push(new Rkns.ViewModel.Node(_p, { |
16 _proj.addNode({ |
23 id: "node-"+i, |
17 id: "node-"+i, |
24 title: "Node #"+(1+i), |
18 title: "Node #"+(1+i), |
25 created_by: "user-" + Math.floor(this._USER_COUNT*Math.random()), |
19 created_by: "user-" + Math.floor(_opts.user_count*Math.random()), |
26 position: { |
20 position: { |
27 x: 200 * Math.random(), |
21 x: 300 * Math.cos(2 * Math.PI * i / _opts.node_count), |
28 y: 150 * Math.random() |
22 y: 300 * Math.sin(2 * Math.PI * i / _opts.node_count) |
29 // x: 100 * Math.cos(2 * Math.PI * i / this._NODE_COUNT), |
|
30 // y: 100 * Math.sin(2 * Math.PI * i / this._NODE_COUNT) |
|
31 } |
23 } |
32 })); |
24 }); |
33 } |
25 } |
34 for (var i = 0; i < this._EDGE_COUNT; i++) { |
26 for (var i = 0; i < _opts.node_count; i++) { |
35 var _from, _to; |
27 var _from, _to; |
36 _from = _to = Math.floor(this._NODE_COUNT*Math.random()); |
28 _from = _to = Math.floor(_opts.node_count*Math.random()); |
37 while(_from === _to) { |
29 while(_from === _to) { |
38 _to = Math.floor(this._NODE_COUNT*Math.random()); |
30 _to = Math.floor(_opts.node_count*Math.random()); |
39 } |
31 } |
40 _p.edges.push(new Rkns.ViewModel.Edge(_p, { |
32 _proj.addEdge({ |
41 id: "edge-"+i, |
33 id: "edge-"+i, |
42 title: "Edge #"+(1+i), |
34 title: "Edge #"+(1+i), |
43 created_by: "user-" + Math.floor(this._USER_COUNT*Math.random()), |
35 created_by: "user-" + Math.floor(_opts.user_count*Math.random()), |
44 from: "node-" + _from, |
36 from: "node-" + _from, |
45 to: "node-" + _to |
37 to: "node-" + _to |
46 })); |
38 }); |
47 } |
39 } |
48 this.handleCallbacks(); |
40 _renkan.current_user = "user-0"; |
49 } |
41 } |