Skip to content

Commit 1a176f0

Browse files
committed
fix some bugs
1 parent b590dfa commit 1a176f0

File tree

6 files changed

+98
-49
lines changed

6 files changed

+98
-49
lines changed

algorithm/etc/dp/fibonacci/code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
tracer._pace(300);
12
for (var i = 2; i < index; i++) {
23
D[i] = D[i - 2] + D[i - 1];
34
tracer._selectSet([i - 2, i - 1]);

css/stylesheet.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ pre {
234234
background: rgba(120, 0, 0, .8);
235235
}
236236

237+
.mtbl-wrapper {
238+
width: 100%;
239+
height: 100%;
240+
}
241+
237242
.mtbl-table {
238243
display: inline-table;
239244
color: white;

js/module/array2d.js

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ var $table = null;
33
function Array2DTracer(module) {
44
if (Tracer.call(this, module || Array2DTracer)) {
55
initTable();
6-
initNavigator(this);
76
return true;
87
}
98
return false;
@@ -44,12 +43,20 @@ Array2DTracer.prototype.createRandomData = function (N, M, min, max) {
4443
// Override
4544
Array2DTracer.prototype.setData = function (D) {
4645
this.D = D;
47-
if (Tracer.prototype.setData.call(this, arguments)) return true;
48-
4946
this.viewX = this.viewY = 0;
5047
this.paddingH = 6;
5148
this.paddingV = 3;
5249
this.fontSize = 16;
50+
51+
if (Tracer.prototype.setData.call(this, arguments)) {
52+
$('.mtbl-row').each(function (i) {
53+
$(this).children().each(function (j) {
54+
$(this).text(D[i][j]);
55+
});
56+
});
57+
return true;
58+
}
59+
5360
$table.empty();
5461
for (var i = 0; i < D.length; i++) {
5562
var $row = $('<div class="mtbl-row">');
@@ -167,8 +174,8 @@ Array2DTracer.prototype.processStep = function (step, options) {
167174

168175
Array2DTracer.prototype.getCellCss = function () {
169176
return {
170-
padding: this.paddingV + 'px ' + this.paddingH + 'px',
171-
'font-size': this.fontSize
177+
padding: this.paddingV.toFixed(1) + 'px ' + this.paddingH.toFixed(1) + 'px',
178+
'font-size': this.fontSize.toFixed(1) + 'px'
172179
};
173180
};
174181

@@ -198,48 +205,58 @@ Array2DTracer.prototype.prevStep = function () {
198205
this.step(finalIndex);
199206
};
200207

201-
var initTable = function () {
202-
$('.module_container').empty();
203-
$table = $('<div class="mtbl-table">');
204-
$('.module_container').append($table);
208+
// Override
209+
Array2DTracer.prototype.mousedown = function (e) {
210+
Tracer.prototype.mousedown.call(this, e);
211+
212+
this.dragX = e.pageX;
213+
this.dragY = e.pageY;
214+
this.dragging = true;
205215
};
206216

207-
var initNavigator = function (tracer) {
208-
var x, y, dragging = false;
209-
var $parent = $table.parent();
210-
$parent.mousedown(function (e) {
211-
x = e.pageX;
212-
y = e.pageY;
213-
dragging = true;
214-
});
215-
$parent.mousemove(function (e) {
216-
if (dragging) {
217-
tracer.viewX += e.pageX - x;
218-
tracer.viewY += e.pageY - y;
219-
x = e.pageX;
220-
y = e.pageY;
221-
tracer.refresh();
222-
}
223-
});
224-
$(document).mouseup(function (e) {
225-
dragging = false;
226-
});
227-
228-
$parent.bind('DOMMouseScroll mousewheel', function (e, delta) {
229-
e = e.originalEvent;
230-
var delta = (e.wheelDelta !== undefined && e.wheelDelta) ||
231-
(e.detail !== undefined && -e.detail);
232-
var weight = 1.01;
233-
var ratio = delta > 0 ? 1 / weight : weight;
234-
if (tracer.fontSize < 8 && ratio < 1) return false;
235-
if (tracer.fontSize > 36 && ratio > 1) return false;
236-
tracer.paddingV *= ratio;
237-
tracer.paddingH *= ratio;
238-
tracer.fontSize *= ratio;
239-
$('.mtbl-cell').css(tracer.getCellCss());
240-
tracer.refresh();
241-
e.preventDefault();
242-
});
217+
// Override
218+
Array2DTracer.prototype.mousemove = function (e) {
219+
Tracer.prototype.mousemove.call(this, e);
220+
221+
if (this.dragging) {
222+
this.viewX += e.pageX - this.dragX;
223+
this.viewY += e.pageY - this.dragY;
224+
this.dragX = e.pageX;
225+
this.dragY = e.pageY;
226+
this.refresh();
227+
}
228+
};
229+
230+
// Override
231+
Array2DTracer.prototype.mouseup = function (e) {
232+
Tracer.prototype.mouseup.call(this, e);
233+
234+
this.dragging = false;
235+
};
236+
237+
// Override
238+
Array2DTracer.prototype.mousewheel = function (e) {
239+
Tracer.prototype.mousewheel.call(this, e);
240+
241+
e.preventDefault();
242+
e = e.originalEvent;
243+
var delta = (e.wheelDelta !== undefined && e.wheelDelta) ||
244+
(e.detail !== undefined && -e.detail);
245+
var weight = 1.01;
246+
var ratio = delta > 0 ? 1 / weight : weight;
247+
if (this.fontSize < 4 && ratio < 1) return;
248+
if (this.fontSize > 40 && ratio > 1) return;
249+
this.paddingV *= ratio;
250+
this.paddingH *= ratio;
251+
this.fontSize *= ratio;
252+
$('.mtbl-cell').css(this.getCellCss());
253+
this.refresh();
254+
};
255+
256+
var initTable = function () {
257+
$module_container.empty();
258+
$table = $('<div class="mtbl-table">');
259+
$module_container.append($table);
243260
};
244261

245262
var paintColor = function (sx, sy, ex, ey, colorClass, addClass) {
@@ -254,7 +271,7 @@ var paintColor = function (sx, sy, ex, ey, colorClass, addClass) {
254271
};
255272

256273
var clearTableColor = function () {
257-
$table.find('.mtbl-cell').css('background', '');
274+
$table.find('.mtbl-cell').removeClass(Object.keys(tableColorClass).join(' '));
258275
};
259276

260277
var tableColorClass = {

js/module/graph.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ GraphTracer.prototype.prevStep = function () {
182182
};
183183

184184
var initGraph = function () {
185-
$('.module_container').empty();
185+
$module_container.empty();
186186
if (sigmaCanvas == null) {
187187
sigmaCanvas = $.extend(true, {}, sigma.canvas);
188188
} else {
189189
sigma.canvas = $.extend(true, {}, sigmaCanvas);
190190
}
191191
s = new sigma({
192192
renderer: {
193-
container: $('.module_container')[0],
193+
container: $module_container[0],
194194
type: 'canvas'
195195
},
196196
settings: {

js/script.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
$.ajaxSetup({cache: false, dataType: "text"});
22

3+
var $module_container = $('.module_container');
34
var _tracer = new Tracer();
45
var initEditor = function (id) {
56
var editor = ace.edit(id);
@@ -257,4 +258,17 @@ for (var i = 0; i < dividers.length; i++) {
257258

258259
$second.append($divider);
259260
})(divider);
260-
}
261+
}
262+
263+
$module_container.mousedown(function (e) {
264+
_tracer.mousedown(e);
265+
});
266+
$module_container.mousemove(function (e) {
267+
_tracer.mousemove(e);
268+
});
269+
$(document).mouseup(function (e) {
270+
_tracer.mouseup(e);
271+
});
272+
$module_container.bind('DOMMouseScroll mousewheel', function (e) {
273+
_tracer.mousewheel(e);
274+
});

js/tracer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@ Tracer.prototype.nextStep = function () {
141141
this.step(this.traceIndex + 1);
142142
};
143143

144+
Tracer.prototype.mousedown = function (e) {
145+
};
146+
147+
Tracer.prototype.mousemove = function (e) {
148+
};
149+
150+
Tracer.prototype.mouseup = function (e) {
151+
};
152+
153+
Tracer.prototype.mousewheel = function (e) {
154+
};
155+
144156
var printTrace = function (message) {
145157
$('#tab_trace .wrapper').append($('<span>').append(message + '<br/>'));
146158
};

0 commit comments

Comments
 (0)