|
|
|
@ -13,6 +13,14 @@ Visualizer.prototype.initItems = function(n) { |
|
|
|
|
shuffled[i].index = n++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.svg !== undefined) { |
|
|
|
|
this.svg.remove(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.instructionIndex = 0; |
|
|
|
|
this.svg = d3.select(this.parent).append('svg') |
|
|
|
|
.attr('class', 'sorter-svg'); |
|
|
|
|
|
|
|
|
|
// Items
|
|
|
|
|
this.groups = this.svg.selectAll('g').data(shuffled).enter().insert('g') |
|
|
|
|
.attr('transform', `translate(0, ${Visualizer.itemY})`); |
|
|
|
@ -25,7 +33,7 @@ Visualizer.prototype.initItems = function(n) { |
|
|
|
|
|
|
|
|
|
this.groups.transition(500) |
|
|
|
|
.attr('transform', function doTransform(d, i) { |
|
|
|
|
return `translate(${i * (Visualizer.itemW + Visualizer.spacerW)}, ${Visualizer.itemY})`; |
|
|
|
|
return `translate(${i * (Visualizer.itemW + Visualizer.spacerW) + Visualizer.spacerW}, ${Visualizer.itemY})`; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Item labels
|
|
|
|
@ -41,7 +49,8 @@ Visualizer.prototype.initItems = function(n) { |
|
|
|
|
// Markers
|
|
|
|
|
var m1 = this.svg.append('g') |
|
|
|
|
.attr('class', 'marker') |
|
|
|
|
.attr('id', 'marker1'); |
|
|
|
|
.attr('id', 'marker1') |
|
|
|
|
.attr('transform', `translate(${Visualizer.spacerW}, ${Visualizer.spacerW})`); |
|
|
|
|
|
|
|
|
|
m1.append('rect') |
|
|
|
|
.attr('height', Visualizer.itemW) |
|
|
|
@ -53,10 +62,9 @@ Visualizer.prototype.initItems = function(n) { |
|
|
|
|
.attr('y', 10); |
|
|
|
|
|
|
|
|
|
var m2 = this.svg.append('g') |
|
|
|
|
//temp
|
|
|
|
|
.attr('transform', 'translate(19,0)') |
|
|
|
|
//temp
|
|
|
|
|
.attr('transform', `translate(${Visualizer.spacerW}, ${Visualizer.spacerW})`) |
|
|
|
|
.attr('class', 'marker') |
|
|
|
|
.attr('style', 'display:none') |
|
|
|
|
.attr('id', 'marker2'); |
|
|
|
|
|
|
|
|
|
m2.append('rect') |
|
|
|
@ -67,8 +75,6 @@ Visualizer.prototype.initItems = function(n) { |
|
|
|
|
.attr('text-anchor', 'middle') |
|
|
|
|
.attr('x', (Visualizer.itemW / 2)) |
|
|
|
|
.attr('y', 10); |
|
|
|
|
|
|
|
|
|
setTimeout(this.followInstruction.bind(this, 0), 500); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -87,9 +93,25 @@ Visualizer.prototype.initMessages = function() { |
|
|
|
|
var div3 = document.createElement('div'); |
|
|
|
|
div3.className = 'message'; |
|
|
|
|
|
|
|
|
|
var div4 = document.createElement('div'); |
|
|
|
|
div4.className = 'message'; |
|
|
|
|
div4.innerHTML = 'Comparisons: 0'; |
|
|
|
|
|
|
|
|
|
var div5 = document.createElement('div'); |
|
|
|
|
div5.className = 'message'; |
|
|
|
|
div5.innerHTML = 'Swaps: 0'; |
|
|
|
|
|
|
|
|
|
div1.innerHTML = 'testing'; |
|
|
|
|
div2.innerHTML = 'testing'; |
|
|
|
|
div3.innerHTML = 'testing'; |
|
|
|
|
div4.innerHTML = 'testing'; |
|
|
|
|
div5.innerHTML = 'testing'; |
|
|
|
|
|
|
|
|
|
container.appendChild(div1); |
|
|
|
|
container.appendChild(div2); |
|
|
|
|
container.appendChild(div3); |
|
|
|
|
container.appendChild(div4); |
|
|
|
|
container.appendChild(div5); |
|
|
|
|
|
|
|
|
|
return container; |
|
|
|
|
}; |
|
|
|
@ -106,7 +128,6 @@ Visualizer.prototype.initRange = function() { |
|
|
|
|
this.initItems(event.target.value); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var container = document.createElement('div'); |
|
|
|
|
container.className = 'range-container'; |
|
|
|
|
|
|
|
|
@ -118,7 +139,7 @@ Visualizer.prototype.initRange = function() { |
|
|
|
|
range.setAttribute('type', 'range'); |
|
|
|
|
range.setAttribute('value', 10); |
|
|
|
|
range.setAttribute('min', 10); |
|
|
|
|
range.setAttribute('max', 80); |
|
|
|
|
range.setAttribute('max', 40); |
|
|
|
|
range.addEventListener('change', rangeChange.bind(this)); |
|
|
|
|
range.addEventListener('input', rangeInput.bind(null, msg)); |
|
|
|
|
|
|
|
|
@ -144,23 +165,26 @@ Visualizer.prototype.initControls = function() { |
|
|
|
|
var playclick = function() { |
|
|
|
|
this.paused = !this.paused; |
|
|
|
|
updatePlayPause(this.paused); |
|
|
|
|
this.followInstruction(this.instruction + 1); |
|
|
|
|
this.followInstruction(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var backclick = function() { |
|
|
|
|
this.paused = true; |
|
|
|
|
this.followInstruction(this.instruction - 1); |
|
|
|
|
this.instructionIndex--; |
|
|
|
|
this.followInstruction(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var forwardclick = function() { |
|
|
|
|
this.paused = true; |
|
|
|
|
this.followInstruction(this.instruction + 1); |
|
|
|
|
this.followInstruction(); |
|
|
|
|
this.instructionIndex++; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var restartclick = function() { |
|
|
|
|
this.paused = false; |
|
|
|
|
updatePlayPause(this.paused); |
|
|
|
|
this.followInstruction(0); |
|
|
|
|
this.instructionIndex = 0; |
|
|
|
|
this.followInstruction(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var play = document.createElement('button'); |
|
|
|
@ -183,14 +207,6 @@ Visualizer.prototype.initControls = function() { |
|
|
|
|
reset.title = 'Restart' |
|
|
|
|
reset.addEventListener('click', restartclick.bind(this)); |
|
|
|
|
|
|
|
|
|
var stat1 = document.createElement('div'); |
|
|
|
|
stat1.className = 'stat'; |
|
|
|
|
stat1.innerHTML = 'Comparisons: 999'; |
|
|
|
|
|
|
|
|
|
var stat2 = document.createElement('div'); |
|
|
|
|
stat2.className = 'stat'; |
|
|
|
|
stat2.innerHTML = 'Swaps: 999'; |
|
|
|
|
|
|
|
|
|
var container = document.createElement('div'); |
|
|
|
|
container.className = 'controls-container'; |
|
|
|
|
|
|
|
|
@ -198,8 +214,105 @@ Visualizer.prototype.initControls = function() { |
|
|
|
|
container.appendChild(back); |
|
|
|
|
container.appendChild(play); |
|
|
|
|
container.appendChild(forward); |
|
|
|
|
container.appendChild(stat1); |
|
|
|
|
container.appendChild(stat2); |
|
|
|
|
|
|
|
|
|
return container; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
Visualizer.prototype.initProperties = function() { |
|
|
|
|
// Div 1
|
|
|
|
|
var div1 = document.createElement('div'); |
|
|
|
|
div1.className = 'property p1'; |
|
|
|
|
|
|
|
|
|
var title1 = document.createElement('div'); |
|
|
|
|
title1.innerHTML = 'Stable'; |
|
|
|
|
title1.className = 'title'; |
|
|
|
|
div1.appendChild(title1); |
|
|
|
|
|
|
|
|
|
var value1 = document.createElement('div'); |
|
|
|
|
value1.className = 'value'; |
|
|
|
|
value1.innerHTML = this.parent.attributes['data-stable'].value; |
|
|
|
|
div1.appendChild(value1); |
|
|
|
|
|
|
|
|
|
// Div 2
|
|
|
|
|
var div2 = document.createElement('div'); |
|
|
|
|
div2.className = 'property p2'; |
|
|
|
|
|
|
|
|
|
var title2 = document.createElement('div'); |
|
|
|
|
title2.innerHTML = 'Adaptive'; |
|
|
|
|
title2.className = 'title'; |
|
|
|
|
div2.appendChild(title2); |
|
|
|
|
|
|
|
|
|
var value2 = document.createElement('div'); |
|
|
|
|
value2.className = 'value'; |
|
|
|
|
value2.innerHTML = this.parent.attributes['data-adaptive'].value; |
|
|
|
|
div2.appendChild(value2); |
|
|
|
|
|
|
|
|
|
// Div 3
|
|
|
|
|
var div3 = document.createElement('div'); |
|
|
|
|
div3.className = 'property p3'; |
|
|
|
|
|
|
|
|
|
var title3 = document.createElement('div'); |
|
|
|
|
title3.innerHTML = 'Worst Performance'; |
|
|
|
|
title3.className = 'title'; |
|
|
|
|
div3.appendChild(title3); |
|
|
|
|
|
|
|
|
|
var value3 = document.createElement('div'); |
|
|
|
|
value3.className = 'value'; |
|
|
|
|
value3.innerHTML = this.parent.attributes['data-worst-perf'].value; |
|
|
|
|
div3.appendChild(value3); |
|
|
|
|
|
|
|
|
|
// Div 4
|
|
|
|
|
var div4 = document.createElement('div'); |
|
|
|
|
div4.className = 'property p4'; |
|
|
|
|
|
|
|
|
|
var title4 = document.createElement('div'); |
|
|
|
|
title4.innerHTML = 'Average Performance'; |
|
|
|
|
title4.className = 'title'; |
|
|
|
|
div4.appendChild(title4); |
|
|
|
|
|
|
|
|
|
var value4 = document.createElement('div'); |
|
|
|
|
value4.className = 'value'; |
|
|
|
|
value4.innerHTML = this.parent.attributes['data-avg-perf'].value; |
|
|
|
|
div4.appendChild(value4); |
|
|
|
|
|
|
|
|
|
// Div 5
|
|
|
|
|
var div5 = document.createElement('div'); |
|
|
|
|
div5.className = 'property p5'; |
|
|
|
|
|
|
|
|
|
var title5 = document.createElement('div'); |
|
|
|
|
title5.innerHTML = 'Best Performance'; |
|
|
|
|
title5.className = 'title'; |
|
|
|
|
div5.appendChild(title5); |
|
|
|
|
|
|
|
|
|
var value5 = document.createElement('div'); |
|
|
|
|
value5.className = 'value'; |
|
|
|
|
value5.innerHTML = this.parent.attributes['data-best-perf'].value; |
|
|
|
|
div5.appendChild(value5); |
|
|
|
|
|
|
|
|
|
// Div 6
|
|
|
|
|
var div6 = document.createElement('div'); |
|
|
|
|
div6.className = 'property p6'; |
|
|
|
|
|
|
|
|
|
var title6 = document.createElement('div'); |
|
|
|
|
title6.innerHTML = 'Worst Memory'; |
|
|
|
|
title6.className = 'title'; |
|
|
|
|
div6.appendChild(title6); |
|
|
|
|
|
|
|
|
|
var value6 = document.createElement('div'); |
|
|
|
|
value6.className = 'value'; |
|
|
|
|
value6.innerHTML = this.parent.attributes['data-worst-memory'].value; |
|
|
|
|
div6.appendChild(value6); |
|
|
|
|
|
|
|
|
|
// Container
|
|
|
|
|
var container = document.createElement('div'); |
|
|
|
|
container.className = 'sorter-properties'; |
|
|
|
|
|
|
|
|
|
container.appendChild(div1); |
|
|
|
|
container.appendChild(div2); |
|
|
|
|
container.appendChild(div3); |
|
|
|
|
container.appendChild(div4); |
|
|
|
|
container.appendChild(div5); |
|
|
|
|
container.appendChild(div6); |
|
|
|
|
|
|
|
|
|
return container; |
|
|
|
|
}; |
|
|
|
|