提交 21b6d2a4 编写于 作者: J Jason Park

prepare for other modules

上级 4860059b
var s = null, graph = null, graphMode = null, sigmaCanvas = null; var s = null, graph = null, sigmaCanvas = null;
function GraphTracer(module) { function GraphTracer(module) {
Tracer.call(this, module || GraphTracer); if (Tracer.call(this, module || WeightedGraphTracer)) {
return initGraph(this.module); initGraph();
return true;
}
return false;
} }
GraphTracer.graphMode = "default";
GraphTracer.prototype = Object.create(Tracer.prototype); GraphTracer.prototype = Object.create(Tracer.prototype);
GraphTracer.prototype.constructor = GraphTracer; GraphTracer.prototype.constructor = GraphTracer;
...@@ -59,7 +61,6 @@ GraphTracer.prototype.setTreeData = function (G, root) { ...@@ -59,7 +61,6 @@ GraphTracer.prototype.setTreeData = function (G, root) {
if (this.setData(G, root)) return true; if (this.setData(G, root)) return true;
var place = function (node, x, y) { var place = function (node, x, y) {
console.log(node);
var temp = graph.nodes(n(node)); var temp = graph.nodes(n(node));
temp.x = x; temp.x = x;
temp.y = y; temp.y = y;
...@@ -190,10 +191,7 @@ GraphTracer.prototype.prevStep = function () { ...@@ -190,10 +191,7 @@ GraphTracer.prototype.prevStep = function () {
this.step(finalIndex); this.step(finalIndex);
}; };
var initGraph = function (module) { var initGraph = function () {
if (s && graph && graphMode == module.graphMode) return false;
graphMode = module.graphMode;
$('.visualize_container').empty(); $('.visualize_container').empty();
if (sigmaCanvas == null) { if (sigmaCanvas == null) {
sigmaCanvas = $.extend(true, {}, sigma.canvas); sigmaCanvas = $.extend(true, {}, sigma.canvas);
...@@ -232,8 +230,6 @@ var initGraph = function (module) { ...@@ -232,8 +230,6 @@ var initGraph = function (module) {
drawArrow(edge, source, target, color, context, settings); drawArrow(edge, source, target, color, context, settings);
}; };
sigma.plugins.dragNodes(s, s.renderers[0]); sigma.plugins.dragNodes(s, s.renderers[0]);
return true;
}; };
var graphColor = { var graphColor = {
......
...@@ -6,7 +6,6 @@ function WeightedGraphTracer(module) { ...@@ -6,7 +6,6 @@ function WeightedGraphTracer(module) {
return false; return false;
} }
WeightedGraphTracer.graphMode = "weighted";
WeightedGraphTracer.prototype = Object.create(GraphTracer.prototype); WeightedGraphTracer.prototype = Object.create(GraphTracer.prototype);
WeightedGraphTracer.prototype.constructor = WeightedGraphTracer; WeightedGraphTracer.prototype.constructor = WeightedGraphTracer;
......
...@@ -13,6 +13,7 @@ var codeEditor = initEditor('code'); ...@@ -13,6 +13,7 @@ var codeEditor = initEditor('code');
dataEditor.on('change', function () { dataEditor.on('change', function () {
try { try {
eval(dataEditor.getValue()); eval(dataEditor.getValue());
lastModule = _tracer && _tracer.module;
_tracer = tracer; _tracer = tracer;
} catch (err) { } catch (err) {
} }
...@@ -20,7 +21,6 @@ dataEditor.on('change', function () { ...@@ -20,7 +21,6 @@ dataEditor.on('change', function () {
}); });
var loadFile = function (category, algorithm, file, explanation) { var loadFile = function (category, algorithm, file, explanation) {
lastModule = null;
lastData = null; lastData = null;
$('#explanation').html(explanation); $('#explanation').html(explanation);
dataEditor.setValue(''); dataEditor.setValue('');
...@@ -134,6 +134,7 @@ $('#navigation').click(function () { ...@@ -134,6 +134,7 @@ $('#navigation').click(function () {
$('#btn_run').click(function () { $('#btn_run').click(function () {
try { try {
eval(dataEditor.getValue()); eval(dataEditor.getValue());
lastModule = _tracer && _tracer.module;
_tracer = tracer; _tracer = tracer;
_tracer.reset(); _tracer.reset();
eval(codeEditor.getValue()); eval(codeEditor.getValue());
......
...@@ -9,6 +9,8 @@ var Tracer = function (module) { ...@@ -9,6 +9,8 @@ var Tracer = function (module) {
this.traceOptions = null; this.traceOptions = null;
this.traceIndex = -1; this.traceIndex = -1;
this.stepCnt = 0; this.stepCnt = 0;
return lastModule != module;
}; };
Tracer.prototype.resize = function () { Tracer.prototype.resize = function () {
...@@ -30,8 +32,7 @@ Tracer.prototype.createRandomData = function (arguments) { ...@@ -30,8 +32,7 @@ Tracer.prototype.createRandomData = function (arguments) {
Tracer.prototype.setData = function (arguments) { Tracer.prototype.setData = function (arguments) {
var data = JSON.stringify(arguments); var data = JSON.stringify(arguments);
if (lastModule == this.module && lastData == data) return true; if (lastData == data) return true;
lastModule = this.module;
lastData = data; lastData = data;
return false; return false;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册