Skip to content

Commit 18ae98f

Browse files
authored
Merge pull request #6 from oslabs-beta/freya/filter
reverse filter
2 parents 15a7b4b + 1ba9c8a commit 18ae98f

File tree

3 files changed

+126
-36
lines changed

3 files changed

+126
-36
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,28 @@ import getLinkComponent from './getLinkComponent';
1717
import { onHover, onHoverExit } from '../actions/actions';
1818
import { useStoreContext } from '../store';
1919

20-
const root = hierarchy({
21-
name: 'root',
22-
children: [
23-
{ name: 'child #1' },
24-
{
25-
name: 'child #2',
26-
children: [
27-
{ name: 'grandchild #1' },
28-
{ name: 'grandchild #2' },
29-
{ name: 'grandchild #3' },
30-
],
31-
},
32-
],
33-
});
20+
// const root = hierarchy({
21+
// name: 'root',
22+
// children: [
23+
// { name: 'child #1' },
24+
// {
25+
// name: 'child #2',
26+
// children: [
27+
// { name: 'grandchild #1' },
28+
// { name: 'grandchild #2' },
29+
// { name: 'grandchild #3' },
30+
// ],
31+
// },
32+
// ],
33+
// });
34+
3435
interface TreeNode {
3536
name: string;
3637
isExpanded?: boolean;
3738
children?: TreeNode[];
3839
}
3940

40-
type HierarchyNode = HierarchyPointNode<TreeNode>;
41+
// type HierarchyNode = HierarchyPointNode<TreeNode>;
4142

