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

separate tracer module and data module

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