Skip to content

Commit

Permalink
0.1.9 - some fixes to dotfile updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmadigan committed Aug 27, 2024
1 parent 5a58bb2 commit 1062226
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-policy-topology",
"version": "0.1.8",
"version": "0.1.9",
"type": "module",
"main": "src/main.js",
"module": "src/main.js",
Expand Down
27 changes: 14 additions & 13 deletions src/PolicyTopology.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ import './PolicyTopology.css';

const PolicyTopology = ({ initialDotString }) => {
const containerRef = useRef(null);
const [dotString, setDotString] = useState(initialDotString); // State for the dot string
const [dotString, setDotString] = useState(initialDotString);
const [graph, setGraph] = useState(null);

// Parse the DOT string into a graph object
useEffect(() => {
if (dotString) {
const g = dot.read(dotString);
setGraph(g);
}
}, [dotString]);

// Function to handle node selection and update the graph
// Function to update graph when a node is selected
const handleNodeSelection = useCallback((nodeId) => {
if (!graph) return;

Expand Down Expand Up @@ -58,14 +50,23 @@ const PolicyTopology = ({ initialDotString }) => {
setDotString(filteredDotString); // Update the dotString state
}, [graph]);

// Render the graph when the component mounts or the dotString changes
// Parse the DOT string into a graph object when dotString changes
useEffect(() => {
if (dotString) {
const g = dot.read(dotString);
setGraph(g);
}
}, [dotString]);

// Render the graph with updates using d3-graphviz
useEffect(() => {
if (containerRef.current && graph) {
const renderGraph = () => {
d3.select(containerRef.current).graphviz()
d3.select(containerRef.current)
.graphviz()
.zoom(false)
.fit(true)
.transition(() => d3.transition().duration(750))
.transition(() => d3.transition().duration(750)) // Animate transitions
.renderDot(dotString)
.on('end', () => {
const nodes = containerRef.current.querySelectorAll('g.node');
Expand Down

0 comments on commit 1062226

Please sign in to comment.