提交 3dc7a61a 编写于 作者: J Jason Park

refresh module only if data changed

上级 f2ddec83
var s = null, graph = null, graphMode = "default";
var s = null, graph = null, graphMode = null;
function GraphTracer() {
Tracer.call(this, GraphTracer);
GraphTracer.graphMode = "default";
if (s && graph && graphMode == "default") return;
initSigma();
function GraphTracer(module) {
Tracer.call(this, module || GraphTracer);
return initGraph(this.module);
}
GraphTracer.prototype = Object.create(Tracer.prototype);
......@@ -26,9 +26,8 @@ GraphTracer.prototype.reset = function () {
// Override
GraphTracer.prototype.setData = function (G) {
Tracer.prototype.setData.call(this, G);
if (Tracer.prototype.setData.call(this, arguments)) return;
this.G = G;
graph.clear();
var nodes = [];
var edges = [];
......@@ -73,11 +72,11 @@ Tracer.prototype.clear = function () {
};
Tracer.prototype.visit = function (targetNode, sourceNode) {
this.pushStep({type: 'visit', node: targetNode, parent: sourceNode}, true);
this.pushStep({type: 'visit', node: targetNode, Tracer: sourceNode}, true);
};
Tracer.prototype.leave = function (targetNode, sourceNode) {
this.pushStep({type: 'leave', node: targetNode, parent: sourceNode}, true);
this.pushStep({type: 'leave', node: targetNode, Tracer: sourceNode}, true);
};
GraphTracer.prototype.processStep = function (step, options) {
......@@ -92,15 +91,15 @@ GraphTracer.prototype.processStep = function (step, options) {
var node = graph.nodes(n(step.node));
var color = visit ? graphColor.visited : graphColor.left;
node.color = color;
if (step.parent !== undefined) {
var edgeId = e(step.parent, step.node);
if (step.Tracer !== undefined) {
var edgeId = e(step.Tracer, step.node);
var edge = graph.edges(edgeId);
edge.color = color;
graph.dropEdge(edgeId).addEdge(edge);
}
var parent = step.parent;
if (parent === undefined) parent = '';
printTrace(visit ? parent + ' -> ' + step.node : parent + ' <- ' + step.node);
var Tracer = step.Tracer;
if (Tracer === undefined) Tracer = '';
printTrace(visit ? Tracer + ' -> ' + step.node : Tracer + ' <- ' + step.node);
break;
}
};
......@@ -187,7 +186,11 @@ var e = function (v1, v2) {
return 'e' + v1 + '_' + v2;
};
var initSigma = function () {
var initGraph = function (module) {
if (s && graph && graphMode == module.graphMode) return false;
graphMode = module.graphMode;
$('.visualize_container').empty();
s = new sigma({
renderer: {
container: $('.visualize_container')[0],
......@@ -256,4 +259,6 @@ var initSigma = function () {
});
};
sigma.plugins.dragNodes(s, s.renderers[0]);
return true;
};
\ No newline at end of file
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 () {
};
\ No newline at end of file
var timer = null;
var lastModule = null, lastData = null;
var Tracer = function (module) {
this.module = module;
......@@ -6,6 +7,7 @@ var Tracer = function (module) {
this.pause = false;
this.traceOptions = null;
this.traceIndex = -1;
this.lastData = null;
};
Tracer.prototype.resize = function () {
......@@ -17,7 +19,12 @@ Tracer.prototype.reset = function () {
$('#tab_trace .wrapper').empty();
};
Tracer.prototype.setData = function () {
Tracer.prototype.setData = function (arguments) {
var data = JSON.stringify(arguments);
if (lastModule == this.module && lastData == data) return true;
lastModule = this.module;
lastData = data;
return false;
};
Tracer.prototype.pushStep = function (step, delay) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册