Skip to content

Commit 4369dd2

Browse files
committed
adjusting text spatial arrangement
2 parents f67448c + 6986fac commit 4369dd2

File tree

12 files changed

+108
-67
lines changed

12 files changed

+108
-67
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage
88
src/extension/build.zip
99
src/extension/build.crx
1010
src/extension/build/key.pem
11+
package/__tests__

package/linkFiber.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
// links component state tree to library
55
// changes the setState method to also update our snapshot
66
const Tree = require('./tree');
7-
const astParser = require('./astParser.js');
7+
const astParser = require('./astParser');
8+
const { saveState } = require('./masterState');
89

910
module.exports = (snap, mode) => {
1011
let fiberRoot = null;
11-
let astHooks;
12+
let astHooks;
1213

1314
function sendSnapshot() {
1415
// don't send messages while jumping or while paused
@@ -45,14 +46,15 @@ module.exports = (snap, mode) => {
4546

4647
function changeUseState(component) {
4748
if (component.queue.dispatch.linkFiberChanged) return;
48-
// store the original dispatch function definition
49-
const oldDispatch = component.queue.dispatch.bind(component.queue);;
49+
// store the original dispatch function definition
50+
const oldDispatch = component.queue.dispatch.bind(component.queue);
5051
// redefine the dispatch function so we can inject our code
5152
component.queue.dispatch = (fiber, queue, action) => {
5253
// don't do anything if state is locked
5354
if (mode.locked && !mode.jumping) return;
54-
oldDispatch(fiber, queue, action);
55+
//oldDispatch(fiber, queue, action);
5556
setTimeout(() => {
57+
oldDispatch(fiber, queue, action);
5658
updateSnapShotTree();
5759
sendSnapshot();
5860
}, 100);
@@ -68,9 +70,10 @@ module.exports = (snap, mode) => {
6870
let index = 0;
6971
astHooks = Object.values(astHooks);
7072
// while memoizedState is truthy, save the value to the object
71-
while (memoizedState && astHooks) {
73+
while (memoizedState) {
7274
changeUseState(memoizedState);
73-
memoized[astHooks[index]] = memoizedState.memoizedState;
75+
//memoized[astHooks[index]] = memoizedState.memoizedState;
76+
memoized[astHooks[index]] = memoizedState.memoizedState;
7477
// Reassign memoizedState to its next value
7578
memoizedState = memoizedState.next;
7679
// Increment the index by 2
@@ -98,7 +101,7 @@ module.exports = (snap, mode) => {
98101
changeSetState(stateNode);
99102
}
100103
// Check if the component uses hooks
101-
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
104+
if (memoizedState && memoizedState.hasOwnProperty('baseState')) {
102105
// Add a traversed property and initialize to the evaluated result
103106
// of invoking traverseHooks, and reassign nextTree
104107
memoizedState.traversed = traverseHooks(memoizedState);
@@ -111,7 +114,8 @@ module.exports = (snap, mode) => {
111114

112115
return tree;
113116
}
114-
117+
// runs when page initially loads
118+
// but skips 1st hook click
115119
function updateSnapShotTree() {
116120
const { current } = fiberRoot;
117121
snap.tree = createTree(current);
@@ -125,9 +129,12 @@ module.exports = (snap, mode) => {
125129
// only assign internal rootp if it actually exists
126130
fiberRoot = _internalRoot || _reactRootContainer;
127131
// If hooks are implemented, traverse through the source code
128-
if (entryFile) astHooks = astParser(entryFile);
129-
130-
updateSnapShotTree();
132+
// Save the getter/setter combo for timeJump
133+
if (entryFile) {
134+
astHooks = astParser(entryFile);
135+
saveState(astHooks);
136+
}
137+
updateSnapShotTree();
131138
// send the initial snapshot once the content script has started up
132139
window.addEventListener('message', ({ data: { action } }) => {
133140
if (action === 'contentScriptStarted') sendSnapshot();

package/masterState.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Export two functions that either saves the AST state object into an array
2+
// or returns the array for use
3+
const masterState = [];
4+
5+
module.exports = {
6+
saveState: state => {
7+
for (const key in state) {
8+
masterState.push(state[key]);
9+
}
10+
return masterState;
11+
},
12+
returnState: () => masterState
13+
};

package/timeJump.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-param-reassign */
22
// traverses given tree by accessing children through coords array
3+
const { returnState } = require('./masterState');
4+
35
function traverseTree(tree, coords) {
46
let curr = tree;
57
coords.forEach(coord => {
@@ -21,13 +23,16 @@ module.exports = (origin, mode) => {
2123
});
2224
});
2325
} else {
24-
// if component uses hooks
26+
// if component uses hooks, traverse through the memoize tree
2527
let current = originNode.component;
26-
let index = 1;
27-
// Iterate through the memoized tree
28+
let index = 0;
29+
const hooks = returnState();
30+
// Iterate through the memoize tree
2831
while (current) {
29-
current.queue.dispatch(target.state[`state${index++}`]);
32+
current.queue.dispatch(target.state[hooks[index]]);
33+
// Reassign the current value
3034
current = current.next;
35+
index += 2;
3136
}
3237
}
3338
}

src/app/components/Chart.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class Chart extends Component {
3939

4040
maked3Tree() {
4141
this.removed3Tree();
42-
let width = 960;
43-
let height = 1060;
42+
let width = 900;
43+
let height = 1000;
4444
let chartContainer = d3.select(this.chartRef.current)
4545
.append('svg') // chartContainer is now pointing to svg
4646
.attr('width', width)
@@ -96,7 +96,7 @@ class Chart extends Component {
9696
.attr("x", function (d) {
9797
// this positions how far the text is from leaf nodes (ones without children)
9898
// negative number before the colon moves the text of rightside nodes, positive number moves the text for the leftside nodes
99-
return d.x < Math.PI === !d.children ? -20 : 20;
99+
return d.x < Math.PI === !d.children ? -20 : 23;
100100
})
101101
.attr("text-anchor", function (d) { return d.x < Math.PI === !d.children ? "start" : "end"; })
102102
// this arranges the angle of the text

src/app/components/SwitchState.jsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
import React from 'react';
2-
import Select from 'react-select';
1+
// import React from 'react';
2+
// import Select from 'react-select';
3+
// import Action from './Action';
4+
// import { useStoreContext } from '../store';
35

4-
// SwitchStateDropdown should display options including all
5-
// and specific states being used
6-
// TODO: Need to get the getter name (for functional components)
7-
// and state name for stateful components
8-
const SwitchStateDropdown = () => {
9-
// Requirements:
10-
// Should be able to filter the Actions by the name of the state being changed
11-
// Should consider how to import the state names being changed
12-
// Should display the "All state", as well as specific state names as the options
13-
// When clicked on "All state" >> should display all Actions
14-
// When clicked on a specific "state" >> should only display Actions corresponding to the state
6+
// // SwitchStateDropdown should display options including all
7+
// // and specific states being used
8+
// // TODO: Need to get the getter name (for functional components)
9+
// // and state name for stateful components
10+
// const SwitchStateDropdown = () => {
11+
// const [{ tabs, currentTab}, dispatch] = useStoreContext();
12+
// const { snapshots } = tabs[currentTab];
13+
// // Requirements:
14+
// // Should be able to filter the Actions by the name of the state being changed
15+
// // Should consider how to import the state names being changed
16+
// // Should display the "All state", as well as specific state names as the options
17+
// // When clicked on "All state" >> should display all Actions
18+
// // When clicked on a specific "state" >> should only display Actions corresponding to the state
1519

16-
const sampleDropdown = [
17-
{label: 'Overview'},
18-
{label: 'setUsername'},
19-
{label: 'setPassword'}
20-
];
20+
// // const sampleDropdown = [
21+
// // {label: 'Overview'},
22+
// // {label: 'setUsername'},
23+
// // {label: 'setPassword'}
24+
// // ];
2125

22-
return (
23-
<Select
24-
className="state-dropdown"
25-
placeholder="Choose your state"
26-
options={sampleDropdown}
27-
/>
28-
)
29-
}
26+
// return (
27+
// <Select
28+
// className="state-dropdown"
29+
// placeholder="Choose your state"
30+
// options={sampleDropdown}
31+
// />
32+
// )
33+
// }
3034

31-
export default SwitchStateDropdown;
35+
// export default SwitchStateDropdown;

src/app/containers/ActionContainer.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/no-array-index-key */
22
import React from 'react';
3-
import SwitchStateDropdown from '../components/SwitchState';
3+
//import SwitchStateDropdown from '../components/SwitchState';
44
import Action from '../components/Action';
55

66
import { emptySnapshots } from '../actions/actions';
@@ -33,7 +33,6 @@ function ActionContainer() {
3333
<button className="empty-button" onClick={() => dispatch(emptySnapshots())} type="button">
3434
Empty
3535
</button>
36-
<SwitchStateDropdown />
3736
</div>
3837
<div>{actionsArr}</div>
3938
</div>

src/app/reducers/mainReducer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default (state, action) => produce(state, draft => {
1616
port.postMessage({
1717
action: 'jumpToSnap',
1818
payload: snapshots[newIndex],
19+
index: newIndex,
1920
tabId: currentTab,
2021
});
2122
clearInterval(intervalId);
@@ -31,6 +32,7 @@ export default (state, action) => produce(state, draft => {
3132

3233
port.postMessage({
3334
action: 'jumpToSnap',
35+
index: newIndex,
3436
payload: snapshots[newIndex],
3537
tabId: currentTab,
3638
});
@@ -55,6 +57,7 @@ export default (state, action) => produce(state, draft => {
5557
port.postMessage({
5658
action: 'jumpToSnap',
5759
payload: snapshots[action.payload],
60+
index: action.payload,
5861
tabId: currentTab,
5962
});
6063
tabs[currentTab].sliderIndex = action.payload;

src/app/styles/components/d3graph.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* this represents leaf nodes aka no children */
2+
.node {
3+
cursor: pointer;
4+
}
5+
26
.node circle {
37
fill: #2e3634;
48
}
@@ -18,5 +22,5 @@
1822
fill: none;
1923
stroke: #bfe3da;
2024
stroke-opacity: 0.2;
21-
stroke-width: 50px;
25+
stroke-width: 10px;
2226
}

0 commit comments

Comments
 (0)