Skip to content

Commit e938454

Browse files
Merge pull request #18 from AlexanderLanderos/newComponentMap
New component map
2 parents e0050b8 + f802c6c commit e938454

File tree

4 files changed

+65
-67
lines changed

4 files changed

+65
-67
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import useForceUpdate from './useForceUpdate';
1212
import LinkControls from './LinkControls';
1313
import getLinkComponent from './getLinkComponent';
1414

15-
const defaultMargin = { top: 30, left: 30, right: 30, bottom: 70 };
15+
// setting the base margins for the Map to render in the Chrome extension window.
16+
const defaultMargin = { top: 30, left: 30, right: 30, bottom: 30 };
1617

18+
// export these types because this will only be used on this page, interface not needed as it will not be re-used.
1719
export type LinkTypesProps = {
1820
width: number;
1921
height: number;
@@ -28,23 +30,27 @@ export default function ComponentMap({
2830
margin = defaultMargin,
2931
snapshots: snapshots,
3032
}: LinkTypesProps) {
31-
// preparing the data to be used for render
33+
console.log(totalHeight);
34+
35+
// This is where we select the last object in the snapshots array from props to allow hierarchy to parse the data for render on the component map per hierarchy layout specifications.
3236
const lastNode = snapshots.length - 1;
3337
const data = snapshots[lastNode];
38+
// importing custom hooks for the selection tabs.
3439
const [layout, setLayout] = useState<string>('cartesian');
3540
const [orientation, setOrientation] = useState<string>('horizontal');
3641
const [linkType, setLinkType] = useState<string>('diagonal');
37-
const [stepPercent, setStepPercent] = useState<number>(0.5);
42+
const [stepPercent, setStepPercent] = useState<number>(10);
3843
const forceUpdate = useForceUpdate();
39-
// setting the margins for the Map to render in the tab
44+
4045
const innerWidth = totalWidth - margin.left - margin.right;
4146
const innerHeight = totalHeight - margin.top - margin.bottom;
4247

4348
let origin: { x: number; y: number };
4449
let sizeWidth: number;
4550
let sizeHeight: number;
4651

47-
// rendering for the different tab selections
52+
// Conditional statement sets the location of the root node in the middle of the window
53+
// Else statement sets the location of the root node to the right or top of the window per dropdown selection.
4854
if (layout === 'polar') {
4955
origin = {
5056
x: innerWidth / 2,
@@ -62,7 +68,12 @@ export default function ComponentMap({
6268
sizeHeight = innerWidth;
6369
}
6470
}
65-
// controls for the map
71+
72+
// render controls for the map
73+
// svg - complete layout of self contained component map
74+
// Tree is rendering each component from the component tree.
75+
// rect- Contains both text and rectangle node information for rendering each component on the map.
76+
// circle- setup and layout for the root node.
6677
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
6778
return totalWidth < 10 ? null : (
6879
<div>
@@ -84,7 +95,7 @@ export default function ComponentMap({
8495
<Tree
8596
root={hierarchy(data, (d) => (d.isExpanded ? null : d.children))}
8697
size={[sizeWidth, sizeHeight]}
87-
separation={(a, b) => (a.parent === b.parent ? 1 : 0.5) / a.depth}
98+
separation={(a, b) => (a.parent === b.parent ? 10 : 0) / a.depth}
8899
>
89100
{(tree) => (
90101
<Group top={origin.y} left={origin.x}>
@@ -98,7 +109,7 @@ export default function ComponentMap({
98109
fill='none'
99110
/>
100111
))}
101-
112+
translate
102113
{tree.descendants().map((node, key) => {
103114
const width = 40;
104115
const height = 15;
@@ -125,7 +136,6 @@ export default function ComponentMap({
125136
fill="url('#links-gradient')"
126137
onClick={() => {
127138
node.data.isExpanded = !node.data.isExpanded;
128-
console.log(node);
129139
forceUpdate();
130140
}}
131141
/>
@@ -144,7 +154,7 @@ export default function ComponentMap({
144154
rx={node.data.children ? 0 : 10}
145155
onClick={() => {
146156
node.data.isExpanded = !node.data.isExpanded;
147-
console.log(node);
157+
148158
forceUpdate();
149159
}}
150160
/>

src/app/components/LinkControls.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { link } from 'fs';
12
import React from 'react';
23

34
const controlStyles = { fontSize: 10 };
4-
5+
// props for orientation controls
56
type Props = {
67
layout: string;
78
orientation: string;
@@ -12,7 +13,7 @@ type Props = {
1213
setLinkType: (linkType: string) => void;
1314
setStepPercent: (percent: number) => void;
1415
};
15-
16+
// below are the control options for each of the drop downs.
1617
export default function LinkControls({
1718
layout,
1819
orientation,
@@ -54,7 +55,6 @@ export default function LinkControls({
5455
>
5556
<option value='diagonal'>Diagonal</option>
5657
<option value='step'>Step</option>
57-
<option value='curve'>Curve</option>
5858
<option value='line'>Line</option>
5959
</select>
6060
{linkType === 'step' && layout !== 'polar' && (
@@ -65,7 +65,7 @@ export default function LinkControls({
6565
onClick={(e) => e.stopPropagation()}
6666
type='range'
6767
min={0}
68-
max={1}
68+
max={5}
6969
step={0.1}
7070
onChange={(e) => setStepPercent(Number(e.target.value))}
7171
value={stepPercent}

src/app/components/StateRoute.tsx

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,11 @@ interface StateRouteProps {
4848
const StateRoute = (props: StateRouteProps) => {
4949
const { snapshot, hierarchy, snapshots, viewIndex } = props;
5050

51-
console.log(hierarchy)
51+
console.log(hierarchy);
5252

5353
const isRecoil = snapshot.atomsComponents ? true : false;
5454
const [noRenderData, setNoRenderData] = useState(false);
5555

56-
// component map zoom state
57-
const [{ x, y, k }, setZoomState]: any = useState({
58-
x: 150,
59-
y: 250,
60-
k: 1,
61-
});
62-
6356
// Map
6457
const renderComponentMap = () => {
6558
if (hierarchy) {
@@ -71,12 +64,12 @@ const StateRoute = (props: StateRouteProps) => {
7164
</ParentSize>
7265
);
7366
}
74-
return <div className="noState">{NO_STATE_MSG}</div>;
67+
return <div className='noState'>{NO_STATE_MSG}</div>;
7568
};
7669

7770
// the hierarchy gets set on the first click in the page
7871
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
79-
// if true involk render chart with hierarchy
72+
// if true invoke render chart with hierarchy
8073
const renderHistory = () => {
8174
if (hierarchy) {
8275
return (
@@ -90,41 +83,41 @@ const StateRoute = (props: StateRouteProps) => {
9083
</div>
9184
);
9285
}
93-
return <div className="noState">{NO_STATE_MSG}</div>;
86+
return <div className='noState'>{NO_STATE_MSG}</div>;
9487
};
9588

9689
const renderAtomsRelationship = () => (
97-
98-
<ParentSize>{({ width, height }) =>
99-
<Example
100-
width={width}
101-
height={height}
102-
snapshots={snapshots} />}
90+
<ParentSize>
91+
{({ width, height }) => (
92+
<Example width={width} height={height} snapshots={snapshots} />
93+
)}
10394
</ParentSize>
10495
);
10596

10697
// the hierarchy gets set on the first click in the page
10798
// when the page is refreshed we may not have a hierarchy, so we need to check if hierarchy was initialized
108-
// if true involk render Tree with snapshot
99+
// if true invoke render Tree with snapshot
109100
const renderTree = () => {
110101
if (hierarchy) {
111102
return <Tree snapshot={snapshot} />;
112103
}
113-
return <div className="noState">{NO_STATE_MSG}</div>;
104+
return <div className='noState'>{NO_STATE_MSG}</div>;
114105
};
115106

116107
const renderPerfView = () => {
117108
if (hierarchy) {
118109
return (
119-
<ParentSize>{({ width, height }) =>
120-
<PerformanceVisx
121-
width={width}
122-
height={height}
123-
snapshots={snapshots}
124-
hierarchy={hierarchy}
125-
/>}
110+
<ParentSize>
111+
{({ width, height }) => (
112+
<PerformanceVisx
113+
width={width}
114+
height={height}
115+
snapshots={snapshots}
116+
hierarchy={hierarchy}
117+
/>
118+
)}
126119
</ParentSize>
127-
120+
128121
// <PerfView
129122
// viewIndex={viewIndex}
130123
// snapshots={snapshots}
@@ -134,55 +127,55 @@ const StateRoute = (props: StateRouteProps) => {
134127
// />
135128
);
136129
}
137-
return <div className="noState">{NO_STATE_MSG}</div>;
130+
return <div className='noState'>{NO_STATE_MSG}</div>;
138131
};
139132

140133
return (
141134
<Router>
142-
<div className="navbar">
135+
<div className='navbar'>
143136
<NavLink
144-
className="router-link"
145-
activeClassName="is-active"
137+
className='router-link'
138+
activeClassName='is-active'
146139
exact
147-
to="/"
140+
to='/'
148141
>
149142
Tree
150143
</NavLink>
151144
<NavLink
152-
className="router-link"
153-
activeClassName="is-active"
154-
to="/history"
145+
className='router-link'
146+
activeClassName='is-active'
147+
to='/history'
155148
>
156149
History
157150
</NavLink>
158-
<NavLink className="router-link" activeClassName="is-active" to="/map">
151+
<NavLink className='router-link' activeClassName='is-active' to='/map'>
159152
Map
160153
</NavLink>
161154

162155
{isRecoil && (
163156
<NavLink
164-
className="router-link"
165-
activeClassName="is-active"
166-
to="/relationship"
157+
className='router-link'
158+
activeClassName='is-active'
159+
to='/relationship'
167160
>
168161
AtomsRecoil
169162
</NavLink>
170163
)}
171164

172165
<NavLink
173-
className="router-link"
174-
activeClassName="is-active"
175-
to="/performance"
166+
className='router-link'
167+
activeClassName='is-active'
168+
to='/performance'
176169
>
177170
Performance
178171
</NavLink>
179172
</div>
180173
<Switch>
181-
<Route path="/map" render={renderComponentMap} />
182-
<Route path="/history" render={renderHistory} />
183-
<Route path="/relationship" render={renderAtomsRelationship} />
184-
<Route path="/performance" render={renderPerfView} />
185-
<Route path="/" render={renderTree} />
174+
<Route path='/map' render={renderComponentMap} />
175+
<Route path='/history' render={renderHistory} />
176+
<Route path='/relationship' render={renderAtomsRelationship} />
177+
<Route path='/performance' render={renderPerfView} />
178+
<Route path='/' render={renderTree} />
186179
</Switch>
187180
</Router>
188181
);

src/app/components/getLinkComponent.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
LinkRadialLine,
1414
} from '@visx/shape';
1515

16+
// conditional's to adjust the controls for the componentMap drop downs
1617
export default function getLinkComponent({
1718
layout,
1819
linkType,
@@ -27,8 +28,6 @@ export default function getLinkComponent({
2728
if (layout === 'polar') {
2829
if (linkType === 'step') {
2930
LinkComponent = LinkRadialStep;
30-
} else if (linkType === 'curve') {
31-
LinkComponent = LinkRadialCurve;
3231
} else if (linkType === 'line') {
3332
LinkComponent = LinkRadialLine;
3433
} else {
@@ -37,17 +36,13 @@ export default function getLinkComponent({
3736
} else if (orientation === 'vertical') {
3837
if (linkType === 'step') {
3938
LinkComponent = LinkVerticalStep;
40-
} else if (linkType === 'curve') {
41-
LinkComponent = LinkVerticalCurve;
4239
} else if (linkType === 'line') {
4340
LinkComponent = LinkVerticalLine;
4441
} else {
4542
LinkComponent = LinkVertical;
4643
}
4744
} else if (linkType === 'step') {
4845
LinkComponent = LinkHorizontalStep;
49-
} else if (linkType === 'curve') {
50-
LinkComponent = LinkHorizontalCurve;
5146
} else if (linkType === 'line') {
5247
LinkComponent = LinkHorizontalLine;
5348
} else {

0 commit comments

Comments
 (0)