Skip to content

Commit 4a5689c

Browse files
authored
Merge pull request #9 from kevinfey/chart
Change data input into Map.tsx d3.hierachy. Add CSS for sticky Navbar z=1
2 parents 5ddb32b + 39c92c4 commit 4a5689c

File tree

4 files changed

+39
-46
lines changed

4 files changed

+39
-46
lines changed

src/app/components/Chart.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ const filterHooks = (data: any[]) => {
3030
return JSON.stringify(data[0].state);
3131
};
3232

33-
//const filterRecoil = (data: any[]) => {};
34-
3533
interface ChartProps {
3634
hierarchy: Record<string, unknown>;
3735
}
@@ -76,14 +74,9 @@ class Chart extends Component {
7674
*/
7775
maked3Tree(): void {
7876
this.removed3Tree();
79-
// const margin = {
80-
// top: 0,
81-
// right: 60,
82-
// bottom: 200,
83-
// left: 120,
84-
// };
85-
const width = 600; // - margin.right - margin.left;
86-
const height = 600; // 700 - margin.top - margin.bottom;
77+
78+
const width = 800;
79+
const height = 600;
8780
const svgContainer = d3
8881
.select(this.chartRef.current)
8982
.append('svg') // svgContainer is now pointing to svg

src/app/components/Map.tsx

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

1010
const Map = (props) => {
11-
// Current snapshot
12-
const { snapshot } = props;
13-
console.log('MAP SNAPSHOT', snapshot);
11+
12+
const { snapshot, snapshots} = props;
13+
const lastSnap = snapshots.length -1
1414

1515
// set the heights and width of the tree to be passed into treeMap function
16-
const width: number = 1100;
16+
const width: number = 900;
1717
const height: number = 600;
1818

1919
// this state allows the canvas to stay at the zoom level on multiple re-renders
@@ -22,15 +22,9 @@ const Map = (props) => {
2222
setZoomState(d3.zoomTransform(d3.select('#canvas').node()));
2323
}, [snapshot.children]);
2424

25-
// Create D3 Tree Diagram
25+
// Create D3 Tree Diagram
2626
useEffect(() => {
2727

28-
const appState: any = {
29-
name: ' Root',
30-
children: snapshot.children,
31-
};
32-
console.log('STATE', appState);
33-
3428
document.getElementById('canvas').innerHTML = '';
3529

3630
// creating the main svg container for d3 elements
@@ -44,12 +38,11 @@ const Map = (props) => {
4438
.append('g')
4539
.attr('transform', `translate(${x}, ${y}), scale(${k})`); // sets the canvas to the saved zoomState
4640

47-
4841
// creating the tree map
4942
const treeMap: any = d3.tree().nodeSize([width, height]);
5043

5144
// creating the nodes of the tree
52-
const hierarchyNodes: any = d3.hierarchy(appState);
45+
const hierarchyNodes: any = d3.hierarchy(snapshots[lastSnap]);
5346

5447
// calling the tree function with nodes created from data
5548
const finalMap: any = treeMap(hierarchyNodes);
@@ -110,7 +103,6 @@ const Map = (props) => {
110103
.attr('stroke', '#646464')
111104
.attr('stroke-width', 2);
112105

113-
114106
// display the data in the node on hover
115107
node.on('mouseover', function (d: any, i: number): any {
116108
if (!d.children) {
@@ -142,24 +134,24 @@ const Map = (props) => {
142134
);
143135

144136
// allows the canvas to be zoom-able
145-
// d3 zoom functionality
146-
let zoom = d3.zoom().on('zoom', zoomed);
147-
svgContainer.call(
148-
zoom.transform,
149-
// Changes the initial view, (left, top)
150-
d3.zoomIdentity.translate(150, 250).scale(0.2),
151-
);
152-
// allows the canvas to be zoom-able
153-
svgContainer.call(
154-
d3
155-
.zoom()
156-
.scaleExtent([0.05, 0.9]) // [zoomOut, zoomIn]
157-
.on('zoom', zoomed),
158-
);
159-
// helper function that allows for zooming
160-
function zoomed(d: any) {
161-
g.attr('transform', d3.event.transform);
162-
}
137+
// d3 zoom functionality
138+
let zoom = d3.zoom().on('zoom', zoomed);
139+
svgContainer.call(
140+
zoom.transform,
141+
// Changes the initial view, (left, top)
142+
d3.zoomIdentity.translate(150, 250).scale(0.2)
143+
);
144+
// allows the canvas to be zoom-able
145+
svgContainer.call(
146+
d3
147+
.zoom()
148+
.scaleExtent([0.05, 0.9]) // [zoomOut, zoomIn]
149+
.on('zoom', zoomed)
150+
);
151+
// helper function that allows for zooming
152+
function zoomed(d: any) {
153+
g.attr('transform', d3.event.transform);
154+
}
163155

164156
// helper functions that help with dragging functionality
165157
function dragStarted(): any {
@@ -176,8 +168,6 @@ const Map = (props) => {
176168
function dragEnded(): any {
177169
g.attr('cursor', 'grab');
178170
}
179-
180-
181171
});
182172

183173
return (

src/app/components/StateRoute.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const StateRoute = (props: StateRouteProps) => {
4343
//Test Map
4444
const renderMap = () => {
4545
if (hierarchy) {
46-
return <Map snapshot={snapshot} />;
46+
return <Map snapshot={snapshot} snapshots={snapshots} />;
4747
}
4848
return <div className="noState">{NO_STATE_MSG}</div>;
4949
};
@@ -83,6 +83,8 @@ const StateRoute = (props: StateRouteProps) => {
8383
/>
8484
);
8585
}
86+
87+
//This will intermitently block Recoil PerfCharts from rendering
8688
// else {
8789
// perfChart = (
8890
// <div className="no-data-message">

src/app/styles/layout/_stateContainer.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
.state-container {
22
font-size: 12px;
33
overflow: auto;
4+
45
background-color: $brand-color;
56
}
67

78
.state-container .navbar {
9+
810
background-color: $navbar-color;
911
display: flex;
1012
flex-direction: row;
@@ -14,15 +16,21 @@
1416
}
1517

1618
.state-container .main-navbar{
19+
1720
background-color: #565A61;
1821
display: flex;
1922
flex-direction: row;
23+
justify-content: flex-start;
2024
align-items: center;
2125
height: 40px;
2226
margin: 6px;
2327
}
2428

2529
.state-container .main-navbar-container{
30+
position: sticky ;
31+
top: 0px;
32+
left: 0px;
33+
z-index: 1;
2634
background-color: #565A61;
2735
display: flex;
2836
flex-direction: row;
@@ -33,7 +41,7 @@
3341

3442
.navbar {
3543
// prevent navbar from scrolling with state/tree display
36-
position: sticky;
44+
position: sticky ;
3745
top: 0px;
3846
left: 0px;
3947
z-index: 1;

0 commit comments

Comments
 (0)