Skip to content

Commit 1a919e5

Browse files
more pseudocode
1 parent 101d3c4 commit 1a919e5

14 files changed

+138
-121
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export default function ComponentMap({
3535
width: totalWidth,
3636
height: totalHeight,
3737
margin = defaultMargin,
38-
currentSnapshot,
38+
currentSnapshot, // from 'tabs[currentTab].stateSnapshot object in 'MainContainer'
3939
}: LinkTypesProps): JSX.Element {
40-
// importing custom hooks for the selection tabs.
40+
4141
const [layout, setLayout] = useState('cartesian');
4242
const [orientation, setOrientation] = useState('vertical');
4343
const [linkType, setLinkType] = useState('diagonal');
@@ -47,7 +47,7 @@ export default function ComponentMap({
4747
const toolTipTimeoutID = useRef(null);
4848

4949
useEffect(() => {
50-
dispatch(setCurrentTabInApp('map'));
50+
dispatch(setCurrentTabInApp('map')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'map' to facilitate render.
5151
}, [dispatch]);
5252

5353
// setting the margins for the Map to render in the tab window.

src/app/components/StateRoute/ComponentMap/LinkControls.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ const collectNodes = (node: Node): void => {
3636
};
3737

3838
export default function LinkControls({
39-
layout,
40-
linkType,
41-
stepPercent,
42-
setLayout,
43-
setOrientation,
44-
setLinkType,
45-
setStepPercent,
46-
setSelectedNode,
39+
layout, // from the layout local state (initially 'cartesian') in 'ComponentMap'
40+
linkType, // from linkType local state (initially 'vertical') in 'ComponentMap'
41+
stepPercent, // from stepPercent local state (initially '10') in 'ComponentMap'
42+
setLayout, // from the layout local state in 'ComponentMap'
43+
setOrientation, // from the orientation local state in 'ComponentMap'
44+
setLinkType, // from the linkType local state in 'ComponentMap'
45+
setStepPercent, // from the stepPercent local state in 'ComponentMap'
46+
setSelectedNode, // from the selectedNode local state in 'ComponentMap'
4747
snapShots,
4848
}: LinkControlProps): JSX.Element {
4949
collectNodes(snapShots);

src/app/components/StateRoute/ComponentMap/ToolTipDataDisplay.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ const colors = {
1414
base06: '#b9b6b0',
1515
base07: '#e7e9db',
1616
base08: '#ef6155',
17-
//base09 is orange for booleans and numbers. This base in particular fails to match the entered color.
18-
base09: '#824508',
19-
// base09: '#592bad', // alternative purple
17+
base09: '#824508', //base09 is orange for booleans and numbers. This base in particular fails to match the entered color.
18+
// base09: '#592bad', // alternative purple
2019
base0A: '#fec418',
2120
base0B: '#48b685',
2221
base0C: '#5bc4bf',
@@ -27,17 +26,17 @@ const colors = {
2726

2827

2928
const ToolTipDataDisplay = ({ containerName, dataObj }) => {
30-
//The key:value properties of printableObject will be rendered in the JSON Tree
31-
const printableObject = {}
32-
//If state is null rather than an object, print "State: null" in tooltip
33-
if (!dataObj) {
29+
30+
const printableObject = {} // The key:value properties of printableObject will be rendered in the JSON Tree
31+
32+
if (!dataObj) { // If state is null rather than an object, print "State: null" in tooltip
3433
printableObject[containerName] = dataObj;
3534
} else {
36-
// Props often contain circular references and messages from the backend must be sent as JSON
37-
// objects (strings). JSON objects can't contain circular ref's, so the backend filters out problematic
38-
// values by stringifying the values of object properties and ignoring any values that fail the
39-
// conversion due to a circular ref.
40-
// The following logic converts these values back to JS so they display clearly and are collapsible.
35+
/*
36+
Props often contain circular references.
37+
Messages from the backend must be sent as JSON objects (strings).
38+
JSON objects can't contain circular ref's, so the backend filters out problematic values by stringifying the values of object properties and ignoring any values that fail the conversion due to a circular ref. The following logic converts these values back to JS so they display clearly and are collapsible.
39+
*/
4140
const data = {};
4241
for (const key in dataObj) {
4342
if (typeof dataObj[key] === 'string') {
@@ -50,8 +49,9 @@ const ToolTipDataDisplay = ({ containerName, dataObj }) => {
5049
data[key] = dataObj[key];
5150
}
5251
}
53-
// Adds container name (State, Props, future different names for hooks) at top of object
54-
// so everything nested in it will collapse when you click on it.
52+
/*
53+
Adds container name (State, Props, future different names for hooks) at top of object so everything nested in it will collapse when you click on it.
54+
*/
5555
printableObject[containerName] = data
5656
}
5757

@@ -61,10 +61,10 @@ const ToolTipDataDisplay = ({ containerName, dataObj }) => {
6161
key={`${containerName}-data-container`}
6262
>
6363
<JSONTree
64-
data={printableObject}
65-
theme={{ extend: colors, tree: () => ({ className: `tooltipData-JSONTree` }) }}
66-
shouldExpandNode={() => true}
67-
hideRoot={true}
64+
data={printableObject} // data to be rendered, a snapshot object
65+
theme={{ extend: colors, tree: () => ({ className: `tooltipData-JSONTree` }) }} // theme set to a base16 theme that has been extended to include "className: 'json-tree'"
66+
shouldExpandNodeInitially={() => true} // determines if node should be expanded when it first renders (root is expanded by default)
67+
hideRoot={true} // hides the root node
6868
/>
6969
</div>
7070
)

src/app/components/StateRoute/ComponentMap/getLinkComponent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {
1414
} from '@visx/shape';
1515
import { LinkComponent } from '../../../FrontendTypes'
1616

17+
/*
18+
19+
*/
20+
1721
export default function getLinkComponent({
1822
layout,
1923
linkType,

src/app/components/StateRoute/History.tsx

Lines changed: 76 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,122 +41,129 @@ function History(props: Record<string, unknown>): JSX.Element {
4141
const innerWidth: number = totalWidth - margin.left - margin.right;
4242
const innerHeight: number = totalHeight - margin.top - margin.bottom - 60;
4343

44-
function labelCurrentNode(d3root) {
45-
if (d3root.data.index === currLocation.index) {
46-
let currNode = d3root;
47-
while (currNode.parent) {
48-
currNode.color = '#999';
49-
currNode = currNode.parent;
44+
function labelCurrentNode(d3root) { // iterates through the parents of a node and applies a color property
45+
if (d3root.data.index === currLocation.index) { // node.data aka d3root.data allows us to access associated node data. So if node.index === currLocation.index...
46+
47+
let currNode = d3root; // make our input the currNode
48+
49+
while (currNode.parent) { // while there are parent nodes
50+
currNode.color = '#999'; // change or give the node a color property
51+
currNode = currNode.parent; // change currNode to the parent
5052
}
51-
currNode.color = '#999';
52-
return d3root;
53+
54+
currNode.color = '#999'; // when there are no more parent nodes, change or give the last node a color property
55+
56+
return d3root; // return the modified d3root
5357
}
58+
5459
let found;
55-
if (!d3root.children) {
56-
return found;
60+
61+
if (!d3root.children) { // if root has no children array
62+
return found; // return undefined
5763
}
58-
d3root.children.forEach((child) => {
59-
if (!found) {
60-
found = labelCurrentNode(child);
64+
65+
d3root.children.forEach((child) => { // for each child node within the children array
66+
if (!found) { // if found is undefined
67+
found = labelCurrentNode(child); //
6168
}
6269
});
63-
return found;
70+
return found; // return's the found child node
6471
}
6572

66-
// findDiff function uses same logic as ActionContainer.tsx
67-
function findDiff(index) {
68-
const statelessCleanning = (obj: {
73+
function findDiff(index) { // determines the difference between our current index and the index-1 snapshot and produces an html string
74+
const statelessCleaning = (obj: { //'statelessCleaning' functions in the same way as the 'statelessCleaning' function in Diff.tsx
6975
name?: string;
7076
componentData?: object;
7177
state?: string | any;
7278
stateSnaphot?: object;
7379
children?: any[];
7480
}) => {
75-
const newObj = { ...obj };
76-
if (newObj.name === 'nameless') {
77-
delete newObj.name;
81+
const newObj = { ...obj }; // duplicate our input object into a new object
82+
83+
if (newObj.name === 'nameless') { // if our new object's name is nameless
84+
delete newObj.name; // delete the name property
7885
}
79-
if (newObj.componentData) {
80-
delete newObj.componentData;
86+
if (newObj.componentData) { // if our new object has a componentData property
87+
delete newObj.componentData; // delete the componentData property
8188
}
82-
if (newObj.state === 'stateless') {
83-
delete newObj.state;
89+
if (newObj.state === 'stateless') { // if if our new object's state is stateless
90+
delete newObj.state; // delete the state property
8491
}
85-
if (newObj.stateSnaphot) {
86-
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
92+
if (newObj.stateSnaphot) { // if our new object has a stateSnaphot property
93+
newObj.stateSnaphot = statelessCleaning(obj.stateSnaphot); // run statelessCleaning on the stateSnapshot
8794
}
88-
if (newObj.children) {
95+
96+
if (newObj.children) { // if our new object has a children property
8997
newObj.children = [];
90-
if (obj.children.length > 0) {
98+
if (obj.children.length > 0) { // and if our input object's children property is non-empty, go through each children object from our input object and determine, if the object being iterated on either has a stateless state or has a children array with a non-zero amount of objects. Objects that fulfill the above that need to be cleaned through statelessCleaning. Those that are cleaned through this process are then pushed to the new object's children array.
9199
obj.children.forEach((element: { state?: object | string; children?: [] }) => {
92100
if (element.state !== 'stateless' || element.children.length > 0) {
93-
const clean = statelessCleanning(element);
101+
const clean = statelessCleaning(element);
94102
newObj.children.push(clean);
95103
}
96104
});
97105
}
98106
}
99-
return newObj;
107+
return newObj; // return the cleaned state snapshot(s)
100108
};
101109

102-
function findStateChangeObj(delta, changedState = []) {
103-
if (!delta.children && !delta.state) {
104-
return changedState;
110+
function findStateChangeObj(delta, changedState = []) { // function determines whether delta has resulted in a changedState. Function would return an empty array if there were no changes to state and an array of objects that changed state.
111+
if (!delta.children && !delta.state) { // if delta doesn't have a children property or a state property
112+
return changedState; // returns an empty array
105113
}
106-
if (delta.state && delta.state[0] !== 'stateless') {
107-
changedState.push(delta.state);
114+
115+
if (delta.state && delta.state[0] !== 'stateless') { // ignore stateless delta objects
116+
changedState.push(delta.state); // and push stateful delta objects to changedState
108117
}
109-
if (!delta.children) {
110-
return changedState;
118+
119+
if (!delta.children) { // if the delta doesn't have any children
120+
return changedState; // return the changedState array with any and all stateful delta objects.
111121
}
112-
Object.keys(delta.children).forEach((child) => {
122+
123+
Object.keys(delta.children).forEach((child) => { // but if the delta object did have children, we iterate through each child object
113124
// if (isNaN(child) === false) {
114-
changedState.push(...findStateChangeObj(delta.children[child]));
125+
changedState.push(...findStateChangeObj(delta.children[child])); // recursively call this function on each child object. Push every 'stateful' child into the changedState array.
115126
// }
116127
});
117-
return changedState;
128+
129+
return changedState; // return the changedState array with any and all stateful delta objects.
118130
}
119131

120-
const delta = diff(
121-
statelessCleanning(snapshots[index - 1]),
122-
statelessCleanning(snapshots[index]),
132+
const delta = diff( // 'diff' function from 'jsondiffpatch' returns the difference in state between the (snapshot that occurred before the indexed snapshot) and the (indexed snapshot).
133+
statelessCleaning(snapshots[index - 1]),
134+
statelessCleaning(snapshots[index]),
123135
);
124-
const changedState = findStateChangeObj(delta);
125-
// figured out the formatting for hover, applying diff.csss
126-
const html = formatters.html.format(changedState[0]);
127-
// uneeded, not returning a react component in SVG div
128-
// const output = ReactHtmlParser(html);
129-
return html;
136+
137+
const changedState = findStateChangeObj(delta); // determines if delta had any stateful changes
138+
const html = formatters.html.format(changedState[0]); // formats the difference into html string
139+
return html; // return html string
130140
}
131141

132142
/**
133143
* @method makeD3Tree :Creates a new D3 Tree
134144
*/
135145

136146
const makeD3Tree = () => {
137-
const svg = d3.select(svgRef.current);
138-
svg.selectAll('*').remove(); // Clear svg content before adding new elements
139-
const tree = (data) => {
140-
const treeRoot = d3.hierarchy(data);
141-
return d3.tree().size([innerWidth, innerHeight])(treeRoot);
147+
const svg = d3.select(svgRef.current); // d3.select Selects the first element/node that matches svgRef.current. If no element/node match returns an empty selection. If multiple elements/nodes match the selector, only the first matching element/node (in document order) will be selected.
148+
svg.selectAll('*').remove(); // Selects all elements. The elements will be selected in document order (top-to-bottom). We then remove the selected elements/nodes from the DOM
149+
150+
const tree = (data) => { // function that takes in data and turns it into a d3 tree.
151+
const treeRoot = d3.hierarchy(data); // 'd3.hierarchy' constructs a root node from the specified hierarchical data.
152+
return d3.tree().size([innerWidth, innerHeight])(treeRoot); // d3.tree creates a new tree layout with a size option of innerWidth (~line 41) and innerHeight (~line 42). We specify our new tree layout's root as 'treeRoot' which assigns an x and y property to each node to represent an [x, y] coordinate system.
142153
};
143-
const d3root = tree(root);
144154

145-
const currNode = labelCurrentNode(d3root);
155+
const d3root = tree(root); // create a d3. tree from our root
156+
const currNode = labelCurrentNode(d3root); // iterate through our nodes and apply a color property
146157

147158
const g = svg
148-
.append('g')
159+
.append('g') // create an element 'g' on svg
149160
.attr(
150161
'transform',
151162
`translate(${margin.left},${d3root.height === 0 ? totalHeight / 2 : margin.top})`,
152163
);
153164

154165
const link = g
155-
.selectAll('.link')
156-
// root.links() gets an array of all the links,
157-
// where each element is an object containing a
158-
// source property, which represents the link's source node,
159-
// and a target property, which represents the link's target node.
166+
.selectAll('.link') // select all elements that contain the string '.link' and return a selection
160167
.data(d3root.descendants().slice(1))
161168
.enter()
162169
.append('path')
@@ -179,12 +186,11 @@ function History(props: Record<string, unknown>): JSX.Element {
179186
.on('click', (event, d) => {
180187
dispatch(changeView(d.data.index));
181188
dispatch(changeSlider(d.data.index));
189+
/*
190+
created popup div and appended it to display div(returned in this function)
182191
183-
// created popup div and appended it to display div(returned in this function)
184-
// D3 doesn't utilize z-index for priority,
185-
// rather decides on placement by order of rendering
186-
// needed to define the return div with a className to have a target to append to
187-
// with the correct level of priority
192+
D3 doesn't utilize z-index for priority, rather decides on placement by order of rendering needed to define the return div with a className to have a target to append to with the correct level of priority
193+
*/
188194
function renderToolTip() {
189195
const [x, y] = d3.pointer(event);
190196
const div = d3
@@ -271,11 +277,12 @@ function History(props: Record<string, unknown>): JSX.Element {
271277

272278
useEffect(() => {
273279
makeD3Tree();
274-
}, [root, currLocation]);
280+
}, [root, currLocation]); // if the 'root' or 'currLocation' changes, re-build the D3 Tree
275281

276282
useEffect(() => {
277-
dispatch(setCurrentTabInApp('history'));
283+
dispatch(setCurrentTabInApp('history')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'webmetrics' to facilitate render.
278284
}, []);
285+
279286
// then rendering each node in History tab to render using D3, which will share area with LegendKey
280287
return (
281288
<div className='display'>

src/app/components/StateRoute/PerformanceVisx/BarGraphComparison.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
4949
const [open, setOpen] = React.useState(false);
5050
const [picOpen, setPicOpen] = React.useState(false);
5151
useEffect(() => {
52-
dispatch(setCurrentTabInApp('performance-comparison'));
52+
dispatch(setCurrentTabInApp('performance-comparison')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance-comparison' to facilitate render.
5353
}, [dispatch]);
5454

5555
const currentIndex: number = tabs[currentTab].sliderIndex;

src/app/components/StateRoute/PerformanceVisx/BarGraphComparisonActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const BarGraphComparisonActions = (props: BarGraphComparisonAction) => {
3939
const [setOpen] = React.useState(false);
4040
const [setPicOpen] = React.useState(false);
4141
useEffect(() => {
42-
dispatch(setCurrentTabInApp('performance-comparison'));
42+
dispatch(setCurrentTabInApp('performance-comparison')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance-comparison' to facilitate render.
4343
}, []);
4444

4545
const { tooltipOpen, tooltipLeft, tooltipTop, tooltipData, hideTooltip, showTooltip } =

src/app/components/StateRoute/PerformanceVisx/PerformanceVisx.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
164164
const [snapshot, setSnapshot] = useState('All Snapshots');
165165
// snapshots = 3.0
166166
useEffect(() => {
167-
dispatch(setCurrentTabInApp('performance'));
167+
dispatch(setCurrentTabInApp('performance')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance' to facilitate render.
168168
}, [dispatch]);
169169

170170
// Creates the actions array used to populate the compare actions dropdown

src/app/components/StateRoute/PerformanceVisx/RenderingFrequency.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const RenderingFrequency = (props) => {
99
const perfData = props.data;
1010
const [store, dispatch] = useStoreContext();
1111
useEffect(() => {
12-
dispatch(setCurrentTabInApp('performance-comparison'));
12+
dispatch(setCurrentTabInApp('performance-comparison')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance-comparison' to facilitate render.
1313
}, []);
1414
return (
1515
<div>

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const StateRoute = (props: StateRouteProps) => {
5959
<ParentSize>
6060
{({ width, height }) => (
6161
<History
62-
width={width}
62+
width={width}
6363
height={height}
6464
hierarchy={hierarchy}
6565
dispatch={dispatch}

0 commit comments

Comments
 (0)