Skip to content

Commit 241baa6

Browse files
authored
FEAT: URL input and share
- Refer to URL-Code-Implementation-Guideline-20241004.pdf to implement it on your algorithms
2 parents c911967 + ccf80a6 commit 241baa6

35 files changed

+18405
-18758
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
31.7 KB
Binary file not shown.

package-lock.json

Lines changed: 17236 additions & 18314 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@
6666
"denque": "^2.0.1",
6767
"framer-motion": "^4.0.0",
6868
"lodash": "^4.17.21",
69-
"prop-types": "^15.7.2",
69+
"prop-types": "^15.8.1",
7070
"react": "^17.0.2",
7171
"react-dom": "^17.0.2",
7272
"react-markdown": "^5.0.0",
7373
"react-resize-detector": "^6.6.0",
7474
"react-router-dom": "^5.2.0",
75-
"react-scripts": "^4.0",
75+
"react-scripts": "^5.0.1",
7676
"react-table": "^7.5.0",
7777
"reactjs-popup": "^2.0.5",
7878
"remark-gfm": "^1.0.0",
@@ -83,7 +83,7 @@
8383
},
8484
"devDependencies": {
8585
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
86-
"electron": "^15.0.0",
86+
"electron": "^31.4.0",
8787
"enzyme": "^3.11.0",
8888
"eslint": "^7.11.0",
8989
"eslint-plugin-import": "^2.28.1",
@@ -96,4 +96,3 @@
9696
"run-script-os": "^1.1.6"
9797
}
9898
}
99-

src/algorithms/controllers/TTFTreeInsertion.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ export default {
347347
},
348348

