Moving through 0-length instruction delays automatically.

master
ben-burlingham 10 years ago
parent 18563eb6ec
commit 9bd76056b6
  1. 4
      js/quicksort.js
  2. 8
      js/visualizer-actions.js
  3. 6
      js/visualizer.js

@ -35,10 +35,10 @@ QuickSort.prototype.sort = function(arr, start, end) {
this//.instruct('initSection', left, right)
.instruct('showMarker', 0, 1)
.instruct('marker', 100, 1, left, 'L')
.instruct('marker', 0, 1, left, 'L')
.instruct('message', 0, 3, 'Left: ' + left)
.instruct('showMarker', 0, 2)
.instruct('marker', 100, 2, right, 'R')
.instruct('marker', 0, 2, right, 'R')
.instruct('message', 0, 4, 'Right: ' + right)
.instruct('unhighlight')
.instruct('highlight', 100, pivot)

@ -48,9 +48,10 @@ Visualizer.prototype.unhighlight = function() {
};
// TODO restart instructions on re-init
// TODO on 'next step', skip past all zero-length timeouts -> do this in followInstruction by checking if timeout is zero
// TODO add adaptive/stable bools below canvas
// TODO add tabs for best/worst cases
// TODO add links to stats
// TODO fade unfade
// TODO try to pass reference instead of string, use apply() or call()?
// /**
// * Greys out an item.
@ -99,6 +100,7 @@ Visualizer.prototype.showMarker = function(args) {
* Marker movement.
*/
Visualizer.prototype.marker = function(args) {
var delay = args[1];
var which = args[2];
var index = args[3];
var label = args[4];
@ -109,7 +111,7 @@ Visualizer.prototype.marker = function(args) {
}
this.svg.select(`#marker${which}`)
.transition().duration(100)
.transition().duration(delay)
.attr('transform', `translate(${Visualizer.calculateX(index)},${Visualizer.spacerW})`)
};

@ -90,7 +90,11 @@ Visualizer.prototype.followInstruction = function() {
if (typeof operation === 'function') {
operation.call(this, instruction);
if (this.paused === false) {
if (delay === 0) {
this.instructionIndex++;
this.followInstruction();
}
else if (this.paused === false) {
this.instructionIndex++;
setTimeout(this.followInstruction.bind(this), delay);
}

Loading…
Cancel
Save