-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AdiletBaimyrza/adilet/create-ctx-nav-add-ids
Adilet/create ctx nav add ids
- Loading branch information
Showing
20 changed files
with
319 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import PropTypes from "prop-types"; | ||
import { createContext, useState } from "react"; | ||
|
||
export const GraphParamsContext = createContext(); | ||
|
||
// Custom hook useGraphParams to manage the states | ||
const useGraphParams = () => { | ||
const [nodes, setNodes] = useState([]); | ||
const [edges, setEdges] = useState([]); | ||
|
||
return { nodes, setNodes, edges, setEdges }; | ||
}; | ||
|
||
/** | ||
* Provides the context for the graph parameters. | ||
* @param {Object} props - The component props. | ||
* @param {ReactNode} props.children - The child components to be rendered. | ||
* @returns {JSX.Element} - The context provider component with the graph parameters as value. | ||
*/ | ||
export const GraphParamsProvider = ({ children }) => { | ||
// Get the graph parameters from the useGraphParams hook | ||
const graphParams = useGraphParams(); | ||
|
||
// Return the context provider component with the graph parameters as value | ||
return ( | ||
<GraphParamsContext.Provider value={graphParams}> | ||
{children} | ||
</GraphParamsContext.Provider> | ||
); | ||
}; | ||
|
||
// Makes sure the 'children' prop is a React node and that it is a required parameter | ||
GraphParamsProvider.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; |
142 changes: 71 additions & 71 deletions
142
dijkstra-prim-visualization/src/components/Canvas/Canvas.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
dijkstra-prim-visualization/src/components/Canvas/Edge/Edge.jsx
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
dijkstra-prim-visualization/src/components/Canvas/Edges/Edge/Edge.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import PropTypes from "prop-types"; | ||
import classes from "./Edge.module.css"; | ||
|
||
/** | ||
* Renders an edge between two points on the canvas. | ||
* @param {Object} props - The component props. | ||
* @param {string} props.id - The unique identifier for the edge. | ||
* @param {number} props.x1 - The x-coordinate of the starting point. | ||
* @param {number} props.y1 - The y-coordinate of the starting point. | ||
* @param {number} props.x2 - The x-coordinate of the ending point. | ||
* @param {number} props.y2 - The y-coordinate of the ending point. | ||
* @returns {JSX.Element} - The rendered component. | ||
*/ | ||
const Edge = ({ id, x1, y1, x2, y2 }) => { | ||
return ( | ||
<line className={classes.line} id={id} x1={x1} y1={y1} x2={x2} y2={y2} /> | ||
); | ||
}; | ||
|
||
export default Edge; | ||
|
||
// Validates that the required props are passed and their type is number | ||
Edge.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
x1: PropTypes.number.isRequired, | ||
y1: PropTypes.number.isRequired, | ||
x2: PropTypes.number.isRequired, | ||
y2: PropTypes.number.isRequired, | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.