Skip to content

Commit de7550b

Browse files
authored
Merge pull request #4 from oslabs-beta/andy
Andy
2 parents 06e5894 + fc4c433 commit de7550b

File tree

3 files changed

+59
-69
lines changed

3 files changed

+59
-69
lines changed

src/app/components/History.tsx

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react-hooks/exhaustive-deps */
12
// @ts-nocheck
23
import React, { Component, useEffect, useState } from 'react';
34
import * as d3 from 'd3';
@@ -7,10 +8,10 @@ import { changeView, changeSlider } from '../actions/actions';
78
* @var colors: Colors array for the diffrerent node branches, each color is for a different branch
89
*/
910
const colors = [
10-
'#eb4d70',
11-
'#f19938',
12-
'#6ce18b',
13-
'#78f6ef',
11+
'#eb4d70',
12+
'#f19938',
13+
'#6ce18b',
14+
'#78f6ef',
1415
'#9096f8',
1516
'#C5B738',
1617
'#858DFF',
@@ -39,17 +40,19 @@ const filterHooks = (data: any[]) => {
3940
// main function exported to StateRoute
4041
// below we destructure the props
4142
function History(props: Record<string, unknown>) {
42-
const { width, height, hierarchy, dispatch, sliderIndex, viewIndex } = props;
43+
const {
44+
width, height, hierarchy, dispatch, sliderIndex, viewIndex,
45+
} = props;
4346

44-
let root = JSON.parse(JSON.stringify(hierarchy));
45-
let isRecoil = false;
47+
const root = JSON.parse(JSON.stringify(hierarchy));
48+
const isRecoil = false;
4649

47-
let HistoryRef = React.createRef(root);
50+
const HistoryRef = React.createRef(root);
4851
useEffect(() => {
4952
maked3Tree();
50-
}, [root]);
53+
}, [maked3Tree, root]);
5154

52-
let removed3Tree = function () {
55+
const removed3Tree = function () {
5356
const { current } = HistoryRef;
5457
while (current.hasChildNodes()) {
5558
current.removeChild(current.lastChild);
@@ -62,8 +65,8 @@ function History(props: Record<string, unknown>) {
6265
*/
6366
let maked3Tree = function () {
6467
removed3Tree();
65-
const width: number = 800;
66-
const height: number = 600;
68+
const width = 800;
69+
const height = 600;
6770
const svgContainer = d3
6871
.select(HistoryRef.current)
6972
.append('svg') // svgContainer is now pointing to svg
@@ -81,9 +84,7 @@ function History(props: Record<string, unknown>) {
8184
const tree = d3
8285
.tree()
8386
.nodeSize([width / 10, height / 10])
84-
.separation(function (a: { parent: object }, b: { parent: object }) {
85-
return a.parent == b.parent ? 2 : 2;
86-
});
87+
.separation((a: { parent: object }, b: { parent: object }) => (a.parent == b.parent ? 2 : 2));
8788

8889
const d3root = tree(hierarchy);
8990

@@ -101,7 +102,7 @@ function History(props: Record<string, unknown>) {
101102
d3
102103
.linkRadial()
103104
.angle((d: { x: number }) => d.x)
104-
.radius((d: { y: number }) => d.y)
105+
.radius((d: { y: number }) => d.y),
105106
);
106107

107108
const node = g
@@ -110,11 +111,10 @@ function History(props: Record<string, unknown>) {
110111
.data(d3root.descendants())
111112
.enter()
112113
.append('g')
113-
.style('fill', function (d) {
114+
.style('fill', d => {
114115
let loadTime;
115116
if (d.data.stateSnapshot.children[0].componentData.actualDuration) {
116-
loadTime =
117-
d.data.stateSnapshot.children[0].componentData.actualDuration;
117+
loadTime = d.data.stateSnapshot.children[0].componentData.actualDuration;
118118
} else {
119119
loadTime = 1;
120120
}
@@ -135,9 +135,7 @@ function History(props: Record<string, unknown>) {
135135
return colors[indexColors];
136136
})
137137
.attr('class', 'node--internal')
138-
.attr('transform', function (d: { x: number; y: number }) {
139-
return 'translate(' + reinfeldTidierAlgo(d.x, d.y) + ')';
140-
});
138+
.attr('transform', (d: { x: number; y: number }) => `translate(${reinfeldTidierAlgo(d.x, d.y)})`);
141139

142140
// here we the node circle is created and given a radius size, we are also giving it a mouseover and onClick functionality
143141
// mouseover will highlight the node
@@ -146,10 +144,10 @@ function History(props: Record<string, unknown>) {
146144
node
147145
.append('circle')
148146
.attr('r', 14)
149-
.on('mouseover', function (d: `Record<string, unknown>`) {
147+
.on('mouseover', function (d: 'Record<string, unknown>') {
150148
d3.select(this).transition(90).duration(18).attr('r', 21);
151149
})
152-
.on('click', function (d: `Record<string, unknown>`) {
150+
.on('click', (d: 'Record<string, unknown>') => {
153151
const index = parseInt(`${d.data.name}.${d.data.branch}`);
154152
dispatch(changeSlider(index));
155153
dispatch(changeView(index));
@@ -163,41 +161,37 @@ function History(props: Record<string, unknown>) {
163161
.append('text')
164162
// adjusts the y coordinates for the node text
165163
.attr('dy', '0.5em')
166-
.attr('x', function (d: { x: number; children?: [] }) {
164+
.attr('x', (d: { x: number; children?: [] }) =>
167165
// this positions how far the text is from leaf nodes (ones without children)
168166
// negative number before the colon moves the text of rightside nodes,
169167
// positive number moves the text for the leftside nodes
170-
return d.x < Math.PI === !d.children ? 0 : 0;
171-
})
168+
(d.x < Math.PI === !d.children ? 0 : 0))
172169
.attr('text-anchor', 'middle')
173170
// this arranges the angle of the text
174-
.attr('transform', function (d: { x: number; y: number }) {
175-
return (
176-
'rotate(' +
177-
((d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1) /
178-
Math.PI +
179-
')'
180-
);
181-
})
182-
.text(function (d: { data: { name: number; branch: number } }) {
171+
.attr('transform', (d: { x: number; y: number }) => (
172+
`rotate(${
173+
((d.x < Math.PI ? d.x - Math.PI / 2 : d.x + Math.PI / 2) * 1)
174+
/ Math.PI
175+
})`
176+
))
177+
.text((d: { data: { name: number; branch: number } }) =>
183178
// display the name of the specific patch
184179
// return `${d.data.name}.${d.data.branch}`;
185-
return `${d.data.name}.${d.data.branch}`;
186-
});
180+
`${d.data.name}.${d.data.branch}`);
187181

188182
// Zoom Functions
189-
let zoom = d3.zoom().on('zoom', zoomed);
183+
const zoom = d3.zoom().on('zoom', zoomed);
190184
svgContainer.call(
191185
zoom.transform,
192186
// Changes the initial view, (left, top)
193-
d3.zoomIdentity.translate(width / 3, height / 4).scale(1)
187+
d3.zoomIdentity.translate(width / 3, height / 4).scale(1),
194188
);
195189
// allows the canvas to be zoom-able
196190
svgContainer.call(
197191
d3
198192
.zoom()
199193
.scaleExtent([0, 0.9]) // [zoomOut, zoomIn]
200-
.on('zoom', zoomed)
194+
.on('zoom', zoomed),
201195
);
202196
// helper function that allows for zooming ( think about how I can convert this any to typescript)
203197
function zoomed(d: any) {
@@ -210,7 +204,7 @@ function History(props: Record<string, unknown>) {
210204
.drag()
211205
.on('start', dragstarted)
212206
.on('drag', dragged)
213-
.on('end', dragended)
207+
.on('end', dragended),
214208
);
215209

216210
function dragstarted() {

src/app/containers/StateContainer.tsx

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,43 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
4343

4444
return (
4545
<Router>
46-
<div className='state-container'>
47-
<div className='main-navbar-container'>
48-
<div className='main-navbar-text'>
49-
</div>
50-
<div className='main-navbar'>
46+
<div className="state-container">
47+
<div className="main-navbar-container">
48+
<div className="main-navbar-text" />
49+
<div className="main-navbar">
5150
<NavLink
52-
className='main-router-link'
53-
activeClassName='is-active'
51+
className="main-router-link"
52+
activeClassName="is-active"
5453
exact
55-
to='/'
54+
to="/"
5655
>
5756
State
5857
</NavLink>
5958
<NavLink
60-
className='main-router-link'
61-
activeClassName='is-active'
62-
to='/diff'
59+
className="main-router-link"
60+
activeClassName="is-active"
61+
to="/diff"
6362
>
6463
Diff
6564
</NavLink>
6665
</div>
6766
</div>
6867
<Switch>
6968
<Route
70-
path='/diff'
71-
render={() => {
72-
return <DiffRoute snapshot={snapshot} />;
73-
}}
69+
path="/diff"
70+
render={() => <DiffRoute snapshot={snapshot} />}
7471
/>
7572
<Route
76-
path='/'
77-
render={() => {
78-
return (
79-
<StateRoute
80-
webMetrics={webMetrics}
81-
viewIndex={viewIndex}
82-
snapshot={snapshot}
83-
hierarchy={hierarchy}
84-
snapshots={snapshots}
85-
/>
86-
);
87-
}}
73+
path="/"
74+
render={() => (
75+
<StateRoute
76+
webMetrics={webMetrics}
77+
viewIndex={viewIndex}
78+
snapshot={snapshot}
79+
hierarchy={hierarchy}
80+
snapshots={snapshots}
81+
/>
82+
)}
8883
/>
8984
</Switch>
9085
</div>

src/app/reducers/mainReducer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default (state, action) => produce(state, draft => {
5959
};
6060
});
6161
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: false };
62+
break;
6263
}
6364
case types.ON_HOVER_EXIT: {
6465
port.postMessage({

0 commit comments

Comments
 (0)