Skip to content

Commit fda7061

Browse files
committed
minor change in TracerManager
1 parent fec3dbd commit fda7061

File tree

5 files changed

+43
-25
lines changed

5 files changed

+43
-25
lines changed

js/tracer_manager/manager.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ TracerManager.prototype = {
164164
step(i, options = {}) {
165165
const tracer = this;
166166

167-
if (isNaN(i) || i >= this.traces.length || i < 0) {
168-
$('#btn_run').removeClass('active');
169-
return;
170-
}
167+
if (isNaN(i) || i >= this.traces.length || i < 0) return;
171168

172169
this.traceIndex = i;
173170
const trace = this.traces[i];
@@ -182,31 +179,41 @@ TracerManager.prototype = {
182179
if (this.pause) return;
183180

184181
this.timer = setTimeout(() => {
185-
tracer.step(i + 1, options);
182+
if (!tracer.nextStep(options)) {
183+
$('#btn_run').removeClass('active');
184+
}
186185
}, this.interval);
187186
},
188187

189-
prevStep() {
188+
prevStep(options = {}) {
190189
this.command('clear');
191190

192191
const finalIndex = this.traceIndex - 1;
193192
if (finalIndex < 0) {
194193
this.traceIndex = -1;
195194
this.command('refresh');
196-
return;
195+
return false;
197196
}
198197

199198
for (let i = 0; i < finalIndex; i++) {
200-
this.step(i, {
199+
this.step(i, $.extend(options, {
201200
virtual: true
202-
});
201+
}));
203202
}
204203

205204
this.step(finalIndex);
205+
return true;
206206
},
207207

208-
nextStep() {
209-
this.step(this.traceIndex + 1);
208+
nextStep(options = {}) {
209+
const finalIndex = this.traceIndex + 1;
210+
if (finalIndex >= this.traces.length) {
211+
this.traceIndex = this.traces.length - 1;
212+
return false;
213+
}
214+
215+
this.step(finalIndex, options);
216+
return true;
210217
},
211218

212219
visualize() {

public/algorithm_visualizer.js

Lines changed: 21 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/algorithm_visualizer.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)