4243
const defaultMargin = {
4344
top: 30, left: 30, right: 55, bottom: 70,
@@ -69,6 +70,7 @@ export default function ComponentMap({
6970
const [stepPercent, setStepPercent] = useState(10);
7071
const [tooltip, setTooltip] = useState(false);
7172
const [expanded, setExpanded] = useState();
73+
const [selectedNode, setSelectedNode] = useState('root');
7274

7375
// 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
7476
const forceUpdate = useForceUpdate();
@@ -131,6 +133,36 @@ export default function ComponentMap({
131133
return `${time} ms `;
132134
};
133135

136+
//put all nodes into an array
137+
const nodeList = [];
138+
139+
const collectNodes = (node) => {
140+
nodeList.splice(0, nodeList.length);
141+
nodeList.push(node);
142+
for (let i = 0; i < nodeList.length; i++) {
143+
const cur = nodeList[i];
144+
if (cur.children && cur.children.length > 0) {
145+
for (let child of cur.children) {
146+
nodeList.push(child);
147+
}
148+
}
149+
}
150+
console.log('NODELIST in ComponentMap: ', nodeList);
151+
}
152+
collectNodes(snapshots[lastNode]);
153+
154+
//find the node that has been selected and use it as the root
155+
const startNode = null;
156+
const findSelectedNode = () => {
157+
console.log(selectedNode);
158+
for (let node of nodeList) {
159+
if (node.name === selectedNode) {
160+
startNode = node;
161+
}
162+
}
163+
}
164+
findSelectedNode();
165+
134166
// controls for the map
135167
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
136168
return totalWidth < 10 ? null : (
@@ -140,18 +172,22 @@ export default function ComponentMap({
140172
orientation={orientation}
141173
linkType={linkType}
142174
stepPercent={stepPercent}
175+
snapShots={snapshots[lastNode]}
176+
selectedNode={selectedNode}
143177
setLayout={setLayout}
144178
setOrientation={setOrientation}
145179
setLinkType={setLinkType}
146180
setStepPercent={setStepPercent}
181+
setSelectedNode={setSelectedNode}
147182
/>
148183

149184
<svg ref={containerRef} width={totalWidth} height={totalHeight}>
150185
<LinearGradient id="links-gradient" from="#fd9b93" to="#fe6e9e" />
151186
<rect width={totalWidth} height={totalHeight} rx={14} fill="#242529" />
152187
<Group top={margin.top} left={margin.left}>
188+
{console.log('This is the SelectedNode:', selectedNode)}
153189
<Tree
154-
root={hierarchy(data, d => (d.isExpanded ? null : d.children))}
190+
root={hierarchy(startNode || data, d => (d.isExpanded ? null : d.children))}
155191
size={[sizeWidth, sizeHeight]}
156192
separation={(a, b) => (a.parent === b.parent ? 1 : 0.5) / a.depth}
157193
>
@@ -195,8 +231,10 @@ export default function ComponentMap({
195231
// mousing controls & Tooltip display logic
196232
const handleMouseOver = event => {
197233
() => dispatch(onHover(node.data.rtid));
198-
console.log('line 197', event.target.ownerSVGElement);
199-
console.log('line 199: ', node);
234+
console.log('line 197 event.target', event.target.ownerSVGElement);
235+
console.log('line 199 This is DATA: ', data);
236+
console.log('line 200 This is TREE: ', tree);
237+
console.log('line 201 This is NODE: ', node);
200238
const coords = localPoint(
201239
event.target.ownerSVGElement,
202240
event,

src/app/components/LinkControls.tsx

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { List } from '@material-ui/core';
12
import React from 'react';
23
// Font size of the Controls label and Dropdowns
34
const controlStyles = {
@@ -19,24 +20,52 @@ type Props = {
1920
orientation: string;
2021
linkType: string;
2122
stepPercent: number;
23+
selectedNode: string;
2224
setLayout: (layout: string) => void;
2325
setOrientation: (orientation: string) => void;
2426
setLinkType: (linkType: string) => void;
2527
setStepPercent: (percent: number) => void;
28+
setSelectedNode: (selectedNode: string) => void;
29+
snapShots: [];
2630
};
2731

32+
//use BFS to put all the nodes under snapShots(which is the tree node) into an array
33+
const nodeList = [];
34+
35+
const collectNodes = (node) => {
36+
nodeList.splice(0, nodeList.length);
37+
nodeList.push(node);
38+
for (let i = 0; i < nodeList.length; i++) {
39+
const cur = nodeList[i];
40+
if (cur.children && cur.children.length > 0) {
41+
for (let child of cur.children) {
42+
nodeList.push(child);
43+
}
44+
}
45+
}
46+
console.log('NODELIST looks like: ', nodeList);
47+
48+
}
49+
2850
export default function LinkControls({
2951
layout,
3052
orientation,
3153
linkType,
3254
stepPercent,
55+
selectedNode,
3356
setLayout,
3457
setOrientation,
3558
setLinkType,
3659
setStepPercent,
60+
setSelectedNode,
61+
snapShots,
3762
}: Props) {
63+
64+
collectNodes(snapShots);
65+
3866
return (
3967
<div style={controlStyles}>
68+
4069
{/* Controls for the layout selection */}
4170
<label>Layout:</label>
4271
&nbsp;
@@ -50,6 +79,7 @@ export default function LinkControls({
5079
<option value="polar">Polar</option>
5180
</select>
5281
&nbsp;&nbsp;
82+
5383
{/* Controls for the Orientation selection, this dropdown will be disabled when the polar layout is selected as it is not needed */}
5484
<label>Orientation:</label>
5585
&nbsp;
@@ -64,6 +94,7 @@ export default function LinkControls({
6494
<option value="vertical">Vertical</option>
6595
</select>
6696
&nbsp;&nbsp;
97+
6798
{/* Controls for the link selections. */}
6899
<label>Link:</label>
69100
&nbsp;
@@ -77,23 +108,44 @@ export default function LinkControls({
77108
<option value="step">Step</option>
78109
<option value="line">Line</option>
79110
</select>
111+
112+
{/* Controls for the select selections. */}
113+
<label>Select:</label>
114+
&nbsp;
115+
<select
116+
onClick={e => e.stopPropagation()}
117+
onChange={e => {
118+
const val = e.target.value;
119+
console.log("You selected: ", val);
120+
setSelectedNode(e.target.value)
121+
}}
122+
value={selectedNode}
123+
style={dropDownStyle}
124+
>
125+
{console.log("snapShots: ", snapShots)}
126+
127+
{nodeList.map(node => (
128+
<option value={node.name}>{node.name}</option>
129+
))}
130+
</select>
131+
80132
{/* This is the slider control for the step option */}
81133
{linkType === 'step' && layout !== 'polar' && (
82-
<>
83-
&nbsp;&nbsp;
84-
<label>Step:</label>
85-
&nbsp;
86-
<input
87-
onClick={e => e.stopPropagation()}
88-
type="range"
89-
min={0}
90-
max={1}
91-
step={0.1}
92-
onChange={e => setStepPercent(Number(e.target.value))}
93-
value={stepPercent}
94-
disabled={linkType !== 'step' || layout === 'polar'}
95-
/>
96-
</>
134+
<>
135+
&nbsp;&nbsp;
136+
<label>Step:</label>
137+
&nbsp;
138+
<input
139+
onClick={e => e.stopPropagation()}
140+
type="range"
141+
min={0}
142+
max={1}
143+
step={0.1}
144+
onChange={e => setStepPercent(Number(e.target.value))}
145+
value={stepPercent}
146+
disabled={linkType !== 'step' || layout === 'polar'}
147+
/>
148+
</>
97149
)}
98150
</div>
99151
);

src/backend/tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ class Tree {
5353

5454
recoilDomNode: any;
5555

56-
constructor(state: string | {}, name = 'nameless', componentData: {} = {}, rtid: any = null, recoilDomNode:any = null) {
56+
constructor(state: string | {}, name = 'nameless', componentData: {} = {}, rtid: any = null, recoilDomNode: any = null) {
5757
this.state = state === 'root' ? 'root' : serializeState(state);
58-
this.name = name;
58+
this.name = name === "" ? rtid : name;
5959
this.componentData = componentData ? JSON.parse(JSON.stringify(componentData)) : {};
6060
this.children = [];
6161
this.parent = null; // ref to parent so we can add siblings
6262
this.rtid = rtid;
6363
this.recoilDomNode = recoilDomNode;
6464
}
6565

66-
addChild(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode:any): Tree {
66+
addChild(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode: any): Tree {
6767
const newChild: Tree = new Tree(state, name, componentData, rtid, recoilDomNode);
6868
newChild.parent = this;
6969
this.children.push(newChild);

0 commit comments

Comments
 (0)