server/src/main/webapp/js/random-data.js
changeset 9 2ab67fa1e78d
equal deleted inserted replaced
8:8e67c9f6da51 9:2ab67fa1e78d
       
     1 Rkns.Serializers.RandomData = Rkns.Utils.inherit(Rkns.Serializers._Base);
       
     2 
       
     3 Rkns.Serializers.RandomData.prototype._init = function() {
       
     4     this._USER_COUNT = 5;
       
     5     this._NODE_COUNT = 20;
       
     6     this._EDGE_COUNT = 40;
       
     7     this.user_colors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"];
       
     8     this.load();
       
     9 }
       
    10 
       
    11 Rkns.Serializers.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.Model.User(_p, {
       
    16             id: "user-"+i,
       
    17             title: "User #"+(1+i),
       
    18             color: this.user_colors[i]
       
    19         }));
       
    20     }
       
    21     for (var i = 0; i < this._NODE_COUNT; i++) {
       
    22         _p.nodes.push(new Rkns.Model.Node(_p, {
       
    23             id: "node-"+i,
       
    24             title: "Node #"+(1+i),
       
    25             created_by: "user-" + Math.floor(this._USER_COUNT*Math.random()),
       
    26             position: {
       
    27 //                x: 200 * Math.random(),
       
    28 //                y: 150 * Math.random()
       
    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             }
       
    32         }));
       
    33     }
       
    34     for (var i = 0; i < this._EDGE_COUNT; i++) {
       
    35         var _from, _to;
       
    36         _from = _to = Math.floor(this._NODE_COUNT*Math.random());
       
    37         while(_from === _to) {
       
    38             _to = Math.floor(this._NODE_COUNT*Math.random());
       
    39         }
       
    40         _p.edges.push(new Rkns.Model.Edge(_p, {
       
    41             id: "edge-"+i,
       
    42             title: "Edge #"+(1+i),
       
    43             created_by: "user-" + Math.floor(this._USER_COUNT*Math.random()),
       
    44             from: "node-" + _from,
       
    45             to: "node-" + _to
       
    46         }));
       
    47     }
       
    48     this.handleCallbacks();
       
    49 }