Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier refactoring #248

Merged
merged 3 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
"sourceType": "module",
"requireConfigFile": false,
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"env": {
"browser": true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ yarn-error.log*

# my notes for how to contribute from the bluejeans meeting
contrib.txt
.eslintrc
32 changes: 21 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,52 @@ import './css/App.css';
import React, { useEffect, useState } from 'react';
import { Route, BrowserRouter as Router, Switch } from 'react-router-dom';
import AlgoScreen from './screens/AlgoScreen';
import Cookies from 'js-cookie'
import Cookies from 'js-cookie';
import HomeScreen from './screens/HomeScreen';
import ReactGA from 'react-ga4';

const App = () => {
ReactGA.initialize('G-0ERQ9E89XM');
ReactGA.send({ hitType: "pageview", page: "home" });
ReactGA.send({ hitType: 'pageview', page: 'home' });

const [loading, setLoading] = useState(true);
const [theme, setTheme] = useState('light');

useEffect(() => {
const storedTheme = Cookies.get('theme');
if (storedTheme) {
setTheme(storedTheme);
document.body.setAttribute('data-theme', storedTheme);
setTheme(storedTheme);
document.body.setAttribute('data-theme', storedTheme);
}
setLoading(false);
}, []);

const toggleTheme = () => {
const newTheme = theme === 'light' ? 'dark' : 'light';
setTheme(newTheme);
Cookies.set('theme', newTheme);
document.body.setAttribute('data-theme', newTheme);
}
setTheme(newTheme);
Cookies.set('theme', newTheme);
document.body.setAttribute('data-theme', newTheme);
};

if (loading) {
return <div>.</div>
return <div>.</div>;
}

return (
<Router basename={process.env.PUBLIC_URL + '/'}>
<Switch>
<Route exact path={['/', '/about']} render={(props) => <HomeScreen {...props} theme={theme} toggleTheme={toggleTheme} />} />
<Route render={(props) => <AlgoScreen {...props} theme={theme} toggleTheme={toggleTheme} />} />
<Route
exact
path={['/', '/about']}
render={props => (
<HomeScreen {...props} theme={theme} toggleTheme={toggleTheme} />
)}
/>
<Route
render={props => (
<AlgoScreen {...props} theme={theme} toggleTheme={toggleTheme} />
)}
/>
</Switch>
</Router>
);
Expand Down
2 changes: 1 addition & 1 deletion src/algo/AVL.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ AVL.HIGHLIGHT_COLOR = '#007700';
AVL.HEIGHT_LABEL_COLOR = '#000000';

AVL.LINK_COLOR = '#000000';
AVL.LINK_OPACITY = 0.20;
AVL.LINK_OPACITY = 0.2;
AVL.HIGHLIGHT_CIRCLE_COLOR = '#007700';
AVL.FOREGROUND_COLOR = '#000000';
AVL.BACKGROUND_COLOR = '#FFFFFF';
Expand Down
14 changes: 7 additions & 7 deletions src/algo/Algorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ export function addCheckboxToAlgorithmBar(boxLabel, checked, group) {
}

export function addDropDownGroupToAlgorithmBar(optionNames, groupName, group) {
const dropDown = document.createElement("select");
const dropDown = document.createElement('select');
dropDown.name = groupName;
for (let i = 0; i < optionNames.length; i++) {
const option = document.createElement("option");
option.text = optionNames[i];
const option = document.createElement('option');
option.text = optionNames[i];
dropDown.add(option);
}

Expand Down Expand Up @@ -373,13 +373,13 @@ export default class Algorithm {

export function controlKey(keyASCII) {
return (
keyASCII === 8 || // backspace
keyASCII === 9 || // tab
keyASCII === 37 || // % percent
keyASCII === 8 || // backspace
keyASCII === 9 || // tab
keyASCII === 37 || // % percent
keyASCII === 38 || // & ampersand
keyASCII === 39 || // ' apostrophe
keyASCII === 40 || // ( left parenthesis
keyASCII === 46 // . period
keyASCII === 46 // . period
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/algo/BTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,11 @@ export default class BTree extends Algorithm {
}

split(tree) {
this.cmd(act.setText, this.messageID, 'Node now contains too many elements. Splitting ...');
this.cmd(
act.setText,
this.messageID,
'Node now contains too many elements. Splitting ...',
);
this.cmd(act.setHighlight, tree.graphicID, 1);
this.cmd(act.step);
this.cmd(act.setHighlight, tree.graphicID, 0);
Expand Down
8 changes: 1 addition & 7 deletions src/algo/BoyerMoore.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,7 @@ export default class BoyerMoore extends Algorithm {
const xpos = i * this.cellSize + ARRAY_START_X;
const ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
this.cmd(act.createLabel, this.nextIndex++, i, xpos, ypos);
}

for (let i = 0; i < text.length; i++) {
Expand Down
8 changes: 1 addition & 7 deletions src/algo/BruteForce.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,7 @@ export default class BruteForce extends Algorithm {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
this.cmd(act.createLabel, this.nextIndex++, i, xpos, ypos);
}

for (let i = 0; i < text.length; i++) {
Expand Down
8 changes: 2 additions & 6 deletions src/algo/BubbleSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class BubbleSort extends Algorithm {
'Swap Count: ' + this.swapCount,
COMP_COUNT_X + 250,
COMP_COUNT_Y,
)
);

this.code = [
['procedure BubbleSort(array):'],
Expand Down Expand Up @@ -373,11 +373,7 @@ export default class BubbleSort extends Algorithm {
// Move labels
this.cmd(act.move, iLabelID, jXPos, ARRAY_START_Y);
this.cmd(act.move, jLabelID, iXPos, ARRAY_START_Y);
this.cmd(
act.setText,
this.swapCountID,
'Swap Count: ' + ++this.swapCount,
);
this.cmd(act.setText, this.swapCountID, 'Swap Count: ' + ++this.swapCount);
this.cmd(act.step);
// Set text in array and delete temporary labels
this.cmd(act.setText, this.arrayID[i], this.displayData[j]);
Expand Down
6 changes: 1 addition & 5 deletions src/algo/CocktailSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,7 @@ export default class CocktailSort extends Algorithm {
this.cmd(act.setText, this.arrayID[j], '');
this.cmd(act.move, iLabelID, jXPos, jYPos);
this.cmd(act.move, jLabelID, iXPos, iYPos);
this.cmd(
act.setText,
this.swapCountID,
'Swap Count: ' + ++this.swapCount,
);
this.cmd(act.setText, this.swapCountID, 'Swap Count: ' + ++this.swapCount);
this.cmd(act.step);
this.cmd(act.setText, this.arrayID[i], this.displayData[j]);
this.cmd(act.setText, this.arrayID[j], this.displayData[i]);
Expand Down
18 changes: 16 additions & 2 deletions src/algo/DFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,23 @@ export default class DFS extends Graph {
];

if (this.physicalStack) {
this.codeID = this.addCodeToCanvasBase(this.itCode, CODE_START_X, CODE_START_Y, undefined, undefined, 1);
this.codeID = this.addCodeToCanvasBase(
this.itCode,
CODE_START_X,
CODE_START_Y,
undefined,
undefined,
1,
);
} else {
this.codeID = this.addCodeToCanvasBase(this.recCode, CODE_START_X, CODE_START_Y, undefined, undefined, 1);
this.codeID = this.addCodeToCanvasBase(
this.recCode,
CODE_START_X,
CODE_START_Y,
undefined,
undefined,
1,
);
}

this.animationManager.setAllLayers([0, this.currentLayer]);
Expand Down
9 changes: 8 additions & 1 deletion src/algo/Dijkstras.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ export default class Dijkstras extends Graph {
[' PQ.enqueue((w, d1 + d2))'],
];

this.codeID = this.addCodeToCanvasBase(this.code, CODE_START_X, CODE_START_Y, undefined, undefined, 1);
this.codeID = this.addCodeToCanvasBase(
this.code,
CODE_START_X,
CODE_START_Y,
undefined,
undefined,
1,
);

this.tableEntryHeight = this.isLarge ? LARGE_TABLE_ENTRY_HEIGHT : SMALL_TABLE_ENTRY_HEIGHT;
for (let i = 0; i < this.size; i++) {
Expand Down
30 changes: 14 additions & 16 deletions src/algo/Hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,14 @@ export default class Hash extends Algorithm {
this.dropDownGroup = addGroupToAlgorithmBar(false);

this.hashTypeDropDown = addDropDownGroupToAlgorithmBar(
[
'Hash Integers',
'Hash Strings',
'True Hash Function'
],
['Hash Integers', 'Hash Strings', 'True Hash Function'],
'Hash Type',
this.dropDownGroup
this.dropDownGroup,
);

this.hashTypeDropDown.onchange = this.checkHashType.bind(this);

this.hashType = 'integers';

}

checkHashType() {
Expand All @@ -200,7 +195,7 @@ export default class Hash extends Algorithm {
} else if (this.hashTypeDropDown.value === 'Hash Strings') {
this.implementAction(this.changeHashType.bind(this), 'strings');
} else if (this.hashTypeDropDown.value === 'True Hash Function') {
this.implementAction(this.changeHashType.bind(this), 'true')
this.implementAction(this.changeHashType.bind(this), 'true');
}
}

Expand Down Expand Up @@ -269,7 +264,7 @@ export default class Hash extends Algorithm {
false,
);
}
}
}
return this.resetAll();
}

Expand Down Expand Up @@ -657,13 +652,13 @@ export default class Hash extends Algorithm {
return 0;
}
let hash = 0;
for (let i = 0; i < key.length; i++) {
hash = ((hash << 5) - hash) + key.charCodeAt(i);
for (let i = 0; i < key.length; i++) {
hash = (hash << 5) - hash + key.charCodeAt(i);
hash ^= 11597109109121;
hash &= 0xFFFF // convert to 16 bits
}
return hash;
}
hash &= 0xffff; // convert to 16 bits
}
return hash;
}

resetAll() {
this.keyField.value = '';
Expand All @@ -674,7 +669,10 @@ export default class Hash extends Algorithm {
}

insertCallback() {
const insertedKey = this.hashType === 'integers' ? parseInt(this.keyField.value).toString() : this.keyField.value;
const insertedKey =
this.hashType === 'integers'
? parseInt(this.keyField.value).toString()
: this.keyField.value;
const insertedValue = this.valueField.value;
if (insertedKey !== '' && insertedValue !== '') {
this.keyField.value = '';
Expand Down
6 changes: 1 addition & 5 deletions src/algo/InsertionSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,7 @@ export default class InsertionSort extends Algorithm {
this.cmd(act.setText, this.arrayID[j], '');
this.cmd(act.move, iLabelID, jXPos, jYPos);
this.cmd(act.move, jLabelID, iXPos, iYPos);
this.cmd(
act.setText,
this.swapCountID,
'Swap Count: ' + ++this.swapCount,
);
this.cmd(act.setText, this.swapCountID, 'Swap Count: ' + ++this.swapCount);
this.cmd(act.step);
this.cmd(act.setText, this.arrayID[i], this.displayData[j]);
this.cmd(act.setText, this.arrayID[j], this.displayData[i]);
Expand Down
8 changes: 1 addition & 7 deletions src/algo/KMP.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,7 @@ export default class KMP extends Algorithm {
xpos = i * this.cellSize + ARRAY_START_X;
ypos = ARRAY_START_Y - 25;
this.textRowID[i] = this.nextIndex;
this.cmd(
act.createLabel,
this.nextIndex++,
i,
xpos,
ypos,
);
this.cmd(act.createLabel, this.nextIndex++, i, xpos, ypos);
}

for (let i = 0; i < text.length; i++) {
Expand Down
9 changes: 8 additions & 1 deletion src/algo/Kruskals.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ export default class Kruskals extends Graph {
[` merge u's cluster with v's cluster`],
];

this.codeID = this.addCodeToCanvasBase(this.code, CODE_START_X, CODE_START_Y, undefined, undefined, 1);
this.codeID = this.addCodeToCanvasBase(
this.code,
CODE_START_X,
CODE_START_Y,
undefined,
undefined,
1,
);

this.animationManager.setAllLayers([0, this.currentLayer]);
this.animationManager.startNewAnimation(this.commands);
Expand Down
8 changes: 1 addition & 7 deletions src/algo/LCS.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,7 @@ export default class LCS extends Algorithm {
[' if ', '(S1[y] == S2[x])'],
[' matrix[y][x] = 1 + ', 'matrix[y - 1][x - 1]'],
[' else'],
[
' matrix[y][x] = max(',
'matrix[y - 1][x]',
',',
' matrix[y][x - 1]',
')',
],
[' matrix[y][x] = max(', 'matrix[y - 1][x]', ',', ' matrix[y][x - 1]', ')'],
[' end for'],
[' end for'],
[' currY ← S1.length'],
Expand Down
Loading