Skip to content

Commit 46b11b1

Browse files
authored
Merge pull request #2 from oslabs-beta/andy
added some console.logs to better see the flow
2 parents 2ce1674 + 17dd865 commit 46b11b1

File tree

9 files changed

+221
-209
lines changed

9 files changed

+221
-209
lines changed

src/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ The general flow of data is described in the following steps:
7070
![GENERAL DATA FLOW](../assets/dataflow.jpg)
7171

7272
1. When the background bundle is loaded by the browser, it executes a script injection into the dom. (see section on *backend*). This script uses a technique called [throttle](https://medium.com/@bitupon.211/debounce-and-throttle-160affa5457b) to send state data from the app to the content script every specified milliseconds (in our case, this interval is 70ms).
73+
<!-- CHECK LINE 496 IN LINKFIBER.TS -->
74+
7375

7476
2. The content script always listens for messages being passed from the extension's target application. Upon receiving data from the target app, the content script will immediately forward this data to the background script which then updates an object called `tabsObj`. Each time `tabsObj` is updated, its latest version will be passed to Reactime, where it is processed for displaying to the user by the *app* folder scripts.
7577

src/app/components/ComponentMap.tsx

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ import { Group } from '@visx/group';
44
import { hierarchy, Tree } from '@visx/hierarchy';
55
import { LinearGradient } from '@visx/gradient';
66
import { pointRadial } from 'd3-shape';
7-
import useForceUpdate from './useForceUpdate';
8-
import LinkControls from './LinkControls';
9-
import getLinkComponent from './getLinkComponent';
107
import { localPoint } from '@visx/event';
118
import {
129
useTooltip,
1310
useTooltipInPortal,
1411
TooltipWithBounds,
1512
defaultStyles,
1613
} from '@visx/tooltip';
14+
import useForceUpdate from './useForceUpdate';
15+
import LinkControls from './LinkControls';
16+
import getLinkComponent from './getLinkComponent';
1717
import { onHover, onHoverExit } from '../actions/actions';
1818
import { useStoreContext } from '../store';
1919

2020
const root = hierarchy({
21-
name: "root",
21+
name: 'root',
2222
children: [
23-
{ name: "child #1" },
23+
{ name: 'child #1' },
2424
{
25-
name: "child #2",
25+
name: 'child #2',
2626
children: [
27-
{ name: "grandchild #1" },
28-
{ name: "grandchild #2" },
29-
{ name: "grandchild #3" },
27+
{ name: 'grandchild #1' },
28+
{ name: 'grandchild #2' },
29+
{ name: 'grandchild #3' },
3030
],
3131
},
3232
],
@@ -39,7 +39,9 @@ interface TreeNode {
3939

4040
type HierarchyNode = HierarchyPointNode<TreeNode>;
4141

42-
const defaultMargin = { top: 30, left: 30, right: 55, bottom: 70 };
42+
const defaultMargin = {
43+
top: 30, left: 30, right: 55, bottom: 70,
44+
};
4345

4446
export type LinkTypesProps = {
4547
width: number;
@@ -53,17 +55,17 @@ export default function ComponentMap({
5355
width: totalWidth,
5456
height: totalHeight,
5557
margin = defaultMargin,
56-
snapshots: snapshots,
58+
snapshots,
5759
}: LinkTypesProps) {
5860
const [{ tabs, currentTab }, dispatch] = useStoreContext();
5961
// 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.
6062
const lastNode = snapshots.length - 1;
6163
const data: {} = snapshots[lastNode];
6264

6365
// importing custom hooks for the selection tabs.
64-
const [layout, setLayout] = useState("cartesian");
65-
const [orientation, setOrientation] = useState("horizontal");
66-
const [linkType, setLinkType] = useState("diagonal");
66+
const [layout, setLayout] = useState('cartesian');
67+
const [orientation, setOrientation] = useState('horizontal');
68+
const [linkType, setLinkType] = useState('diagonal');
6769
const [stepPercent, setStepPercent] = useState(10);
6870

6971
// Declared this variable and assigned it to the useForceUpdate function that forces a state to change causing that component to re-render and display on the map
@@ -79,7 +81,7 @@ export default function ComponentMap({
7981

8082
// This sets the starting position for the root node on the maps display. the polar layout sets the root node to the relative center of the display box based on the size of the browser window.
8183
// the else conditional statements determines the root nodes location either in the left middle or top middle of the browser window relative to the size of the browser.
82-
if (layout === "polar") {
84+
if (layout === 'polar') {
8385
origin = {
8486
x: innerWidth / 2,
8587
y: innerHeight / 2,
@@ -88,7 +90,7 @@ export default function ComponentMap({
8890
sizeHeight = Math.min(innerWidth, innerHeight) / 2;
8991
} else {
9092
origin = { x: 0, y: 0 };
91-
if (orientation === "vertical") {
93+
if (orientation === 'vertical') {
9294
sizeWidth = innerWidth;
9395
sizeHeight = innerHeight;
9496
} else {
@@ -97,7 +99,7 @@ export default function ComponentMap({
9799
}
98100
}
99101

100-
//Tooltip stuff:
102+
// Tooltip stuff:
101103
const {
102104
tooltipData,
103105
tooltipLeft,
@@ -122,7 +124,7 @@ export default function ComponentMap({
122124
fontFamily: 'Roboto',
123125
};
124126

125-
const formatRenderTime = (time) => {
127+
const formatRenderTime = time => {
126128
time = time.toFixed(3);
127129
return `${time} ms `;
128130
};
@@ -147,11 +149,11 @@ export default function ComponentMap({
147149
<rect width={totalWidth} height={totalHeight} rx={14} fill="#242529" />
148150
<Group top={margin.top} left={margin.left}>
149151
<Tree
150-
root={hierarchy(data, (d) => (d.isExpanded ? null : d.children))}
152+
root={hierarchy(data, d => (d.isExpanded ? null : d.children))}
151153
size={[sizeWidth, sizeHeight]}
152154
separation={(a, b) => (a.parent === b.parent ? 1 : 0.5) / a.depth}
153155
>
154-
{(tree) => (
156+
{tree => (
155157
<Group top={origin.y} left={origin.x}>
156158
{tree.links().map((link, i) => (
157159
<LinkComponent
@@ -165,8 +167,8 @@ export default function ComponentMap({
165167
))}
166168

167169
{tree.descendants().map((node, key) => {
168-
const widthFunc = (name) => {
169-
let nodeLength = name.length;
170+
const widthFunc = name => {
171+
const nodeLength = name.length;
170172
if (nodeLength < 5) return nodeLength + 40;
171173
if (nodeLength < 10) return nodeLength + 60;
172174
return nodeLength + 70;
@@ -176,28 +178,27 @@ export default function ComponentMap({
176178

177179
let top: number;
178180
let left: number;
179-
if (layout === "polar") {
181+
if (layout === 'polar') {
180182
const [radialX, radialY] = pointRadial(node.x, node.y);
181183
top = radialY;
182184
left = radialX;
183-
} else if (orientation === "vertical") {
185+
} else if (orientation === 'vertical') {
184186
top = node.y;
185187
left = node.x;
186188
} else {
187189
top = node.x;
188190
left = node.y;
189191
}
190192

191-
//mousing controls & Tooltip display logic
192-
const handleMouseOver = (event) => {
193+
// mousing controls & Tooltip display logic
194+
const handleMouseOver = event => {
193195
() => dispatch(onHover(node.data.rtid));
194196
const coords = localPoint(
195197
event.target.ownerSVGElement,
196-
event
198+
event,
197199
);
198-
const tooltipObj = Object.assign({}, node.data);
199-
if (typeof tooltipObj.state === 'object')
200-
tooltipObj.state = 'stateful';
200+
const tooltipObj = { ...node.data };
201+
if (typeof tooltipObj.state === 'object') tooltipObj.state = 'stateful';
201202
showTooltip({
202203
tooltipLeft: coords.x,
203204
tooltipTop: coords.y,
@@ -218,25 +219,25 @@ export default function ComponentMap({
218219
}}
219220
/>
220221
)}
221-
{/* This creates the rectangle boxes for each component and sets it relative position to other parent nodes of the same level.*/}
222+
{/* This creates the rectangle boxes for each component and sets it relative position to other parent nodes of the same level. */}
222223
{node.depth !== 0 && (
223224
<rect
224225
height={height}
225226
width={width}
226227
y={-height / 2}
227228
x={-width / 2}
228-
fill={node.children ? "#161521" : "#62d6fb"}
229-
stroke={node.children ? "#62d6fb" : "#161521"}
229+
fill={node.children ? '#161521' : '#62d6fb'}
230+
stroke={node.children ? '#62d6fb' : '#161521'}
230231
strokeWidth={1}
231-
strokeDasharray={node.children ? "0" : "2,2"}
232+
strokeDasharray={node.children ? '0' : '2,2'}
232233
strokeOpacity="1"
233234
rx={node.children ? 4 : 10}
234235
onClick={() => {
235236
node.data.isExpanded = !node.data.isExpanded;
236237
forceUpdate();
237238
}}
238-
//Tooltip event handlers
239-
//test feature
239+
// Tooltip event handlers
240+
// test feature
240241
onMouseOver={handleMouseOver}
241242
onMouseOut={hideTooltip}
242243
onMouseEnter={() => dispatch(onHover(node.data.rtid))}
@@ -249,13 +250,13 @@ export default function ComponentMap({
249250
fontSize={10}
250251
fontFamily="Roboto"
251252
textAnchor="middle"
252-
style={{ pointerEvents: "none" }}
253+
style={{ pointerEvents: 'none' }}
253254
fill={
254255
node.depth === 0
255-
? "#161521"
256+
? '#161521'
256257
: node.children
257-
? "white"
258-
: "#161521"
258+
? 'white'
259+
: '#161521'
259260
}
260261
>
261262
{node.data.name}
@@ -278,13 +279,19 @@ export default function ComponentMap({
278279
>
279280
<div style={{}}>
280281
{' '}
281-
<strong>{tooltipData.name}</strong>{' '}
282+
<strong>{tooltipData.name}</strong>
283+
{' '}
284+
</div>
285+
<div>
286+
State:
287+
{tooltipData.state}
282288
</div>
283-
<div>State: {tooltipData.state}</div>
284289
<div>
285290
{' '}
286-
Render time:{' '}
287-
{formatRenderTime(tooltipData.componentData.actualDuration)}{' '}
291+
Render time:
292+
{' '}
293+
{formatRenderTime(tooltipData.componentData.actualDuration)}
294+
{' '}
288295
</div>
289296
</TooltipInPortal>
290297
)}

0 commit comments

Comments
 (0)