Skip to content

Commit 75ca194

Browse files
committed
Set up link to ListTracer from algorithm controller. Still non functional
1 parent 74fde46 commit 75ca194

File tree

7 files changed

+166
-142
lines changed

7 files changed

+166
-142
lines changed

.idea/workspace.xml

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import GraphTracer from '../../components/DataStructures/Graph/GraphTracer';
2-
import ArrayTracer from '../../components/DataStructures/Array/Array1DTracer';
1+
import ListTracer from '../../components/DataStructures/List/ListTracer.js';
32

43
export default {
54
initVisualisers() {
65
return {
7-
array: {
8-
instance: new ArrayTracer('array', null, 'Array view', { arrayItemMagnitudes: true }), // Label the input array as array view
6+
list: {
7+
instance: new ListTracer('array', null, 'List Prototype', { arrayItemMagnitudes: true }), // Label the input array as array view
98
order: 0,
10-
},
11-
heap: {
12-
instance: new GraphTracer('heap', null, 'Tree view'), // Label the animation of the heap as tree view
13-
order: 1,
14-
},
9+
}
1510
};
1611
},
12+
13+
run(chunker, {values}) {
14+
15+
chunker.add(
16+
0,
17+
(vis, list) => {
18+
vis.list.set(list, "Prototype");
19+
},
20+
[values]
21+
);
22+
}
1723
};

src/algorithms/controllers/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ export { default as DFSrec } from './DFSrec';
1919
export { default as prim_old } from './prim_old';
2020
export { default as prim } from './prim';
2121
export { default as kruskal } from './kruskal';
22-
2322
export { default as PROTOTYPE } from './Prototype';
2423

src/algorithms/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ const allalgs = {
311311
'LINKED_LIST_PROTOTYPE': {
312312
noDeploy: false,
313313
name: 'Linked List prototype',
314-
category: 'Insert/Search',
314+
category: 'Insert/Sort',
315315
explanation: Explanation.PROTOTYPE,
316316
param: <Param.PROTOTYPE_PARAM/>,
317317
instructions: Instructions.PROTOTYPEINSTRUCTION,
@@ -323,7 +323,6 @@ const allalgs = {
323323
Sort: Controller.PROTOTYPE,
324324
},
325325
},
326-
327326
};
328327

329328
const algorithms =
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
import React, { useState } from 'react';
22
import '../../styles/Param.scss';
3+
import ListParam from "./helpers/ListParam";
4+
import {genRandNumList} from "./helpers/ParamHelper";
5+
6+
const DEFAULT_LIST = genRandNumList(10, 1, 100);
7+
const PROTOTYPE_TEXT = 'Linked List Prototype';
8+
const EXAMPLE_TEXT = 'PARAMETER/example';
9+
310
function PrototypeParam() {
11+
12+
const [message, setMessage] = useState(null);
13+
const [values, setValues] = useState(DEFAULT_LIST);
14+
415
return (
516
<>
17+
<div className="form">
18+
<ListParam
19+
name="Linked List Prototype"
20+
buttonName="Sort"
21+
mode="sort"
22+
formClassName="formLeft"
23+
DEFAULT_VAL={values}
24+
SET_VAL={setValues}
25+
ALGORITHM_NAME={PROTOTYPE_TEXT}
26+
EXAMPLE={EXAMPLE_TEXT}
27+
setMessage={setMessage}
28+
/>
29+
</div>
630
</>
731
);
832
}
33+
934
export default PrototypeParam;

src/components/DataStructures/List/ListRenderer/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
/* eslint-disable object-curly-newline */
2121

2222
import React from 'react';
23-
// import Array1DRenderer from '../Array1DRenderer/index';
2423
import { motion, AnimateSharedLayout } from 'framer-motion';
2524
import ListRenderer from '../ListRenderer/index';
2625
import styles from './ListRenderer.module.scss';
Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* eslint-disable import/no-unresolved */
22

33
import Tracer from '../common/Tracer';
4-
import {Element} from "../Array/Array2DTracer";
5-
import {cloneDeepWith} from "lodash";
64

