提交 39e2ef00 编写于 作者: J Jason Park

separate tracer module and data module

上级 3c0d2c6d
'use strict';
const RSVP = require('rsvp');
const appInstance = require('./app');
const app = require('./app');
const AppConstructor = require('./app/constructor');
const DOM = require('./dom');
const Server = require('./server');
......@@ -33,14 +33,14 @@ RSVP.on('error', function (reason) {
$(() => {
// initialize the application and attach in to the instance module
const app = new AppConstructor();
extend(true, appInstance, app);
const appConstructor = new AppConstructor();
extend(true, app, appConstructor);
// load modules to the global scope so they can be evaled
extend(true, window, modules);
Server.loadCategories().then((data) => {
appInstance.setCategories(data);
app.setCategories(data);
DOM.addCategories();
// determine if the app is loading a pre-existing scratch-pad
......
const Array2D = require('./array2d');
const random = (N, min, max) => {
return Array2D.random(1, N, min, max)[0];
};
const randomSorted = (N, min, max)=> {
return Array2D.randomSorted(1, N, min, max)[0];
};
module.exports = {
random,
randomSorted
};
const random = (N, M, min, max) => {
if (!N) N = 10;
if (!M) M = 10;
if (min === undefined) min = 1;
if (max === undefined) max = 9;
var D = [];
for (var i = 0; i < N; i++) {
D.push([]);
for (var j = 0; j < M; j++) {
D[i].push((Math.random() * (max - min + 1) | 0) + min);
}
}
return D;
};
const randomSorted = (N, M, min, max)=> {
return this.random(N, M, min, max).map(function (arr) {
return arr.sort(function (a, b) {
return a - b;
});
});
};
module.exports = {
random,
randomSorted
};
\ No newline at end of file
const random = (N, min, max) => {
if (!N) N = 7;
if (!min) min = 1;
if (!max) max = 10;
var C = new Array(N);
for (var i = 0; i < N; i++) C[i] = new Array(2);
for (var i = 0; i < N; i++)
for (var j = 0; j < C[i].length; j++)
C[i][j] = (Math.random() * (max - min + 1) | 0) + min;
return C;
};
module.exports = {
random
};
\ No newline at end of file
const random = (N, ratio) => {
if (!N) N = 5;
if (!ratio) ratio = .3;
var G = new Array(N);
for (var i = 0; i < N; i++) {
G[i] = new Array(N);
for (var j = 0; j < N; j++) {
if (i != j) {
G[i][j] = (Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0;
}
}
}
return G;
};
module.exports = {
random
};
\ No newline at end of file
'use strict';
const Array1D = require('./array1d');
const Array2D = require('./array2d');
const CoordinateSystem = require('./coordinate_system');
const DirectedGraph = require('./directed_graph');
const UndirectedGraph = require('./undirected_graph');
const WeightedDirectedGraph = require('./weighted_directed_graph');
const WeightedUndirectedGraph = require('./weighted_undirected_graph');
module.exports = {
Array1D,
Array2D,
CoordinateSystem,
DirectedGraph,
UndirectedGraph,
WeightedDirectedGraph,
WeightedUndirectedGraph
};
\ No newline at end of file
const random = (N, ratio) => {
if (!N) N = 5;
if (!ratio) ratio = .3;
var G = new Array(N);
for (var i = 0; i < N; i++) G[i] = new Array(N);
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (i > j) {
G[i][j] = G[j][i] = (Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0;
}
}
}
return G;
};
module.exports = {
random
};
\ No newline at end of file
const random = (N, ratio, min, max) => {
if (!N) N = 5;
if (!ratio) ratio = .3;
if (!min) min = 1;
if (!max) max = 5;
var G = new Array(N);
for (var i = 0; i < N; i++) {
G[i] = new Array(N);
for (var j = 0; j < N; j++) {
if (i != j && (Math.random() * (1 / ratio) | 0) == 0) {
G[i][j] = (Math.random() * (max - min + 1) | 0) + min;
}
}
}
return G;
};
module.exports = {
random
};
\ No newline at end of file
const random = (N, ratio, min, max) => {
if (!N) N = 5;
if (!ratio) ratio = .3;
if (!min) min = 1;
if (!max) max = 5;
var G = new Array(N);
for (var i = 0; i < N; i++) G[i] = new Array(N);
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (i > j && (Math.random() * (1 / ratio) | 0) == 0) {
G[i][j] = G[j][i] = (Math.random() * (max - min + 1) | 0) + min;
}
}
}
return G;
};
module.exports = {
random
};
\ No newline at end of file
'use strict';
const Tracer = require('./tracer');
var tracers = require('./tracer');
var datas = require('./data');
const LogTracer = require('./log_tracer');
const {
Array1D,
Array1DTracer
} = require('./array1d');
const {
Array2D,
Array2DTracer
} = require('./array2d');
const ChartTracer = require('./chart');
const {
CoordinateSystem,
CoordinateSystemTracer
} = require('./coordinate_system');
const {
DirectedGraph,
DirectedGraphTracer
} = require('./directed_graph');
const {
UndirectedGraph,
UndirectedGraphTracer
} = require('./undirected_graph');
const {
WeightedDirectedGraph,
WeightedDirectedGraphTracer
} = require('./weighted_directed_graph');
const {
WeightedUndirectedGraph,
WeightedUndirectedGraphTracer
} = require('./weighted_undirected_graph');
extend
} = $;
module.exports = {
Tracer,
LogTracer,
Array1D,
Array1DTracer,
Array2D,
Array2DTracer,
ChartTracer,
CoordinateSystem,
CoordinateSystemTracer,
DirectedGraph,
DirectedGraphTracer,
UndirectedGraph,
UndirectedGraphTracer,
WeightedDirectedGraph,
WeightedDirectedGraphTracer,
WeightedUndirectedGraph,
WeightedUndirectedGraphTracer
};
\ No newline at end of file
module.exports = extend(true, {}, tracers, datas);
\ No newline at end of file
const {
Array2D,
Array2DTracer
} = require('./array2d');
const Array2DTracer = require('./array2d');
function Array1DTracer() {
return Array2DTracer.apply(this, arguments);
......@@ -39,16 +36,4 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype),
}
});
var Array1D = {
random: function (N, min, max) {
return Array2D.random(1, N, min, max)[0];
},
randomSorted: function (N, min, max) {
return Array2D.randomSorted(1, N, min, max)[0];
}
};
module.exports = {
Array1D,
Array1DTracer
};
\ No newline at end of file
module.exports = Array1DTracer;
\ No newline at end of file
const Tracer = require('./tracer');
const {
refineByType
} = require('../tracer_manager/util');
} = require('../../tracer_manager/util/index');
function Array2DTracer() {
if (Tracer.apply(this, arguments)) {
......@@ -303,31 +304,4 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
}
});
var Array2D = {
random: function (N, M, min, max) {
if (!N) N = 10;
if (!M) M = 10;
if (min === undefined) min = 1;
if (max === undefined) max = 9;
var D = [];
for (var i = 0; i < N; i++) {
D.push([]);
for (var j = 0; j < M; j++) {
D[i].push((Math.random() * (max - min + 1) | 0) + min);
}
}
return D;
},
randomSorted: function (N, M, min, max) {
return this.random(N, M, min, max).map(function (arr) {
return arr.sort(function (a, b) {
return a - b;
});
});
}
};
module.exports = {
Array2D,
Array2DTracer
};
\ No newline at end of file
module.exports = Array2DTracer;
\ No newline at end of file
const {
DirectedGraph,
DirectedGraphTracer
} = require('./directed_graph');
const DirectedGraphTracer = require('./directed_graph');
function CoordinateSystemTracer() {
if (DirectedGraphTracer.apply(this, arguments)) {
......@@ -137,21 +134,4 @@ CoordinateSystemTracer.prototype = $.extend(true, Object.create(DirectedGraphTra
}
});
var CoordinateSystem = {
random: function (N, min, max) {
if (!N) N = 7;
if (!min) min = 1;
if (!max) max = 10;
var C = new Array(N);
for (var i = 0; i < N; i++) C[i] = new Array(2);
for (var i = 0; i < N; i++)
for (var j = 0; j < C[i].length; j++)
C[i][j] = (Math.random() * (max - min + 1) | 0) + min;
return C;
}
};
module.exports = {
CoordinateSystem,
CoordinateSystemTracer
};
\ No newline at end of file
module.exports = CoordinateSystemTracer;
\ No newline at end of file
......@@ -334,23 +334,6 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
}
});
var DirectedGraph = {
random: function (N, ratio) {
if (!N) N = 5;
if (!ratio) ratio = .3;
var G = new Array(N);
for (var i = 0; i < N; i++) {
G[i] = new Array(N);
for (var j = 0; j < N; j++) {
if (i != j) {
G[i][j] = (Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0;
}
}
}
return G;
}
};
sigma.canvas.labels.def = function (node, context, settings) {
var func = settings('funcLabelsDef');
if (func) {
......@@ -376,7 +359,4 @@ sigma.canvas.edges.arrow = function (edge, source, target, context, settings) {
}
};
module.exports = {
DirectedGraph,
DirectedGraphTracer
};
\ No newline at end of file
module.exports = DirectedGraphTracer;
\ No newline at end of file
'use strict';
const Tracer = require('./tracer');
const LogTracer = require('./log');
const Array1DTracer = require('./array1d');
const Array2DTracer = require('./array2d');
const ChartTracer = require('./chart');
const CoordinateSystemTracer = require('./coordinate_system');
const DirectedGraphTracer = require('./directed_graph');
const UndirectedGraphTracer = require('./undirected_graph');
const WeightedDirectedGraphTracer = require('./weighted_directed_graph');
const WeightedUndirectedGraphTracer = require('./weighted_undirected_graph');
module.exports = {
Tracer,
LogTracer,
Array1DTracer,
Array2DTracer,
ChartTracer,
CoordinateSystemTracer,
DirectedGraphTracer,
UndirectedGraphTracer,
WeightedDirectedGraphTracer,
WeightedUndirectedGraphTracer
};
\ No newline at end of file
const {
toJSON,
fromJSON
} = require('../tracer_manager/util');
} = require('../../tracer_manager/util/index');
function Tracer(name) {
this.module = this.constructor;
......
const {
DirectedGraph,
DirectedGraphTracer
} = require('./directed_graph');
const DirectedGraphTracer = require('./directed_graph');
function UndirectedGraphTracer() {
if (DirectedGraphTracer.apply(this, arguments)) {
......@@ -121,24 +118,4 @@ UndirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGraphTrac
}
});
var UndirectedGraph = {
random: function (N, ratio) {
if (!N) N = 5;
if (!ratio) ratio = .3;
var G = new Array(N);
for (var i = 0; i < N; i++) G[i] = new Array(N);
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (i > j) {
G[i][j] = G[j][i] = (Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0;
}
}
}
return G;
}
};
module.exports = {
UndirectedGraph,
UndirectedGraphTracer
};
\ No newline at end of file
module.exports = UndirectedGraphTracer;
\ No newline at end of file
const {
DirectedGraph,
DirectedGraphTracer
} = require('./directed_graph');
const DirectedGraphTracer = require('./directed_graph');
const {
refineByType
} = require('../tracer_manager/util');
} = require('../../tracer_manager/util/index');
function WeightedDirectedGraphTracer() {
if (DirectedGraphTracer.apply(this, arguments)) {
......@@ -237,26 +234,4 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
}
});
var WeightedDirectedGraph = {
random: function (N, ratio, min, max) {
if (!N) N = 5;
if (!ratio) ratio = .3;
if (!min) min = 1;
if (!max) max = 5;
var G = new Array(N);
for (var i = 0; i < N; i++) {
G[i] = new Array(N);
for (var j = 0; j < N; j++) {
if (i != j && (Math.random() * (1 / ratio) | 0) == 0) {
G[i][j] = (Math.random() * (max - min + 1) | 0) + min;
}
}
}
return G;
}
};
module.exports = {
WeightedDirectedGraph,
WeightedDirectedGraphTracer
};
\ No newline at end of file
module.exports = WeightedDirectedGraphTracer;
\ No newline at end of file
const {
WeightedDirectedGraph,
WeightedDirectedGraphTracer
} = require('./weighted_directed_graph');
const {
UndirectedGraphTracer
} = require('./undirected_graph');
const WeightedDirectedGraphTracer = require('./weighted_directed_graph');
const UndirectedGraphTracer = require('./undirected_graph');
function WeightedUndirectedGraphTracer() {
if (WeightedDirectedGraphTracer.apply(this, arguments)) {
......@@ -93,26 +87,4 @@ WeightedUndirectedGraphTracer.prototype = $.extend(true, Object.create(WeightedD
}
});
var WeightedUndirectedGraph = {
random: function (N, ratio, min, max) {
if (!N) N = 5;
if (!ratio) ratio = .3;
if (!min) min = 1;
if (!max) max = 5;
var G = new Array(N);
for (var i = 0; i < N; i++) G[i] = new Array(N);
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (i > j && (Math.random() * (1 / ratio) | 0) == 0) {
G[i][j] = G[j][i] = (Math.random() * (max - min + 1) | 0) + min;
}
}
}
return G;
}
};
module.exports = {
WeightedUndirectedGraph,
WeightedUndirectedGraphTracer
};
\ No newline at end of file
module.exports = WeightedUndirectedGraphTracer;
\ No newline at end of file
'use strict';
const TracerManager = require('./manager');
const Tracer = require('../module/tracer');
const Tracer = require('../module/tracer/tracer');
module.exports = {
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册