提交 500a9d2b 编写于 作者: J Jason Park

modify all the agorithms since tracer modules are revised

上级 03545ee5
...@@ -169,7 +169,6 @@ section { ...@@ -169,7 +169,6 @@ section {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: scroll;
visibility: hidden; visibility: hidden;
} }
...@@ -182,15 +181,20 @@ section { ...@@ -182,15 +181,20 @@ section {
visibility: visible; visibility: visible;
} }
.module_wrapper {
overflow: scroll;
}
.module_wrapper .name { .module_wrapper .name {
position: absolute; position: fixed;
z-index: 5;
padding: 4px; padding: 4px;
font-size: 14px; font-size: 14px;
background: rgb(44, 44, 44); background: rgb(44, 44, 44);
} }
.module_wrapper .wrapper { .module_wrapper .wrapper {
padding: 16px; padding: 24px 16px;
box-sizing: border-box; box-sizing: border-box;
} }
...@@ -297,6 +301,6 @@ pre { ...@@ -297,6 +301,6 @@ pre {
background: #00f; background: #00f;
} }
.mtbl-cell.notifying { .mtbl-cell.notified {
background: #f00; background: #f00;
} }
...@@ -4,12 +4,13 @@ function Array1DTracer(module) { ...@@ -4,12 +4,13 @@ function Array1DTracer(module) {
Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), { Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), {
constructor: Array1DTracer, constructor: Array1DTracer,
_notify: function (idx1, idx2) { _notify: function (idx, v) {
if (idx2 === undefined) { Array2DTracer.prototype._notify.call(this, 0, idx, v);
Array2DTracer.prototype._notify.call(this, 0, idx1); return this;
} else { },
Array2DTracer.prototype._notify.call(this, 0, idx1, 0, idx2); _denotify: function (idx) {
} Array2DTracer.prototype._denotify.call(this, 0, idx);
return this;
}, },
_select: function (s, e) { _select: function (s, e) {
if (e === undefined) { if (e === undefined) {
...@@ -17,16 +18,7 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), ...@@ -17,16 +18,7 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype),
} else { } else {
Array2DTracer.prototype._selectRow.call(this, 0, s, e); Array2DTracer.prototype._selectRow.call(this, 0, s, e);
} }
}, return this;
_selectSet: function (indexes) {
var coords = [];
indexes.forEach(function (index) {
coords.push({
x: 0,
y: index
});
});
Array2DTracer.prototype._selectSet.call(this, coords);
}, },
_deselect: function (s, e) { _deselect: function (s, e) {
if (e === undefined) { if (e === undefined) {
...@@ -34,16 +26,7 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype), ...@@ -34,16 +26,7 @@ Array1DTracer.prototype = $.extend(true, Object.create(Array2DTracer.prototype),
} else { } else {
Array2DTracer.prototype._deselectRow.call(this, 0, s, e); Array2DTracer.prototype._deselectRow.call(this, 0, s, e);
} }
}, return this;
_deselectSet: function (indexes) {
var coords = [];
indexes.forEach(function (index) {
coords.push({
x: 0,
y: index
});
});
Array2DTracer.prototype._deselectSet.call(this, coords);
}, },
setData: function (D) { setData: function (D) {
return Array2DTracer.prototype.setData.call(this, [D]); return Array2DTracer.prototype.setData.call(this, [D]);
......
...@@ -12,54 +12,59 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -12,54 +12,59 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
this.$table = this.capsule.$table = $('<div class="mtbl-table">'); this.$table = this.capsule.$table = $('<div class="mtbl-table">');
this.$container.append(this.$table); this.$container.append(this.$table);
}, },
_notify: function (x1, y1, x2, y2) { _notify: function (x1, y1, v1, x2, y2, v2) {
var second = x2 !== undefined && y2 !== undefined; var second = x2 !== undefined && y2 !== undefined;
tm.pushStep(this.capsule, { tm.pushStep(this.capsule, {
type: 'notifying', type: 'notify',
x: x1, x: x1,
y: y1, y: y1,
value: this.D[x1][y1] v: v1
}, !second); }, !second);
if (second) tm.pushStep(this.capsule, { if (second) tm.pushStep(this.capsule, {
type: 'notifying', type: 'notify',
x: x2, x: x2,
y: y2, y: y2,
value: this.D[x2][y2] v: v2
}); });
return this;
},
_denotify: function (x1, y1, x2, y2) {
var second = x2 !== undefined && y2 !== undefined;
tm.pushStep(this.capsule, { tm.pushStep(this.capsule, {
type: 'notified', type: 'denotify',
x: x1, x: x1,
y: y1 y: y1
}, false); });
if (second) tm.pushStep(this.capsule, { if (second) tm.pushStep(this.capsule, {
type: 'notified', type: 'denotify',
x: x2, x: x2,
y: y2 y: y2
}, false); });
return this;
}, },
_select: function (sx, sy, ex, ey) { _select: function (sx, sy, ex, ey) {
this.pushSelectingStep('select', null, arguments); this.pushSelectingStep('select', null, arguments);
return this;
}, },
_selectRow: function (x, sy, ey) { _selectRow: function (x, sy, ey) {
this.pushSelectingStep('select', 'row', arguments); this.pushSelectingStep('select', 'row', arguments);
return this;
}, },
_selectCol: function (y, sx, ex) { _selectCol: function (y, sx, ex) {
this.pushSelectingStep('select', 'col', arguments); this.pushSelectingStep('select', 'col', arguments);
}, return this;
_selectSet: function (coords) {
this.pushSelectingStep('select', 'set', arguments);
}, },
_deselect: function (sx, sy, ex, ey) { _deselect: function (sx, sy, ex, ey) {
this.pushSelectingStep('deselect', null, arguments); this.pushSelectingStep('deselect', null, arguments);
return this;
}, },
_deselectRow: function (x, sy, ey) { _deselectRow: function (x, sy, ey) {
this.pushSelectingStep('deselect', 'row', arguments); this.pushSelectingStep('deselect', 'row', arguments);
return this;
}, },
_deselectCol: function (y, sx, ex) { _deselectCol: function (y, sx, ex) {
this.pushSelectingStep('deselect', 'col', arguments); this.pushSelectingStep('deselect', 'col', arguments);
}, return this;
_deselectSet: function (coords) {
this.pushSelectingStep('deselect', 'set', arguments);
}, },
pushSelectingStep: function () { pushSelectingStep: function () {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
...@@ -82,11 +87,6 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -82,11 +87,6 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
ex: args[2] ex: args[2]
}; };
break; break;
case 'set':
coord = {
coords: args[0]
};
break;
default: default:
if (args[2] === undefined && args[3] === undefined) { if (args[2] === undefined && args[3] === undefined) {
coord = { coord = {
...@@ -106,44 +106,37 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -106,44 +106,37 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
type: type type: type
}; };
$.extend(step, coord); $.extend(step, coord);
tm.pushStep(this.capsule, step, type == 'select'); tm.pushStep(this.capsule, step);
}, },
processStep: function (step, options) { processStep: function (step, options) {
var tracer = this; var tracer = this;
switch (step.type) { switch (step.type) {
case 'notifying': case 'notify':
var $row = this.$table.find('.mtbl-row').eq(step.x); if (step.v) {
$row.find('.mtbl-cell').eq(step.y).text(step.value); var $row = this.$table.find('.mtbl-row').eq(step.x);
case 'notified': $row.find('.mtbl-cell').eq(step.y).text(refineNumber(step.v));
}
case 'denotify':
case 'select': case 'select':
case 'deselect': case 'deselect':
var colorClass = step.type == 'select' || step.type == 'deselect' ? this.colorClass.selected : this.colorClass.notifying; var colorClass = step.type == 'select' || step.type == 'deselect' ? this.colorClass.selected : this.colorClass.notified;
var addClass = step.type == 'select' || step.type == 'notifying'; var addClass = step.type == 'select' || step.type == 'notify';
if (step.coords) { var sx = step.sx;
step.coords.forEach(function (coord) { var sy = step.sy;
var x = coord.x; var ex = step.ex;
var y = coord.y; var ey = step.ey;
tracer.paintColor(x, y, x, y, colorClass, addClass); if (sx === undefined) sx = step.x;
}); if (sy === undefined) sy = step.y;
} else { if (ex === undefined) ex = step.x;
var sx = step.sx; if (ey === undefined) ey = step.y;
var sy = step.sy; this.paintColor(sx, sy, ex, ey, colorClass, addClass);
var ex = step.ex;
var ey = step.ey;
if (sx === undefined) sx = step.x;
if (sy === undefined) sy = step.y;
if (ex === undefined) ex = step.x;
if (ey === undefined) ey = step.y;
this.paintColor(sx, sy, ex, ey, colorClass, addClass);
}
break; break;
default: default:
Tracer.prototype.processStep.call(this, step, options); Tracer.prototype.processStep.call(this, step, options);
} }
}, },
setData: function (D) { setData: function (D) {
this.D = D;
this.viewX = this.viewY = 0; this.viewX = this.viewY = 0;
this.paddingH = 6; this.paddingH = 6;
this.paddingV = 3; this.paddingV = 3;
...@@ -152,7 +145,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -152,7 +145,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
if (Tracer.prototype.setData.apply(this, arguments)) { if (Tracer.prototype.setData.apply(this, arguments)) {
this.$table.find('.mtbl-row').each(function (i) { this.$table.find('.mtbl-row').each(function (i) {
$(this).children().each(function (j) { $(this).children().each(function (j) {
$(this).text(D[i][j]); $(this).text(refineNumber(D[i][j]));
}); });
}); });
return true; return true;
...@@ -165,7 +158,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -165,7 +158,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
for (var j = 0; j < D[i].length; j++) { for (var j = 0; j < D[i].length; j++) {
var $cell = $('<div class="mtbl-cell">') var $cell = $('<div class="mtbl-cell">')
.css(this.getCellCss()) .css(this.getCellCss())
.text(D[i][j]); .text(refineNumber(D[i][j]));
$row.append($cell); $row.append($cell);
} }
} }
...@@ -253,7 +246,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -253,7 +246,7 @@ Array2DTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
}, },
colorClass: { colorClass: {
selected: 'selected', selected: 'selected',
notifying: 'notifying' notified: 'notified'
} }
}); });
......
...@@ -47,12 +47,15 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype), ...@@ -47,12 +47,15 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
}, },
_setTreeData: function (G, root) { _setTreeData: function (G, root) {
tm.pushStep(this.capsule, {type: 'setTreeData', arguments: arguments}); tm.pushStep(this.capsule, {type: 'setTreeData', arguments: arguments});
return this;
}, },
_visit: function (target, source) { _visit: function (target, source) {
tm.pushStep(this.capsule, {type: 'visit', target: target, source: source}); tm.pushStep(this.capsule, {type: 'visit', target: target, source: source});
return this;
}, },
_leave: function (target, source) { _leave: function (target, source) {
tm.pushStep(this.capsule, {type: 'leave', target: target, source: source}); tm.pushStep(this.capsule, {type: 'leave', target: target, source: source});
return this;
}, },
processStep: function (step, options) { processStep: function (step, options) {
switch (step.type) { switch (step.type) {
...@@ -71,8 +74,11 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype), ...@@ -71,8 +74,11 @@ DirectedGraphTracer.prototype = $.extend(true, Object.create(Tracer.prototype),
edge.color = color; edge.color = color;
this.graph.dropEdge(edgeId).addEdge(edge); this.graph.dropEdge(edgeId).addEdge(edge);
} }
var source = step.source; if (this.logTracer) {
if (source === undefined) source = ''; var source = step.source;
if (source === undefined) source = '';
this.logTracer.print(visit ? source + ' -> ' + step.target : source + ' <- ' + step.target);
}
break; break;
default: default:
Tracer.prototype.processStep.call(this, step, options); Tracer.prototype.processStep.call(this, step, options);
......
...@@ -14,11 +14,12 @@ LogTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -14,11 +14,12 @@ LogTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
}, },
_print: function (msg, delay) { _print: function (msg, delay) {
tm.pushStep(this.capsule, {type: 'print', msg: msg}, delay); tm.pushStep(this.capsule, {type: 'print', msg: msg}, delay);
return this;
}, },
processStep: function (step, options) { processStep: function (step, options) {
switch (step.type) { switch (step.type) {
case 'print': case 'print':
this.printTrace(step.msg); this.print(step.msg);
break; break;
} }
}, },
...@@ -30,7 +31,7 @@ LogTracer.prototype = $.extend(true, Object.create(Tracer.prototype), { ...@@ -30,7 +31,7 @@ LogTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
this.$wrapper.empty(); this.$wrapper.empty();
}, },
printTrace: function (message) { print: function (message) {
this.$wrapper.append($('<span>').append(message + '<br/>')); this.$wrapper.append($('<span>').append(message + '<br/>'));
}, },
scrollToEnd: function (duration) { scrollToEnd: function (duration) {
......
...@@ -14,19 +14,23 @@ Tracer.prototype = { ...@@ -14,19 +14,23 @@ Tracer.prototype = {
init: function () { init: function () {
this.$container.append($('<span class="name">').text(this.name)); this.$container.append($('<span class="name">').text(this.name));
}, },
_setData: function () { _setData: function (a) {
tm.pushStep(this.capsule, {type: 'setData', arguments: arguments}); var args = Array.prototype.slice.call(arguments);
tm.pushStep(this.capsule, {type: 'setData', args: toJSON(args)});
return this;
}, },
_clear: function () { _clear: function () {
tm.pushStep(this.capsule, {type: 'clear'}); tm.pushStep(this.capsule, {type: 'clear'});
return this;
}, },
_next: function () { _next: function () {
tm.newStep(); tm.newStep();
return this;
}, },
processStep: function (step, options) { processStep: function (step, options) {
switch (step.type) { switch (step.type) {
case 'setData': case 'setData':
this.setData.apply(this, step.arguments); this.setData.apply(this, fromJSON(step.args));
break; break;
case 'clear': case 'clear':
this.clear(); this.clear();
...@@ -34,7 +38,7 @@ Tracer.prototype = { ...@@ -34,7 +38,7 @@ Tracer.prototype = {
} }
}, },
setData: function () { setData: function () {
var data = JSON.stringify(arguments); var data = toJSON(arguments);
if (!this.new && this.lastData == data) return true; if (!this.new && this.lastData == data) return true;
this.new = this.capsule.new = false; this.new = this.capsule.new = false;
this.lastData = this.capsule.lastData = data; this.lastData = this.capsule.lastData = data;
...@@ -46,6 +50,12 @@ Tracer.prototype = { ...@@ -46,6 +50,12 @@ Tracer.prototype = {
}, },
clear: function () { clear: function () {
}, },
attach: function (tracer) {
if (tracer.module == LogTracer) {
this.logTracer = tracer;
}
return this;
},
mousedown: function (e) { mousedown: function (e) {
}, },
mousemove: function (e) { mousemove: function (e) {
......
...@@ -41,7 +41,6 @@ TracerManager.prototype = { ...@@ -41,7 +41,6 @@ TracerManager.prototype = {
count++; count++;
selectedCapsule = this.add(newTracer); selectedCapsule = this.add(newTracer);
} }
console.log(newTracer);
selectedCapsule.name = newTracer.constructor.name + count; selectedCapsule.name = newTracer.constructor.name + count;
return selectedCapsule; return selectedCapsule;
}, },
......
...@@ -31,18 +31,21 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra ...@@ -31,18 +31,21 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
}, },
_weight: function (target, weight, delay) { _weight: function (target, weight, delay) {
tm.pushStep(this.capsule, {type: 'weight', target: target, weight: weight}, delay); tm.pushStep(this.capsule, {type: 'weight', target: target, weight: weight}, delay);
return this;
}, },
_visit: function (target, source, weight) { _visit: function (target, source, weight) {
tm.pushStep(this.capsule, {type: 'visit', target: target, source: source, weight: weight}); tm.pushStep(this.capsule, {type: 'visit', target: target, source: source, weight: weight});
return this;
}, },
_leave: function (target, source, weight) { _leave: function (target, source, weight) {
tm.pushStep(this.capsule, {type: 'leave', target: target, source: source, weight: weight}); tm.pushStep(this.capsule, {type: 'leave', target: target, source: source, weight: weight});
return this;
}, },
processStep: function (step, options) { processStep: function (step, options) {
switch (step.type) { switch (step.type) {
case 'weight': case 'weight':
var targetNode = this.graph.nodes(this.n(step.target)); var targetNode = this.graph.nodes(this.n(step.target));
if (step.weight !== undefined) targetNode.weight = step.weight; if (step.weight !== undefined) targetNode.weight = refineNumber(step.weight);
break; break;
case 'visit': case 'visit':
case 'leave': case 'leave':
...@@ -50,15 +53,18 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra ...@@ -50,15 +53,18 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
var targetNode = this.graph.nodes(this.n(step.target)); var targetNode = this.graph.nodes(this.n(step.target));
var color = visit ? this.color.visited : this.color.left; var color = visit ? this.color.visited : this.color.left;
targetNode.color = color; targetNode.color = color;
if (step.weight !== undefined) targetNode.weight = step.weight; if (step.weight !== undefined) targetNode.weight = refineNumber(step.weight);
if (step.source !== undefined) { if (step.source !== undefined) {
var edgeId = this.e(step.source, step.target); var edgeId = this.e(step.source, step.target);
var edge = this.graph.edges(edgeId); var edge = this.graph.edges(edgeId);
edge.color = color; edge.color = color;
this.graph.dropEdge(edgeId).addEdge(edge); this.graph.dropEdge(edgeId).addEdge(edge);
} }
var source = step.source; if (this.logTracer) {
if (source === undefined) source = ''; var source = step.source;
if (source === undefined) source = '';
this.logTracer.print(visit ? source + ' -> ' + step.target : source + ' <- ' + step.target);
}
break; break;
default: default:
DirectedGraphTracer.prototype.processStep.call(this, step, options); DirectedGraphTracer.prototype.processStep.call(this, step, options);
...@@ -91,7 +97,7 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra ...@@ -91,7 +97,7 @@ WeightedDirectedGraphTracer.prototype = $.extend(true, Object.create(DirectedGra
target: this.n(j), target: this.n(j),
color: this.color.default, color: this.color.default,
size: 1, size: 1,
weight: G[i][j] weight: refineNumber(G[i][j])
}); });
} }
} }
......
...@@ -389,4 +389,20 @@ if (/[?&]scratch-paper=/.test(location.search)) { ...@@ -389,4 +389,20 @@ if (/[?&]scratch-paper=/.test(location.search)) {
var gistID = getParameterByName('scratch-paper'); var gistID = getParameterByName('scratch-paper');
console.log(gistID); console.log(gistID);
loadScratchPaper(gistID); loadScratchPaper(gistID);
} }
\ No newline at end of file
var toJSON = function (obj) {
return JSON.stringify(obj, function (key, value) {
return value === Infinity ? "Infinity" : value;
});
};
var fromJSON = function (obj) {
return JSON.parse(obj, function (key, value) {
return value === "Infinity" ? Infinity : value;
});
};
var 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.
先完成此消息的编辑!
想要评论请 注册