Skip to content

Commit 8afdccd

Browse files
Commented what each renderer is responsible for
1 parent 354e7ab commit 8afdccd

File tree

5 files changed

+55
-38
lines changed

5 files changed

+55
-38
lines changed

src/components/DataStructures/Array/Array1DTracer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// used to display one array in the form of a single bar chart, such as
2+
// Binary Search Tree
3+
// Heap Sort
4+
// Merge Sort
5+
// Quick Sort
6+
17
/* eslint-disable class-methods-use-this */
28
/* eslint-disable consistent-return */
39
/* eslint-disable no-plusplus */

src/components/DataStructures/Array/Array2DTracer.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// used to display graphs, such as in the case of:
2+
// A*
3+
// Breadth First Search
4+
// Depth First Search
5+
// Dijkstra's
6+
// Kruskal
7+
// Prim
8+
// Warshall
9+
// Union Find
10+
11+
// Or tables, such as in the case of:
12+
// Horspool's
13+
// Merge Sort List
14+
// Union find
15+
116
/* eslint-disable no-plusplus */
217
/* eslint-disable class-methods-use-this */
318
/* eslint-disable max-classes-per-file */
@@ -167,7 +182,7 @@ class Array2DTracer extends Tracer {
167182

168183
// add variable to item if not undefined or null
169184
if (idx !== null && idx !== undefined)
170-
newData[row][idx].variables.push(v);
185+
newData[row][idx].variables.push(v);
171186

172187
// update this.data
173188
this.data = newData;

src/components/DataStructures/Array/TwoArray1DTracer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable class-methods-use-this */
22

3-
/* draw two arrays in the same box */
3+
/* draw two arrays in the same box (currently unused) */
44

55
import Array2DTracer from './Array2DTracer';
66
import Array1DRenderer from './Array1DRenderer/index';

src/components/DataStructures/Array/TwoArray2DTracer.js

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Only seems to be used for Horspool's algorithm
2+
13
/* eslint-disable no-plusplus */
24
/* eslint-disable class-methods-use-this */
35
/* eslint-disable max-classes-per-file */
@@ -41,89 +43,81 @@ class TwoArray2DTracer extends Tracer {
4143
* @param {array} array2d
4244
* @param {string} algo used to mark if it is a specific algorithm
4345
*/
44-
set(array2d = [],array2d1=[], algo) {
46+
set(array2d = [], array2d1 = [], algo) {
4547
this.data = array2d.map(array1d => [...array1d].map(value => new Element(value)));
4648
this.data1 = array2d1.map(array1d => [...array1d].map(value => new Element(value)));
4749
this.algo = algo;
4850
super.set();
4951
}
5052

51-
getposition(x,y){
53+
getposition(x, y) {
5254
let longestRow = this.data.reduce((longestRow, row) => longestRow.length < row.length ? row : longestRow, []);
5355
let len = longestRow.length;
54-
var xx=x;
55-
var pos=0;
56-
if (x>=len){xx=x-len;pos=1;}
57-
return [pos,xx,y];
56+
var xx = x;
57+
var pos = 0;
58+
if (x >= len) { xx = x - len; pos = 1; }
59+
return [pos, xx, y];
5860
}
5961

6062
patch(x, y, v = this.data[x][y].value) {
61-
let rr=this.getposition(x,y);
62-
var pos=rr[0];
63+
let rr = this.getposition(x, y);
64+
var pos = rr[0];
6365
var xx = rr[2];//x is actually the vertical one
6466
var yy = rr[1];
65-
if (pos===0)
66-
{
67-
if (!this.data[xx][yy]) {this.data[xx][yy] = new Element();}
67+
if (pos === 0) {
68+
if (!this.data[xx][yy]) { this.data[xx][yy] = new Element(); }
6869
this.data[xx][yy].value = v;
6970
this.data[xx][yy].patched = true;
7071
}
71-
else
72-
{
73-
if (!this.data1[xx][yy]) {this.data1[xx][yy] = new Element();}
72+
else {
73+
if (!this.data1[xx][yy]) { this.data1[xx][yy] = new Element(); }
7474
this.data1[xx][yy].value = v;
7575
this.data1[xx][yy].patched = true;
7676
}
7777

7878
}
7979

8080
depatch(x, y) {
81-
let rr=this.getposition(x,y);
82-
var pos=rr[0];
81+
let rr = this.getposition(x, y);
82+
var pos = rr[0];
8383
var xx = rr[2];//x is actually the vertical one
8484
var yy = rr[1];
85-
if (pos===0)
86-
{
87-
if (!this.data[xx][yy]) {this.data[xx][yy] = new Element();}
85+
if (pos === 0) {
86+
if (!this.data[xx][yy]) { this.data[xx][yy] = new Element(); }
8887

8988
this.data[xx][yy].patched = false;
9089
}
91-
else
92-
{
93-
if (!this.data1[xx][yy]) {this.data1[xx][yy] = new Element();}
90+
else {
91+
if (!this.data1[xx][yy]) { this.data1[xx][yy] = new Element(); }
9492

9593
this.data1[xx][yy].patched = false;
9694
}
9795
}
9896
select(x, y) {
99-
let rr=this.getposition(x,y);
100-
var pos=rr[0];
97+
let rr = this.getposition(x, y);
98+
var pos = rr[0];
10199
var xx = rr[2];//x is actually the vertical one
102100
var yy = rr[1];
103-
if (pos===0)
104-
{
105-
if (!this.data[xx][yy]) {this.data[xx][yy] = new Element();}
101+
if (pos === 0) {
102+
if (!this.data[xx][yy]) { this.data[xx][yy] = new Element(); }
106103
this.data[xx][yy].selected = true;
107104
}
108-
else
109-
{
110-
if (!this.data1[xx][yy]) {this.data1[xx][yy] = new Element();}
105+
else {
106+
if (!this.data1[xx][yy]) { this.data1[xx][yy] = new Element(); }
111107
this.data1[xx][yy].selected = true;
112108
}
113109

114110
}
115111

116112
deselect(x, y) {
117-
let rr=this.getposition(x,y);
118-
var pos=rr[0];
113+
let rr = this.getposition(x, y);
114+
var pos = rr[0];
119115
var xx = rr[2];//x is actually the vertical one
120116
var yy = rr[1];
121-
if (pos===0)
122-
{
117+
if (pos === 0) {
123118
this.data[xx][yy].selected = false;
124119
}
125-
else
126-
{
120+
else {
127121
this.data1[xx][yy].selected = false;
128122
}
129123

src/components/DataStructures/ArrayGraph/ArrayGraphTracer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This file, along with everythin in ArrayGraphRenderer, seems to be completely unused at the moment
2+
13
/* eslint-disable max-classes-per-file */
24
/* eslint-disable no-prototype-builtins */
35
/* eslint-disable class-methods-use-this */

0 commit comments

Comments
 (0)