75
class ListTracer extends Tracer {
86
getRendererClass() {
@@ -11,137 +9,14 @@ class ListTracer extends Tracer {
119

1210
init() {
1311
super.init();
14-
this.dimensions = {
15-
baseWidth: 480,
16-
baseHeight: 480,
17-
padding: 32,
18-
arrowGap: 4,
19-
};
2012
}
2113
set(array1d = [], algo) {
22-
const array2d = [array1d];
23-
super.set(array2d, algo);
24-
this.syncChartTracer();
25-
}
26-
27-
// Patches/highlights an element
28-
patch(x, v) {
29-
super.patch(0, x, v);
30-
}
31-
32-
// Removes patch/highlight
33-
depatch(x) {
34-
super.depatch(0, x);
35-
}
36-
37-
// used to highlight sorted elements
38-
sorted(x) {
39-
super.sorted(0, x);
40-
}
41-
42-
select(sx, ex = sx) {
43-
super.select(0, sx, 0, ex);
44-
}
45-
46-
styledSelect(style, sx, ex = sx) {
47-
super.styledSelect(style, 0, sx, 0, ex);
48-
}
49-
50-
deselect(sx, ex = sx) {
51-
super.deselect(0, sx, 0, ex);
52-
}
53-
54-
fadeOut(sx, ex = sx) {
55-
super.fadeOut(0, sx, 0, ex);
56-
}
57-
58-
fadeIn(sx, ex = sx) {
59-
super.fadeIn(0, sx, 0, ex);
60-
}
61-
62-
chart(key) {
63-
this.chartTracer = key ? this.getObject(key) : null;
64-
this.syncChartTracer();
65-
}
14+
const array2d=array1d;
15+
super.set(array2d, algo);}
6616

6717
syncChartTracer() {
6818
if (this.chartTracer) this.chartTracer.data = this.data;
6919
}
20+
}
7021

71-
// Swaps two elements in 1D array
72-
swapElements(x, y) {
73-
const temp1 = { ...this.data[0][x], variables: this.data[0][y].variables };
74-
const temp2 = { ...this.data[0][y], variables: this.data[0][x].variables };
75-
this.data[0][x] = temp2;
76-
this.data[0][y] = temp1;
77-
}
78-
79-
// Adds variable to specific element in array
80-
addVariable(v, sx) {
81-
this.data[0][sx].variables.push(v);
82-
}
83-
84-
// Removes value from array
85-
removeVariable(v) {
86-
for (let y = 0; y < this.data[0].length; y++) {
87-
const newVars = this.data[0][y].variables.filter((val) => val !== v);
88-
this.data[0][y].variables = newVars;
89-
}
90-
}
91-
92-
// Remove all variables from array
93-
clearVariables() {
94-
for (let y = 0; y < this.data[0].length; y++) {
95-
this.data[0][y].variables = [];
96-
}
97-
}
98-
99-
// Removes "variable" from all elements in the array and assigns new "variable" to a specificed index
100-
assignVariable(v, idx) {
101-
// deep clone data so that changes to this.data are all made at the same time which will allow for tweening
102-
function customizer(val) {
103-
if (val instanceof Element) {
104-
const newEl = new Element(val.value, val.key);
105-
newEl.patched = val.patched;
106-
newEl.selected = val.selected;
107-
newEl.sorted = val.sorted;
108-
newEl.faded = val.faded;
109-
newEl.variables = val.variables;
110-
newEl.stack = val.stack;
111-
newEl.stackDepth = val.stackDepth;
112-
newEl.largestValue = val.largestValue;
113-
return newEl;
114-
}
115-
}
116-
const newData = cloneDeepWith(this.data, customizer);
117-
118-
// remove all current occurences of the variable
119-
for (let y = 0; y < newData[0].length; y++) {
120-
const newVars = newData[0][y].variables.filter((val) => val !== v);
121-
newData[0][y].variables = newVars;
122-
}
123-
124-
// add variable to item if not undefined or null
125-
if (idx !== null && idx !== undefined)
126-
newData[0][idx].variables.push(v);
127-
128-
// update this.data
129-
this.data = newData;
130-
}
131-
132-
setStack(val) {
133-
this.stack = val;
134-
}
135-
136-
setStackDepth(depth) {
137-
this.stackDepth = depth;
138-
}
139-
140-
// default is to compute largestColumnValue but we can set it
141-
// explicitly so we can make two arrays look the same when moving
142-
// elements between them and avoid re-scaling
143-
setLargestValue(val) {
144-
this.largestValue = val;
145-
}
146-
147-
}
22+
export default ListTracer

0 commit comments

Comments
 (0)