349349
run(chunker, { nodes }) {
350+
350351
if (nodes === null || nodes.length === 0) return;
351352
let { node: tree, id: newID } = this.createNodeAndIncrement(null);
352353

src/algorithms/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import * as Instructions from './instructions';
2222
src/context/actions.js had better be deployed!
2323
XXX Design of noDeploy stuff was done with the aim of minimal code change
2424
and could be re-thought when there are fewer merges going on.
25-
XXX we could export and use allalgs in key places in the system,
26-
eg src/context/actions.js so we can still access them via the URL, but
27-
not have them appear in the index.
2825
2926
Each imported algorithm is expected to be an object of the form:
3027
{ pseudocode: String, explanation: String, run: Function }
@@ -182,7 +179,6 @@ const allalgs = {
182179
},
183180
},
184181
'BFS': {
185-
186182
name: 'Breadth First Search',
187183
category: 'Graph',
188184
param: <Param.BFSParam/>,
@@ -351,7 +347,13 @@ const algorithms =
351347
* Get the first mode of an algorithm
352348
* @param {string} key algorithm's name
353349
*/
354-
const getDefaultMode = (key) => Object.keys(algorithms[key].pseudocode)[0];
350+
export const getDefaultMode = (key) => Object.keys(algorithms[key].pseudocode)[0];
351+
352+
/**
353+
* Get the category of an algorithm
354+
* @param {string} key algorithm's name
355+
*/
356+
export const getCategory = (key) => algorithms[key].category;
355357

356358
// This function generates a list of algorithms classed by categories
357359
const generateAlgorithmCategoryList = () => {

src/algorithms/parameters/ASTParam.js

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import React, { useState } from 'react';
33
import MatrixParam from './helpers/MatrixParam';
44
import '../../styles/Param.scss';
55
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
6+
import PropTypes from 'prop-types'; // Import this for URL Param
7+
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
68

79
// Note: 'A* Algorithm' currently used in EuclideanMatrixParams.js -
810
// change both or neither!
@@ -30,23 +32,30 @@ const GRAPH_EGS = [ // XXX think up better examples?
3032
edges:
3133
'1-2-10,1-4-4,2-3-6,3-4-10,3-5-5,4-7-3,5-6-7,6-7-8,7-8-2,7-9,8-9-3,9-10-5,9-11-7, 10-11-7,11-13-4,12-13-8,12-14-6,13-14-7,13-15-7,14-16-6,15-16-2,15-17-5,16-17-2'
3234
}];
33-
function ASTParam() {
35+
function ASTParam( { mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max } ) {
3436
const [message, setMessage] = useState(null);
37+
const graph_egs = [
38+
{ name: 'URL Input Graph',
39+
size: size || GRAPH_EGS[0].size,
40+
coords: xyCoords || GRAPH_EGS[0].coords,
41+
edges: edgeWeights || GRAPH_EGS[0].edges
42+
}
43+
]
3544

3645
return (
3746
<>
3847
{/* Matrix input */}
3948
<EuclideanMatrixParams
4049
name="aStar"
4150
mode="find"
42-
defaultSize={DEFAULT_SIZE}
43-
defaultStart={DEFAULT_START}
44-
defaultEnd={DEFAULT_END}
45-
heuristic = {DEFAULT_HEUR}
46-
min={1}
47-
max={49}
51+
defaultSize={ size || DEFAULT_SIZE }
52+
defaultStart={ start || DEFAULT_START }
53+
defaultEnd={ end || DEFAULT_END }
54+
heuristic = { heuristic || DEFAULT_HEUR }
55+
min={ min || 1 }
56+
max={ max || 49 }
4857
symmetric
49-
graphEgs={GRAPH_EGS}
58+
graphEgs={ graph_egs || GRAPH_EGS }
5059
ALGORITHM_NAME={ASTAR}
5160
EXAMPLE={ASTAR_EXAMPLE}
5261
EXAMPLE2={ASTAR_EXAMPLE2}
@@ -60,4 +69,32 @@ function ASTParam() {
6069
);
6170
}
6271

63-
export default ASTParam;
72+
// Define the prop types for URL Params
73+
ASTParam.propTypes = {
74+
alg: PropTypes.string.isRequired,
75+
mode: PropTypes.string.isRequired,
76+
size: PropTypes.string.isRequired,
77+
start: PropTypes.string.isRequired,
78+
end: PropTypes.string.isRequired,
79+
heuristic: PropTypes.string.isRequired,
80+
xyCoords: PropTypes.string.isRequired,
81+
edgeWeights: PropTypes.string.isRequired,
82+
min: PropTypes.string.isRequired,
83+
max: PropTypes.string.isRequired,
84+
};
85+
// ASTParam.propTypes = {
86+
// alg: PropTypes.string.isRequired,
87+
// mode: PropTypes.string.isRequired,
88+
// size: PropTypes.number.isRequired,
89+
// start: PropTypes.arrayOf(PropTypes.number),
90+
// end: PropTypes.arrayOf(PropTypes.number),
91+
// heuristic: PropTypes.number.isRequired,
92+
// xyCoords: PropTypes.string,
93+
// edgeWeights: PropTypes.string,
94+
// min: PropTypes.number,
95+
// max: PropTypes.number
96+
// };
97+
98+
export default withAlgorithmParams(ASTParam); // Export with the wrapper for URL Params
99+
100+

src/algorithms/parameters/BFSParam.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import React, { useState } from 'react';
33
import MatrixParam from './helpers/MatrixParam';
44
import '../../styles/Param.scss';
55
import EuclideanMatrixParams from './helpers/EuclideanMatrixParams';
6+
import PropTypes from 'prop-types'; // Import this for URL Param
7+
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
68

79
const DEFAULT_SIZE = 5;
810
const BFS = 'BFS\'s';
@@ -29,23 +31,29 @@ const GRAPH_EGS = [ // XXX think up better examples?
2931
'1-2-10,1-4-4,2-3-6,3-4-10,3-5-5,4-7-3,5-6-7,6-7-8,7-8-2,7-9,8-9-3,9-10-5,9-11-7, 10-11-7,11-13-4,12-13-8,12-14-6,13-14-7,13-15-7,14-16-6,15-16-2,15-17-5,16-17-2'
3032
}];
3133

32-
function BFSParam() {
34+
function BFSParam({ mode, xyCoords, edgeWeights, size, start, end, heuristic, min, max }) {
3335
const [message, setMessage] = useState(null);
34-
36+
const graph_egs = [
37+
{ name: 'URL Input Graph',
38+
size: size || GRAPH_EGS[0].size,
39+
coords: xyCoords || GRAPH_EGS[0].coords,
40+
edges: edgeWeights || GRAPH_EGS[0].edges
41+
}
42+
]
3543
return (
3644
<>
3745
{/* Matrix input */}
3846
<EuclideanMatrixParams
3947
name="BFS"
4048
mode="find"
41-
defaultSize={DEFAULT_SIZE}
42-
defaultStart={DEFAULT_START}
43-
defaultEnd={DEFAULT_END}
44-
defaultHeur = {DEFAULT_HEUR}
45-
min={1}
46-
max={49}
49+
defaultSize={ size || DEFAULT_SIZE }
50+
defaultStart={ start || DEFAULT_START }
51+
defaultEnd={ end || DEFAULT_END }
52+
defaultHeur = { heuristic || DEFAULT_HEUR }
53+
min={ min || 1 }
54+
max={ max || 49 }
4755
symmetric
48-
graphEgs={GRAPH_EGS}
56+
graphEgs={ graph_egs || GRAPH_EGS }
4957
ALGORITHM_NAME={BFS}
5058
EXAMPLE={BFS_EXAMPLE}
5159
EXAMPLE2={BFS_EXAMPLE2}
@@ -59,4 +67,19 @@ function BFSParam() {
5967
);
6068
}
6169

62-
export default BFSParam;
70+
// Define the prop types for URL Params
71+
BFSParam.propTypes = {
72+
alg: PropTypes.string.isRequired,
73+
mode: PropTypes.string.isRequired,
74+
size: PropTypes.string.isRequired,
75+
start: PropTypes.string.isRequired,
76+
end: PropTypes.string.isRequired,
77+
heuristic: PropTypes.string.isRequired,
78+
xyCoords: PropTypes.string.isRequired,
79+
edgeWeights: PropTypes.string.isRequired,
80+
min: PropTypes.string.isRequired,
81+
max: PropTypes.string.isRequired,
82+
};
83+
84+
export default withAlgorithmParams(BFSParam); // Export with the wrapper for URL Params
85+
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
/* eslint-disable no-unused-vars */
2-
import React, { useState } from 'react';
2+
import React, { useState, useContext, useEffect } from 'react';
33
import { genRandNumList } from './helpers/ParamHelper';
44
import ListParam from './helpers/ListParam';
55
import StringParam from './helpers/StringParam';
66
import '../../styles/Param.scss';
7+
import PropTypes from 'prop-types'; // Import this for URL Param
8+
import { withAlgorithmParams } from './helpers/urlHelpers' // Import this for URL Param
9+
10+
import { URLContext } from '../../context/urlState';
711

812
const DEFAULT_STRING = 'dcaccdddabddac';
913
const DEFAULT_PATTERN = 'ddac';
1014
const BFSS_SEARCH = 'Brute force String Search';
1115
const BFSS_EXAMPLE = 'Enter lower case alphabetic character or space.';
1216

13-
function BFSSParam() {
17+
function BFSSParam({ mode, string, pattern }) {
1418
const [message, setMessage] = useState(null);
15-
const [string, setString] = useState(DEFAULT_STRING);
16-
const [pattern, setPattern] = useState(DEFAULT_PATTERN);
19+
const [string_, setString] = useState(string || DEFAULT_STRING);
20+
const [pattern_, setPattern] = useState(pattern || DEFAULT_PATTERN);
21+
const { setNodes, setSearchValue } = useContext(URLContext);
22+
23+
useEffect(() => {
24+
setNodes(string_);
25+
setSearchValue(pattern_)
26+
}, [string_, pattern_]);
27+
1728
return (
1829
<>
1930
<div className="form">
@@ -22,8 +33,8 @@ function BFSSParam() {
2233
buttonName="SEARCH"
2334
mode="search"
2435
formClassName="formLeft"
25-
DEFAULT_STRING={string}
26-
DEFAULT_PATTERN={pattern}
36+
DEFAULT_STRING={string_}
37+
DEFAULT_PATTERN={pattern_}
2738
SET_STRING={setString}
2839
SET_PATTERN={setPattern}
2940
ALGORITHM_NAME={BFSS_SEARCH}
@@ -34,8 +45,19 @@ function BFSSParam() {
3445
{/* render success/error message */}
3546
<text className="message">{message}</text>
3647
</>
37-
48+
3849
);
3950
}
4051

41-
export default BFSSParam;
52+
// Define the prop types for URL Params
53+
BFSSParam.propTypes = {
54+
alg: PropTypes.string.isRequired,
55+
mode: PropTypes.string.isRequired,
56+
string: PropTypes.string.isRequired,
57+
pattern: PropTypes.string.isRequired
58+
};
59+
60+
export default withAlgorithmParams(BFSSParam); // Export with the wrapper for URL Params
61+
62+
63+

0 commit comments

Comments
 (0)