Skip to content

Commit a946a2f

Browse files
committed
merge
1 parent 29b29b7 commit a946a2f

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed

src/app/components/Map.tsx

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, { useRef, useState, useEffect } from 'react';
88
import * as d3 from 'd3';
99

1010
const Map = (props) => {
11+
// Current snapshot
1112
const { snapshot } = props;
1213
console.log('MAP SNAPSHOT', snapshot);
1314

@@ -17,65 +18,47 @@ const Map = (props) => {
1718

1819
// this state allows the canvas to stay at the zoom level on multiple re-renders
1920
const [{ x, y, k }, setZoomState]: any = useState({ x: 0, y: 0, k: 0 });
20-
2121
useEffect(() => {
2222
setZoomState(d3.zoomTransform(d3.select('#canvas').node()));
2323
}, [snapshot.children]);
2424

25-
// this only clears the canvas if Visualizer is already rendered on the extension
25+
// Create D3 Tree Diagram
2626
useEffect(() => {
27+
28+
const appState: any = {
29+
name: ' Root',
30+
children: snapshot.children,
31+
};
32+
console.log('STATE', appState);
33+
2734
document.getElementById('canvas').innerHTML = '';
2835

2936
// creating the main svg container for d3 elements
3037
const svgContainer: any = d3
3138
.select('#canvas')
3239
.attr('width', width)
3340
.attr('height', height);
41+
3442
// creating a pseudo-class for reusability
3543
const g: any = svgContainer
36-
3744
.append('g')
3845
.attr('transform', `translate(${x}, ${y}), scale(${k})`); // sets the canvas to the saved zoomState
3946

40-
//RE-WRITE ALGORITHIM For All Possible Snapshot Formats
41-
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-
50-
// console.log('CHILDREN', childrenArr);
51-
52-
const appState: any = {
53-
name: ' Root',
54-
// pass in parsed data here
55-
children: snapshot.children,
56-
};
57-
58-
console.log('STATE', appState);
47+
5948
// creating the tree map
6049
const treeMap: any = d3.tree().nodeSize([width, height]);
6150

6251
// creating the nodes of the tree
63-
// pass
6452
const hierarchyNodes: any = d3.hierarchy(appState);
6553

66-
console.log('Hierarchy NODES', hierarchyNodes);
67-
6854
// calling the tree function with nodes created from data
6955
const finalMap: any = treeMap(hierarchyNodes);
7056

71-
console.log('FINAL MAP', finalMap);
72-
7357
// renders a flat array of objects containing all parent-child links
7458
// renders the paths onto the component
7559
let paths: any = finalMap.links();
76-
console.log('PATHS', paths);
7760

78-
// this creates the paths to each atom and its contents in the tree
61+
// this creates the paths to each node and its contents in the tree
7962
g.append('g')
8063
.attr('fill', 'none')
8164
.attr('stroke', '#646464')
@@ -93,11 +76,8 @@ const Map = (props) => {
9376
);
9477

9578
// returns a flat array of objects containing all the nodes and their information
96-
// renders nodes onto the canvas
9779
let nodes: any = hierarchyNodes.descendants();
98-
console.log("NODES",nodes)
9980

100-
// const node is used to create all the nodes
10181
// this segment places all the nodes on the canvas
10282
const node: any = g
10383
.append('g')
@@ -130,8 +110,7 @@ const Map = (props) => {
130110
.attr('stroke', '#646464')
131111
.attr('stroke-width', 2);
132112

133-
// adding a mouseOver event handler to each node
134-
// only add popup text on nodes with no children
113+
135114
// display the data in the node on hover
136115
node.on('mouseover', function (d: any, i: number): any {
137116
if (!d.children) {

0 commit comments

Comments
 (0)