server/src/main/webapp/static/js/random-data.js
author ymh <ymh.work@gmail.com>
Tue, 25 Dec 2012 21:29:11 +0100
changeset 47 267d67791e05
permissions -rw-r--r--
first stabilization of editing a renkan. No collaborative capacities yet.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
Rkns.randomData = function(_renkan, _opts) {
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
    _opts = _opts || {};
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
    _opts.user_count = _opts.user_count || 5;
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    _opts.node_count = _opts.node_count || 20;
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    _opts.edge_count = _opts.edge_count || 2 * _opts.node_count;
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
    _opts.user_colors = _opts.user_colors || ["#ff0000", "#008000", "#0000ff", "#808000", "#808080", "#c000c0", "#00c0c0"];
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    var _proj = _renkan.project
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    for (var i = 0; i < _opts.user_count; i++) {
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
        _proj.addUser({
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
            id: "user-"+i,
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
            title: "User #"+(1+i),
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
            color: _opts.user_colors[i]
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        });
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    }
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    for (var i = 0; i < _opts.node_count; i++) {
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
        _proj.addNode({
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
            id: "node-"+i,
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
            title: "Node #"+(1+i),
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
            created_by: "user-" + Math.floor(_opts.user_count*Math.random()),
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
            position: {
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
                x: 300 * Math.cos(2 * Math.PI * i / _opts.node_count),
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
                y: 300 * Math.sin(2 * Math.PI * i / _opts.node_count)
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
            }
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        });
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    }
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    for (var i = 0; i < _opts.node_count; i++) {
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        var _from, _to;
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        _from = _to = Math.floor(_opts.node_count*Math.random());
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
        while(_from === _to) {
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
            _to = Math.floor(_opts.node_count*Math.random());
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
        }
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
        _proj.addEdge({
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
            id: "edge-"+i,
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
            title: "Edge #"+(1+i),
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
            created_by: "user-" + Math.floor(_opts.user_count*Math.random()),
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
            from: "node-" + _from,
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
            to: "node-" + _to
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        });
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    }
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    _renkan.current_user = "user-0";
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    _renkan.renderer.autoScale();
267d67791e05 first stabilization of editing a renkan.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
}