Skip to content

Commit 7240e07

Browse files
committed
improved fiber tree for Recoil
1 parent 98995f8 commit 7240e07

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/app/components/Map.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const Map = (props) => {
1818
// this state allows the canvas to stay at the zoom level on multiple re-renders
1919
const [{ x, y, k }, setZoomState]: any = useState({ x: 0, y: 0, k: 0 });
2020

21-
useEffect(() => {
22-
setZoomState(d3.zoomTransform(d3.select('#canvas').node()));
23-
}, [snapshot]);
21+
// useEffect(() => {
22+
// setZoomState(d3.zoomTransform(d3.select('#canvas').node()));
23+
// }, [snapshot]);
2424

2525
// this only clears the canvas if Visualizer is already rendered on the extension
2626
useEffect(() => {
@@ -37,33 +37,39 @@ const Map = (props) => {
3737
.append('g')
3838
.attr('transform', `translate(${x}, ${y}), scale(${k})`); // sets the canvas to the saved zoomState
3939

40-
// atomState is the object that is passed into d3.hierarchy
41-
const childrenArr = [];
42-
if (snapshot.children[0].state.hooksState) {
43-
snapshot.children[0].state.hooksState[0].undefined.forEach((el) =>
44-
childrenArr.push(el)
45-
);
46-
}
47-
console.log(childrenArr);
40+
//RE-WRITE ALGORITHIM
4841

49-
const atomState: any = {
42+
// appState is the object that is passed into d3.hierarchy
43+
// const childrenArr = [];
44+
// if (snapshot.children[0].state.hooksState) {
45+
// snapshot.children[0].state.hooksState.forEach((el) =>
46+
// childrenArr.push(el)
47+
// );
48+
// }
49+
// console.log('CHILDREN', childrenArr);
50+
51+
const appState: any = {
5052
name: ' Root',
5153
// pass in parsed data here
5254
// call the helper function passing in the most recent snapshot
53-
children: childrenArr,
55+
children: snapshot.children,
5456
};
5557

56-
console.log('STATE', atomState);
58+
console.log('STATE', appState);
5759
// creating the tree map
5860
const treeMap: any = d3.tree().nodeSize([width, height]);
5961

6062
// creating the nodes of the tree
6163
// pass
62-
const hierarchyNodes: any = d3.hierarchy(atomState);
64+
const hierarchyNodes: any = d3.hierarchy(appState);
65+
66+
console.log('Hierarchy NODES', hierarchyNodes);
6367

6468
// calling the tree function with nodes created from data
6569
const finalMap: any = treeMap(hierarchyNodes);
6670

71+
console.log('FINAL MAP', finalMap);
72+
6773
// renders a flat array of objects containing all parent-child links
6874
// renders the paths onto the component
6975
let paths: any = finalMap.links();

0 commit comments

Comments
 (0)