1 Rkns.randomData = function(_renkan, _opts) { |
|
2 _opts = _opts || {}; |
|
3 _opts.user_count = _opts.user_count || 5; |
|
4 _opts.node_count = _opts.node_count || 20; |
|
5 _opts.edge_count = _opts.edge_count || 2 * _opts.node_count; |
|
6 _opts.user_colors = _opts.user_colors || ["#ff0000", "#008000", "#0000ff", "#808000", "#808080", "#c000c0", "#00c0c0"]; |
|
7 var _proj = _renkan.project |
|
8 for (var i = 0; i < _opts.user_count; i++) { |
|
9 _proj.addUser({ |
|
10 id: "user-"+i, |
|
11 title: "User #"+(1+i), |
|
12 color: _opts.user_colors[i] |
|
13 }); |
|
14 } |
|
15 for (var i = 0; i < _opts.node_count; i++) { |
|
16 _proj.addNode({ |
|
17 id: "node-"+i, |
|
18 title: "Node #"+(1+i), |
|
19 created_by: "user-" + Math.floor(_opts.user_count*Math.random()), |
|
20 position: { |
|
21 x: 300 * Math.cos(2 * Math.PI * i / _opts.node_count), |
|
22 y: 300 * Math.sin(2 * Math.PI * i / _opts.node_count) |
|
23 } |
|
24 }); |
|
25 } |
|
26 for (var i = 0; i < _opts.node_count; i++) { |
|
27 var _from, _to; |
|
28 _from = _to = Math.floor(_opts.node_count*Math.random()); |
|
29 while(_from === _to) { |
|
30 _to = Math.floor(_opts.node_count*Math.random()); |
|
31 } |
|
32 _proj.addEdge({ |
|
33 id: "edge-"+i, |
|
34 title: "Edge #"+(1+i), |
|
35 created_by: "user-" + Math.floor(_opts.user_count*Math.random()), |
|
36 from: "node-" + _from, |
|
37 to: "node-" + _to |
|
38 }); |
|
39 } |
|
40 _renkan.current_user = "user-0"; |
|
41 _renkan.renderer.autoScale(); |
|
42 } |
|