weighted_graph.js 1.4 KB
Newer Older
J
Jason Park 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
WeightedGraphTracer.graphMode = "weighted";

function WeightedGraphTracer(module) {
    if (GraphTracer.call(this, module || WeightedGraphTracer)) {
        initWeightedGraph();
        return true;
    }
    return false;
}

WeightedGraphTracer.prototype = Object.create(GraphTracer.prototype);
WeightedGraphTracer.prototype.constructor = WeightedGraphTracer;

// Override
WeightedGraphTracer.prototype.setData = function (G) {
    if (Tracer.prototype.setData.call(this, arguments)) return;

    graph.clear();
    var nodes = [];
    var edges = [];
    var unitAngle = 2 * Math.PI / G.length;
    var currentAngle = 0;
    for (var i = 0; i < G.length; i++) {
        currentAngle += unitAngle;
        nodes.push({
            id: n(i),
            label: '' + i,
            x: .5 + Math.sin(currentAngle) / 2,
            y: .5 + Math.cos(currentAngle) / 2,
            size: 1,
            color: graphColor.default
        });
        for (var j = 0; j < G[i].length; j++) {
            edges.push({
                id: e(i, G[i][j]),
                source: n(i),
                target: n(G[i][j]),
                color: graphColor.default,
                size: 1
            })
        }
    }

    graph.read({
        nodes: nodes,
        edges: edges
    });
    s.camera.goTo({
        x: 0,
        y: 0,
        angle: 0,
        ratio: 1
    });
    this.refresh();
};

var initWeightedGraph = function () {
};