Skip to content

Commit c5b4ef3

Browse files
committed
map change to component map
1 parent 73cc432 commit c5b4ef3

File tree

2 files changed

+7
-114
lines changed

2 files changed

+7
-114
lines changed

src/app/components/Map.tsx renamed to src/app/components/ComponentMap.tsx

Lines changed: 3 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import React, { useEffect, useCallback, useState } from 'react';
88
import * as d3 from 'd3';
99

10-
const Map = (props) => {
10+
const ComponentMap = (props) => {
1111
//import props
1212
const { viewIndex, snapshots ,x ,y, k, setZoomState} = props;
1313
let lastSnap: number | null = null;
@@ -75,7 +75,7 @@ const Map = (props) => {
7575

7676
// declare re render funciton to handle collapse and expansion of nodes
7777
const update = (source) => {
78-
const duration = 0;
78+
const duration = 250;
7979
const nodes = root.descendants().reverse();
8080
const links = root.links();
8181

@@ -236,118 +236,11 @@ const Map = (props) => {
236236
);
237237

238238

239-
<<<<<<< HEAD
240-
// returns a flat array of objects containing all the nodes and their information
241-
let nodes: any = hierarchyNodes.descendants();
242-
243-
// this segment places all the nodes on the canvas
244-
const node: any = g
245-
.append('g')
246-
.attr('stroke-linejoin', 'round') // no clue what this does
247-
.attr('stroke-width', 1)
248-
.selectAll('g')
249-
.data(nodes)
250-
.enter()
251-
.append('g')
252-
.attr('transform', (d: any) => `translate(${d.y}, ${d.x})`)
253-
.attr('class', 'atomNodes');
254-
255-
// for each node that got created, append a circle element
256-
node
257-
.append('circle')
258-
.attr('fill', (d: any) => (d.children ? '#95B6B7' : '#46edf2'))
259-
.attr('r', 50);
260-
261-
// for each node that got created, append a text element that displays the name of the node
262-
node
263-
.append('text')
264-
.attr('dy', '.31em')
265-
.attr('x', (d: any) => (d.children ? -50 : 50))
266-
.attr('text-anchor', (d: any) => (d.children ? 'end' : 'start'))
267-
.text((d: any) => d.data.name)
268-
.style('font-size', `2rem`)
269-
.style('fill', 'white')
270-
.clone(true)
271-
.lower()
272-
.attr('stroke', '#646464')
273-
.attr('stroke-width', 2);
274-
275-
// display the data in the node on hover
276-
node.on('mouseover', function (d: any, i: number): any {
277-
if (!d.children) {
278-
d3.select(this)
279-
.append('text')
280-
.text(JSON.stringify(d.data, undefined, 2))
281-
.style('fill', 'white')
282-
.attr('x', -999)
283-
.attr('y', 100)
284-
.style('font-size', '3rem')
285-
.style('text-align', 'center')
286-
.attr('stroke', '#646464')
287-
.attr('id', `popup${i}`);
288-
}
289-
});
290-
291-
// add mouseOut event handler that removes the popup text
292-
node.on('mouseout', function (d: any, i: number): any {
293-
d3.select(`#popup${i}`).remove();
294-
});
295-
296-
// allows the canvas to be draggable
297-
node.call(
298-
d3
299-
.drag()
300-
.on('start', dragStarted)
301-
.on('drag', dragged)
302-
.on('end', dragEnded)
303-
);
304-
305-
// allows the canvas to be zoom-able
306-
// d3 zoom functionality
307-
let zoom = d3.zoom().on('zoom', zoomed);
308-
// svgContainer.call(
309-
// zoom.transform,
310-
// // Changes the initial view, (left, top)
311-
// d3.zoomIdentity.translate(150, 250).scale(0.2)
312-
// );
313-
// allows the canvas to be zoom-able
314-
svgContainer.call(
315-
d3
316-
.zoom()
317-
.scaleExtent([0.05, 0.9]) // [zoomOut, zoomIn]
318-
.on('zoom', zoomed)
319-
);
320-
// helper function that allows for zooming
321-
function zoomed(d: any) {
322-
g.attr('transform', d3.event.transform);
323-
}
324-
325-
// helper functions that help with dragging functionality
326-
function dragStarted(): any {
327-
d3.select(this).raise();
328-
g.attr('cursor', 'grabbing');
329-
}
330-
331-
function dragged(d: any): any {
332-
d3.select(this)
333-
.attr('dx', (d.x = d3.event.x))
334-
.attr('dy', (d.y = d3.event.y));
335-
}
336-
337-
function dragEnded(): any {
338-
g.attr('cursor', 'grab');
339-
}
340-
341-
342-
343-
});
344-
=======
345239
// call update on node click
346240
update(root);
347241
},
348242
[data]
349243
);
350-
>>>>>>> master
351244

352245
return (
353246
<div data-testid="canvas">
@@ -358,4 +251,4 @@ const Map = (props) => {
358251
);
359252
};
360253

361-
export default Map;
254+
export default ComponentMap;

src/app/components/StateRoute.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Switch,
1313
} from 'react-router-dom';
1414
import Tree from './Tree';
15-
import Map from './Map';
15+
import ComponentMap from './ComponentMap';
1616
import PerfView from './PerfView';
1717

1818
const History = require('./History').default;
@@ -45,9 +45,9 @@ const StateRoute = (props: StateRouteProps) => {
4545
k: 0.75,
4646
});
4747
//Map
48-
const renderMap = () => {
48+
const renderComponentMap = () => {
4949
if (hierarchy) {
50-
return <Map viewIndex={viewIndex} snapshots={snapshots} x={x} y={y} k={k} setZoomState={setZoomState} />;
50+
return <ComponentMap viewIndex={viewIndex} snapshots={snapshots} x={x} y={y} k={k} setZoomState={setZoomState} />;
5151
}
5252
return <div className="noState">{NO_STATE_MSG}</div>;
5353
};
@@ -128,7 +128,7 @@ const StateRoute = (props: StateRouteProps) => {
128128
</NavLink>
129129
</div>
130130
<Switch>
131-
<Route path="/map" render={renderMap} />
131+
<Route path="/map" render={renderComponentMap} />
132132
<Route path="/history" render={renderHistory} />
133133
<Route path="/performance" render={renderPerfView} />
134134
<Route path="/" render={renderTree} />

0 commit comments

Comments
 (0)