Skip to content

Commit 33e5861

Browse files
committed
separate tracer module and data module
1 parent e437d72 commit 33e5861

26 files changed

+473
-511
lines changed

js/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const RSVP = require('rsvp');
4-
const appInstance = require('./app');
4+
const app = require('./app');
55
const AppConstructor = require('./app/constructor');
66
const DOM = require('./dom');
77
const Server = require('./server');
@@ -33,14 +33,14 @@ RSVP.on('error', function (reason) {
3333
$(() => {
3434

3535
// initialize the application and attach in to the instance module
36-
const app = new AppConstructor();
37-
extend(true, appInstance, app);
36+
const appConstructor = new AppConstructor();
37+
extend(true, app, appConstructor);
3838

3939
// load modules to the global scope so they can be evaled
4040
extend(true, window, modules);
4141

4242
Server.loadCategories().then((data) => {
43-
appInstance.setCategories(data);
43+
app.setCategories(data);
4444
DOM.addCategories();
4545

4646
// determine if the app is loading a pre-existing scratch-pad

js/module/data/array1d.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const Array2D = require('./array2d');
2+
3+
const random = (N, min, max) => {
4+
return Array2D.random(1, N, min, max)[0];
5+
};
6+
7+
const randomSorted = (N, min, max)=> {
8+
return Array2D.randomSorted(1, N, min, max)[0];
9+
};
10+
11+
module.exports = {
12+
random,
13+
randomSorted
14+
};

js/module/data/array2d.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const random = (N, M, min, max) => {
2+
if (!N) N = 10;
3+
if (!M) M = 10;
4+
if (min === undefined) min = 1;
5+
if (max === undefined) max = 9;
6+
var D = [];
7+
for (var i = 0; i < N; i++) {
8+
D.push([]);
9+
for (var j = 0; j < M; j++) {
10+
D[i].push((Math.random() * (max - min + 1) | 0) + min);
11+
}
12+
}
13+
return D;
14+
};
15+
16+
const randomSorted = (N, M, min, max)=> {
17+
return this.random(N, M, min, max).map(function (arr) {
18+
return arr.sort(function (a, b) {
19+
return a - b;
20+
});
21+
});
22+
};
23+
24+
module.exports = {
25+
random,
26+
randomSorted
27+
};

js/module/data/coordinate_system.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const random = (N, min, max) => {
2+
if (!N) N = 7;
3+
if (!min) min = 1;
4+
if (!max) max = 10;
5+
var C = new Array(N);
6+
for (var i = 0; i < N; i++) C[i] = new Array(2);
7+
for (var i = 0; i < N; i++)
8+
for (var j = 0; j < C[i].length; j++)
9+
C[i][j] = (Math.random() * (max - min + 1) | 0) + min;
10+
return C;
11+
};
12+
13+
module.exports = {
14+
random
15+
};

js/module/data/directed_graph.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const random = (N, ratio) => {
2+
if (!N) N = 5;
3+
if (!ratio) ratio = .3;
4+
var G = new Array(N);
5+
for (var i = 0; i < N; i++) {
6+
G[i] = new Array(N);
7+
for (var j = 0; j < N; j++) {
8+
if (i != j) {
9+
G[i][j] = (Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0;
10+
}
11+
}
12+
}
13+
return G;
14+
};
15+
16+
module.exports = {
17+
random
18+
};

js/module/data/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const Array1D = require('./array1d');
4+
const Array2D = require('./array2d');
5+
const CoordinateSystem = require('./coordinate_system');
6+
const DirectedGraph = require('./directed_graph');
7+
const UndirectedGraph = require('./undirected_graph');
8+
const WeightedDirectedGraph = require('./weighted_directed_graph');
9+
const WeightedUndirectedGraph = require('./weighted_undirected_graph');
10+
11+
module.exports = {
12+
Array1D,
13+
Array2D,
14+
CoordinateSystem,
15+
DirectedGraph,
16+
UndirectedGraph,
17+
WeightedDirectedGraph,
18+
WeightedUndirectedGraph
19+
};

js/module/data/undirected_graph.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const random = (N, ratio) => {
2+
if (!N) N = 5;
3+
if (!ratio) ratio = .3;
4+
var G = new Array(N);
5+
for (var i = 0; i < N; i++) G[i] = new Array(N);
6+
for (var i = 0; i < N; i++) {
7+
for (var j = 0; j < N; j++) {
8+
if (i > j) {
9+
G[i][j] = G[j][i] = (Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0;
10+
}
11+
}
12+
}
13+
return G;
14+
};
15+
16+
module.exports = {
17+
random
18+
};
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const random = (N, ratio, min, max) => {
2+
if (!N) N = 5;
3+
if (!ratio) ratio = .3;
4+
if (!min) min = 1;
5+
if (!max) max = 5;
6+
var G = new Array(N);
7+
for (var i = 0; i < N; i++) {
8+
G[i] = new Array(N);
9+
for (var j = 0; j < N; j++) {
10+
if (i != j && (Math.random() * (1 / ratio) | 0) == 0) {
11+
G[i][j] = (Math.random() * (max - min + 1) | 0) + min;
12+
}
13+
}
14+
}
15+
return G;
16+
};
17+
18+
module.exports = {
19+
random
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const random = (N, ratio, min, max) => {
2+
if (!N) N = 5;
3+
if (!ratio) ratio = .3;
4+
if (!min) min = 1;
5+
if (!max) max = 5;
6+
var G = new Array(N);
7+
for (var i = 0; i < N; i++) G[i] = new Array(N);
8+
for (var i = 0; i < N; i++) {
9+
for (var j = 0; j < N; j++) {
10+
if (i > j && (Math.random() * (1 / ratio) | 0) == 0) {
11+
G[i][j] = G[j][i] = (Math.random() * (max - min + 1) | 0) + min;
12+
}
13+
}
14+
}
15+
return G;
16+
};
17+
18+
module.exports = {
19+
random
20+
};

js/module/index.js

+5-54
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,10 @@
11
'use strict';
22

3-
const Tracer = require('./tracer');
3+
var tracers = require('./tracer');
4+
var datas = require('./data');
45

5-
const LogTracer = require('./log_tracer');
6-
7-
const {
8-
Array1D,
9-
Array1DTracer
10-
} = require('./array1d');
11-
const {
12-
Array2D,
13-
Array2DTracer
14-
} = require('./array2d');
15-
16-
const ChartTracer = require('./chart');
17-
18-
const {
19-
CoordinateSystem,
20-
CoordinateSystemTracer
21-
} = require('./coordinate_system');
22-
23-
const {
24-
DirectedGraph,
25-
DirectedGraphTracer
26-
} = require('./directed_graph');
27-
const {
28-
UndirectedGraph,
29-
UndirectedGraphTracer
30-
} = require('./undirected_graph');
31-
32-
const {
33-
WeightedDirectedGraph,
34-
WeightedDirectedGraphTracer
35-
} = require('./weighted_directed_graph');
366
const {
37-
WeightedUndirectedGraph,
38-
WeightedUndirectedGraphTracer
39-
} = require('./weighted_undirected_graph');
7+
extend
8+
} = $;
409

41-
module.exports = {
42-
Tracer,
43-
LogTracer,
44-
Array1D,
45-
Array1DTracer,
46-
Array2D,
47-
Array2DTracer,
48-
ChartTracer,
49-
CoordinateSystem,
50-
CoordinateSystemTracer,
51-
DirectedGraph,
52-
DirectedGraphTracer,
53-
UndirectedGraph,
54-
UndirectedGraphTracer,
55-
WeightedDirectedGraph,
56-
WeightedDirectedGraphTracer,
57-
WeightedUndirectedGraph,
58-
WeightedUndirectedGraphTracer
59-
};
10+
module.exports = extend(true, {}, tracers, datas);

js/module/array1d.js renamed to js/module/tracer/array1d.js

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
const {
2-
Array2D,
3-
Array2DTracer
4-
} = require('./array2d');
1+
const Array2DTracer = require('./array2d');
52

63
function Array1DTracer() {
74
return Array2DTracer.apply(this, arguments);
@@ -39,16 +36,4 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype),
3936
}
4037
});
4138

42-
var Array1D = {
43-
random: function (N, min, max) {
44-
return Array2D.random(1, N, min, max)[0];
45-
},
46-
randomSorted: function (N, min, max) {
47-
return Array2D.randomSorted(1, N, min, max)[0];
48-
}
49-
};
50-
51-
module.exports = {
52-
Array1D,
53-
Array1DTracer
54-
};
39+
module.exports = Array1DTracer;

js/module/array2d.js renamed to js/module/tracer/array2d.js

+3-29
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const Tracer = require('./tracer');
2+
23
const {
34
refineByType
4-
} = require('../tracer_manager/util');
5+
} = require('../../tracer_manager/util/index');
56

67
function Array2DTracer() {
78
if (Tracer.apply(this, arguments)) {
@@ -303,31 +304,4 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
303304
}
304305
});
305306

306-
var Array2D = {
307-
random: function (N, M, min, max) {
308-
if (!N) N = 10;
309-
if (!M) M = 10;
310-
if (min === undefined) min = 1;
311-
if (max === undefined) max = 9;
312-
var D = [];
313-
for (var i = 0; i < N; i++) {
314-
D.push([]);
315-
for (var j = 0; j < M; j++) {
316-
D[i].push((Math.random() * (max - min + 1) | 0) + min);
317-
}
318-
}
319-
return D;
320-
},
321-
randomSorted: function (N, M, min, max) {
322-
return this.random(N, M, min, max).map(function (arr) {
323-
return arr.sort(function (a, b) {
324-
return a - b;
325-
});
326-
});
327-
}
328-
};
329-
330-
module.exports = {
331-
Array2D,
332-
Array2DTracer
333-
};
307+
module.exports = Array2DTracer;
File renamed without changes.

js/module/coordinate_system.js renamed to js/module/tracer/coordinate_system.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
const {
2-
DirectedGraph,
3-
DirectedGraphTracer
4-
} = require('./directed_graph');
1+
const DirectedGraphTracer = require('./directed_graph');
52

63
function CoordinateSystemTracer() {
74
if (DirectedGraphTracer.apply(this, arguments)) {
@@ -137,21 +134,4 @@ CoordinateSystemTracer.prototype = $.extend(true, Object.create(DirectedGraphTra
137134
}
138135
});
139136

140-
var CoordinateSystem = {
141-
random: function (N, min, max) {
142-
if (!N) N = 7;
143-
if (!min) min = 1;
144-
if (!max) max = 10;
145-
var C = new Array(N);
146-
for (var i = 0; i < N; i++) C[i] = new Array(2);
147-
for (var i = 0; i < N; i++)
148-
for (var j = 0; j < C[i].length; j++)
149-
C[i][j] = (Math.random() * (max - min + 1) | 0) + min;
150-
return C;
151-
}
152-
};
153-
154-
module.exports = {
155-
CoordinateSystem,
156-
CoordinateSystemTracer
157-
};
137+
module.exports = CoordinateSystemTracer;

0 commit comments

Comments
 (0)