Skip to content

Commit fa6f854

Browse files
committed
prepare for other modules
1 parent aec1266 commit fa6f854

File tree

7 files changed

+23
-17
lines changed

7 files changed

+23
-17
lines changed

algorithm/category.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,14 @@
55
"dfs": "DFS",
66
"bfs": "BFS"
77
}
8+
},
9+
"sorting": {
10+
"name": "Sorting",
11+
"list": {
12+
"insertion": "Insertion Sort",
13+
"selection": "Selection Sort",
14+
"bubble": "Bubble Sort",
15+
"quick": "Quick Sort"
16+
}
817
}
918
}

algorithm/graph_search/bfs/shortest_path/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ do {
2929
e = Math.random() * G.length | 0;
3030
} while (s == e);
3131
var MAX_VALUE = 999;
32-
tracer._pace(500);
32+
tracer._pace(100);
3333
tracer._print('finding the shortest path from ' + s + ' to ' + e);
3434
tracer._sleep(1000);
3535
var minWeight = BFS(s);

algorithm/graph_search/dfs/shortest_path/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ do {
2828
} while (s == e);
2929
var MAX_VALUE = 999;
3030
var minWeight = MAX_VALUE;
31-
tracer._pace(500);
31+
tracer._pace(100);
3232
tracer._print('finding the shortest path from ' + s + ' to ' + e);
3333
tracer._sleep(1000);
3434
var D = []; // D[i] indicates whether the i-th node is discovered or not

js/module/graph.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
var s = null, graph = null, graphMode = null, sigmaCanvas = null;
1+
var s = null, graph = null, sigmaCanvas = null;
22

33
function GraphTracer(module) {
4-
Tracer.call(this, module || GraphTracer);
5-
return initGraph(this.module);
4+
if (Tracer.call(this, module || WeightedGraphTracer)) {
5+
initGraph();
6+
return true;
7+
}
8+
return false;
69
}
710

8-
GraphTracer.graphMode = "default";
911
GraphTracer.prototype = Object.create(Tracer.prototype);
1012
GraphTracer.prototype.constructor = GraphTracer;
1113

@@ -59,7 +61,6 @@ GraphTracer.prototype.setTreeData = function (G, root) {
5961
if (this.setData(G, root)) return true;
6062

6163
var place = function (node, x, y) {
62-
console.log(node);
6364
var temp = graph.nodes(n(node));
6465
temp.x = x;
6566
temp.y = y;
@@ -190,10 +191,7 @@ GraphTracer.prototype.prevStep = function () {
190191
this.step(finalIndex);
191192
};
192193

193-
var initGraph = function (module) {
194-
if (s && graph && graphMode == module.graphMode) return false;
195-
graphMode = module.graphMode;
196-
194+
var initGraph = function () {
197195
$('.visualize_container').empty();
198196
if (sigmaCanvas == null) {
199197
sigmaCanvas = $.extend(true, {}, sigma.canvas);
@@ -232,8 +230,6 @@ var initGraph = function (module) {
232230
drawArrow(edge, source, target, color, context, settings);
233231
};
234232
sigma.plugins.dragNodes(s, s.renderers[0]);
235-
236-
return true;
237233
};
238234

239235
var graphColor = {

js/module/weighted_graph.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ function WeightedGraphTracer(module) {
66
return false;
77
}
88

9-
WeightedGraphTracer.graphMode = "weighted";
109
WeightedGraphTracer.prototype = Object.create(GraphTracer.prototype);
1110
WeightedGraphTracer.prototype.constructor = WeightedGraphTracer;
1211

js/script.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ var codeEditor = initEditor('code');
1313
dataEditor.on('change', function () {
1414
try {
1515
eval(dataEditor.getValue());
16+
lastModule = _tracer && _tracer.module;
1617
_tracer = tracer;
1718
} catch (err) {
1819
}
1920
_tracer.reset();
2021
});
2122

2223
var loadFile = function (category, algorithm, file, explanation) {
23-
lastModule = null;
2424
lastData = null;
2525
$('#explanation').html(explanation);
2626
dataEditor.setValue('');
@@ -134,6 +134,7 @@ $('#navigation').click(function () {
134134
$('#btn_run').click(function () {
135135
try {
136136
eval(dataEditor.getValue());
137+
lastModule = _tracer && _tracer.module;
137138
_tracer = tracer;
138139
_tracer.reset();
139140
eval(codeEditor.getValue());

js/tracer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var Tracer = function (module) {
99
this.traceOptions = null;
1010
this.traceIndex = -1;
1111
this.stepCnt = 0;
12+
13+
return lastModule != module;
1214
};
1315

1416
Tracer.prototype.resize = function () {
@@ -30,8 +32,7 @@ Tracer.prototype.createRandomData = function (arguments) {
3032

3133
Tracer.prototype.setData = function (arguments) {
3234
var data = JSON.stringify(arguments);
33-
if (lastModule == this.module && lastData == data) return true;
34-
lastModule = this.module;
35+
if (lastData == data) return true;
3536
lastData = data;
3637
return false;
3738
};

0 commit comments

Comments
 (0)