diff --git a/js/module/graph.js b/js/module/graph.js index 3e8bfef000cb109baa243ab68f34f0493a969710..726875695e2d112f255fb81aa92f6d9274dcef9c 100644 --- a/js/module/graph.js +++ b/js/module/graph.js @@ -1,11 +1,13 @@ -var s = null, graph = null, graphMode = null, sigmaCanvas = null; +var s = null, graph = null, sigmaCanvas = null; function GraphTracer(module) { - Tracer.call(this, module || GraphTracer); - return initGraph(this.module); + if (Tracer.call(this, module || WeightedGraphTracer)) { + initGraph(); + return true; + } + return false; } -GraphTracer.graphMode = "default"; GraphTracer.prototype = Object.create(Tracer.prototype); GraphTracer.prototype.constructor = GraphTracer; @@ -59,7 +61,6 @@ GraphTracer.prototype.setTreeData = function (G, root) { if (this.setData(G, root)) return true; var place = function (node, x, y) { - console.log(node); var temp = graph.nodes(n(node)); temp.x = x; temp.y = y; @@ -190,10 +191,7 @@ GraphTracer.prototype.prevStep = function () { this.step(finalIndex); }; -var initGraph = function (module) { - if (s && graph && graphMode == module.graphMode) return false; - graphMode = module.graphMode; - +var initGraph = function () { $('.visualize_container').empty(); if (sigmaCanvas == null) { sigmaCanvas = $.extend(true, {}, sigma.canvas); @@ -232,8 +230,6 @@ var initGraph = function (module) { drawArrow(edge, source, target, color, context, settings); }; sigma.plugins.dragNodes(s, s.renderers[0]); - - return true; }; var graphColor = { diff --git a/js/module/weighted_graph.js b/js/module/weighted_graph.js index 85edbddae470850583ccd4481fa6572e2883cd0c..73df8d9613a2997ea0fc5041dc2961c00f2f5ff3 100644 --- a/js/module/weighted_graph.js +++ b/js/module/weighted_graph.js @@ -6,7 +6,6 @@ function WeightedGraphTracer(module) { return false; } -WeightedGraphTracer.graphMode = "weighted"; WeightedGraphTracer.prototype = Object.create(GraphTracer.prototype); WeightedGraphTracer.prototype.constructor = WeightedGraphTracer; diff --git a/js/script.js b/js/script.js index f35389f6915588483dcdb3c780ab133199b9aed7..85850f30a3d6de1e4ac5471350e19f907e480326 100644 --- a/js/script.js +++ b/js/script.js @@ -13,6 +13,7 @@ var codeEditor = initEditor('code'); dataEditor.on('change', function () { try { eval(dataEditor.getValue()); + lastModule = _tracer && _tracer.module; _tracer = tracer; } catch (err) { } @@ -20,7 +21,6 @@ dataEditor.on('change', function () { }); var loadFile = function (category, algorithm, file, explanation) { - lastModule = null; lastData = null; $('#explanation').html(explanation); dataEditor.setValue(''); @@ -134,6 +134,7 @@ $('#navigation').click(function () { $('#btn_run').click(function () { try { eval(dataEditor.getValue()); + lastModule = _tracer && _tracer.module; _tracer = tracer; _tracer.reset(); eval(codeEditor.getValue()); diff --git a/js/tracer.js b/js/tracer.js index 115333b30409a3384ea1273c6be0d1d7d086d780..3cd046d7eed3e60bd3b01356faaa4373a4ef5e0b 100644 --- a/js/tracer.js +++ b/js/tracer.js @@ -9,6 +9,8 @@ var Tracer = function (module) { this.traceOptions = null; this.traceIndex = -1; this.stepCnt = 0; + + return lastModule != module; }; Tracer.prototype.resize = function () { @@ -30,8 +32,7 @@ Tracer.prototype.createRandomData = function (arguments) { Tracer.prototype.setData = function (arguments) { var data = JSON.stringify(arguments); - if (lastModule == this.module && lastData == data) return true; - lastModule = this.module; + if (lastData == data) return true; lastData = data; return false; };