提交 c286e59d 编写于 作者: J Jason Park

remove global vars

上级 a58a553c
......@@ -111,7 +111,7 @@
<script src="js/sigma/plugins/sigma.plugins.dragNodes.min.js"></script>
<script src="js/ace/ace.js"></script>
<script src="js/ace/ext-language_tools.js"></script>
<script src="js/module/tracer_manager.js"></script>
<script src="js/tracer_manager.js"></script>
<script src="js/module/tracer.js"></script>
<script src="js/module/log_tracer.js"></script>
<script src="js/module/array2d.js"></script>
......
......@@ -13,7 +13,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
this.$container.append(this.$table);
},
_notify: function (x, y, v) {
tm.pushStep(this.capsule, {
this.tm.pushStep(this.capsule, {
type: 'notify',
x: x,
y: y,
......@@ -22,7 +22,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
return this;
},
_denotify: function (x, y) {
tm.pushStep(this.capsule, {
this.tm.pushStep(this.capsule, {
type: 'denotify',
x: x,
y: y
......@@ -93,14 +93,14 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
type: type
};
$.extend(step, coord);
tm.pushStep(this.capsule, step);
this.tm.pushStep(this.capsule, step);
},
processStep: function (step, options) {
switch (step.type) {
case 'notify':
if (step.v) {
var $row = this.$table.find('.mtbl-row').eq(step.x);
$row.find('.mtbl-cell').eq(step.y).text(refineNumber(step.v));
$row.find('.mtbl-cell').eq(step.y).text(TracerUtil.refineNumber(step.v));
}
case 'denotify':
case 'select':
......@@ -130,7 +130,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
if (Tracer.prototype.setData.apply(this, arguments)) {
this.$table.find('.mtbl-row').each(function (i) {
$(this).children().each(function (j) {
$(this).text(refineNumber(D[i][j]));
$(this).text(TracerUtil.refineNumber(D[i][j]));
});
});
return true;
......@@ -143,7 +143,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
for (var j = 0; j < D[i].length; j++) {
var $cell = $('<div class="mtbl-cell">')
.css(this.getCellCss())
.text(refineNumber(D[i][j]));
.text(TracerUtil.refineNumber(D[i][j]));
$row.append($cell);
}
}
......
......@@ -46,15 +46,15 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
this.graph = this.capsule.graph = this.s.graph;
},
_setTreeData: function (G, root) {
tm.pushStep(this.capsule, {type: 'setTreeData', arguments: arguments});
this.tm.pushStep(this.capsule, {type: 'setTreeData', arguments: arguments});
return this;
},
_visit: function (target, source) {
tm.pushStep(this.capsule, {type: 'visit', target: target, source: source});
this.tm.pushStep(this.capsule, {type: 'visit', target: target, source: source});
return this;
},
_leave: function (target, source) {
tm.pushStep(this.capsule, {type: 'leave', target: target, source: source});
this.tm.pushStep(this.capsule, {type: 'leave', target: target, source: source});
return this;
},
processStep: function (step, options) {
......
......@@ -13,7 +13,7 @@ LogTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
this.$container.append(this.$wrapper);
},
_print: function (msg) {
tm.pushStep(this.capsule, {type: 'print', msg: msg});
this.tm.pushStep(this.capsule, {type: 'print', msg: msg});
return this;
},
processStep: function (step, options) {
......
function Tracer(name) {
this.module = this.constructor;
this.capsule = tm.allocate(this);
this.capsule = this.tm.allocate(this);
$.extend(this, this.capsule);
this.setName(name);
return this.new;
......@@ -8,23 +8,24 @@ function Tracer(name) {
Tracer.prototype = {
constructor: Tracer,
tm: null,
_setData: function () {
var args = Array.prototype.slice.call(arguments);
tm.pushStep(this.capsule, {type: 'setData', args: toJSON(args)});
this.tm.pushStep(this.capsule, {type: 'setData', args: TracerUtil.toJSON(args)});
return this;
},
_clear: function () {
tm.pushStep(this.capsule, {type: 'clear'});
this.tm.pushStep(this.capsule, {type: 'clear'});
return this;
},
_wait: function () {
tm.newStep();
this.tm.newStep();
return this;
},
processStep: function (step, options) {
switch (step.type) {
case 'setData':
this.setData.apply(this, fromJSON(step.args));
this.setData.apply(this, TracerUtil.fromJSON(step.args));
break;
case 'clear':
this.clear();
......@@ -42,7 +43,7 @@ Tracer.prototype = {
$name.text(name || this.defaultName);
},
setData: function () {
var data = toJSON(arguments);
var data = TracerUtil.toJSON(arguments);
if (!this.new && this.lastData == data) return true;
this.new = this.capsule.new = false;
this.lastData = this.capsule.lastData = data;
......
......@@ -30,22 +30,22 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
});
},
_weight: function (target, weight) {
tm.pushStep(this.capsule, {type: 'weight', target: target, weight: weight});
this.tm.pushStep(this.capsule, {type: 'weight', target: target, weight: weight});
return this;
},
_visit: function (target, source, weight) {
tm.pushStep(this.capsule, {type: 'visit', target: target, source: source, weight: weight});
this.tm.pushStep(this.capsule, {type: 'visit', target: target, source: source, weight: weight});
return this;
},
_leave: function (target, source, weight) {
tm.pushStep(this.capsule, {type: 'leave', target: target, source: source, weight: weight});
this.tm.pushStep(this.capsule, {type: 'leave', target: target, source: source, weight: weight});
return this;
},
processStep: function (step, options) {
switch (step.type) {
case 'weight':
var targetNode = this.graph.nodes(this.n(step.target));
if (step.weight !== undefined) targetNode.weight = refineNumber(step.weight);
if (step.weight !== undefined) targetNode.weight = TracerUtil.refineNumber(step.weight);
break;
case 'visit':
case 'leave':
......@@ -53,7 +53,7 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
var targetNode = this.graph.nodes(this.n(step.target));
var color = visit ? this.color.visited : this.color.left;
targetNode.color = color;
if (step.weight !== undefined) targetNode.weight = refineNumber(step.weight);
if (step.weight !== undefined) targetNode.weight = TracerUtil.refineNumber(step.weight);
if (step.source !== undefined) {
var edgeId = this.e(step.source, step.target);
var edge = this.graph.edges(edgeId);
......@@ -97,7 +97,7 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
target: this.n(j),
color: this.color.default,
size: 1,
weight: refineNumber(G[i][j])
weight: TracerUtil.refineNumber(G[i][j])
});
}
}
......
此差异已折叠。
......@@ -10,7 +10,7 @@ var TracerManager = function () {
TracerManager.prototype = {
add: function (tracer) {
var $container = $('<section class="module_wrapper">');
$module_container.append($container);
$('.module_container').append($container);
var capsule = {
module: tracer.module,
tracer: tracer,
......@@ -176,4 +176,20 @@ TracerManager.prototype = {
});
return selectedCapsule.tracer;
}
};
var TracerUtil = {
toJSON: function (obj) {
return JSON.stringify(obj, function (key, value) {
return value === Infinity ? "Infinity" : value;
});
},
fromJSON: function (obj) {
return JSON.parse(obj, function (key, value) {
return value === "Infinity" ? Infinity : value;
});
},
refineNumber: function (number) {
return number === Infinity ? '' : number;
}
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册