client/js/random-data.js
author veltr
Mon, 30 Jul 2012 18:44:59 +0200
changeset 6 a7b54105f74e
parent 4 f5297dde9053
child 20 bd58970ffd16
permissions -rw-r--r--
Now with a gradient

Rkns.Serializers.RandomData = Rkns.Utils.inherit(Rkns.Serializers._Base);

Rkns.Serializers.RandomData.prototype._init = function() {
    this._USER_COUNT = 5;
    this._NODE_COUNT = 20;
    this._EDGE_COUNT = 40;
    this.user_colors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"];
    this.load();
}

Rkns.Serializers.RandomData.prototype.load = function() {
    var _p = this._project;
    _p.title = "Random Generated Data";
    for (var i = 0; i < this._USER_COUNT; i++) {
        _p.users.push(new Rkns.Model.User(_p, {
            id: "user-"+i,
            title: "User #"+(1+i),
            color: this.user_colors[i]
        }));
    }
    for (var i = 0; i < this._NODE_COUNT; i++) {
        _p.nodes.push(new Rkns.Model.Node(_p, {
            id: "node-"+i,
            title: "Node #"+(1+i),
            created_by: "user-" + Math.floor(this._USER_COUNT*Math.random()),
            position: {
//                x: 200 * Math.random(),
//                y: 150 * Math.random()
                x: 100 * Math.cos(2 * Math.PI * i / this._NODE_COUNT),
                y: 100 * Math.sin(2 * Math.PI * i / this._NODE_COUNT)
            }
        }));
    }
    for (var i = 0; i < this._EDGE_COUNT; i++) {
        var _from, _to;
        _from = _to = Math.floor(this._NODE_COUNT*Math.random());
        while(_from === _to) {
            _to = Math.floor(this._NODE_COUNT*Math.random());
        }
        _p.edges.push(new Rkns.Model.Edge(_p, {
            id: "edge-"+i,
            title: "Edge #"+(1+i),
            created_by: "user-" + Math.floor(this._USER_COUNT*Math.random()),
            from: "node-" + _from,
            to: "node-" + _to
        }));
    }
    this.handleCallbacks();
}