Skip to content

Commit 167a7d2

Browse files
committed
Added Typescript for clusterData, selectorsCache, innerObj, and outerObj
1 parent da039c0 commit 167a7d2

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

src/app/components/AtomsRelationship.jsx renamed to src/app/components/AtomsRelationship.tsx

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,44 @@ import { Cluster, hierarchy } from '@visx/hierarchy';
44
//import { HierarchyPointNode, HierarchyPointLink } from '@visx/hierarchy/lib/types';
55
import { LinkVertical } from '@visx/shape';
66
import { LinearGradient } from '@visx/gradient';
7+
import { StateRouteProps} from './StateRoute'
78

89
const blue = '#acdbdf';
9-
const white = '#f0ece2';
10+
const selectWhite = '#f0ece2';
1011

1112
export const lightgreen = '#0BAB64';
1213
const green = '#3BB78F'
13-
const selectOrange = '#F39F86';
14+
const orange = '#FED8B1';
1415

1516
const merlinsbeard = '#f7f7f3';
1617
export const background = '#242529';
1718
const root = '#d2f5e3';
1819

19-
// interface NodeShape {
20-
// name: string;
21-
// children?: NodeShape[];
22-
//
20+
interface clusterShape {
21+
name?:string;
22+
children?: clusterShape[]
23+
}
2324

24-
const clusterData = {};
25-
const selectorsCache = {}
25+
interface outerObjShape {
26+
name?:string;
27+
children?: outerObjShape[]
28+
}
29+
30+
interface innerObjShape {
31+
name?:string;
32+
children?: innerObjShape[]
33+
}
34+
35+
interface selectorsCache {
36+
[key:string]: any
37+
}
38+
39+
40+
const clusterData : clusterShape = {};
41+
const selectorsCache :selectorsCache = {}
2642

2743
let initialFire = false
28-
function clusterDataPopulate(props) {
44+
function clusterDataPopulate(props:StateRouteProps) {
2945
let atomCompObj = reorganizedCompObj(props);
3046

3147
//this is to set the root name property
@@ -38,15 +54,15 @@ function clusterDataPopulate(props) {
3854
if(!clusterData.children) clusterData.children = []
3955

4056
for(let key in props[0].atomSelectors){
41-
let outerobj = {}
57+
let outerobj:outerObjShape = {}
4258
outerobj.name = key
4359
selectorsCache[key] = true
4460

4561
if(props[0].atomSelectors[key].length){
4662
for(let i=0; i<props[0].atomSelectors[key].length;i++){
4763

4864
if(!outerobj.children) outerobj.children = []
49-
let innerobj = {}
65+
let innerobj:innerObjShape = {}
5066
innerobj.name = props[0].atomSelectors[key][i]
5167
selectorsCache[props[0].atomSelectors[key][i]] = true
5268

@@ -73,7 +89,7 @@ function clusterDataPopulate(props) {
7389
}
7490

7591
for (let key in atomCompObj){
76-
let outObj = {};
92+
let outObj:outerObjShape = {};
7793
if(!selectorsCache[key]){
7894
outObj.name = key
7995
for (let i=0; i<atomCompObj[key].length;i++){
@@ -84,8 +100,11 @@ function clusterDataPopulate(props) {
84100
}
85101
}
86102
initialFire = true
103+
87104
}
88105

106+
107+
89108
function reorganizedCompObj(props) {
90109
let atomsComponentObj = props[0].atomsComponents;
91110
let reorganizedCompObj = {};
@@ -115,8 +134,8 @@ function Node({ node }) {
115134
{node.depth !== 0 && (
116135
<circle
117136
r={12}
118-
fill={isParent ? white : blue}
119-
stroke={isParent ? white : blue}
137+
fill={isParent ? orange : blue}
138+
stroke={isParent ? orange : blue}
120139
// onClick={() => {
121140
// alert(`clicked: ${JSON.stringify(node.data.name)}`);
122141
// }}
@@ -129,7 +148,7 @@ function Node({ node }) {
129148
textAnchor="middle"
130149
y = "-20"
131150
style={{ pointerEvents: 'none' }}
132-
fill={isParent ? white : blue}
151+
fill={isParent ? orange : blue}
133152
>
134153
{node.data.name}
135154
</text>
@@ -178,8 +197,8 @@ function SelectorNode({ node }) {
178197
{node.depth !== 0 && (
179198
<circle
180199
r={12}
181-
fill={selectOrange}
182-
stroke={selectOrange}
200+
fill={selectWhite}
201+
stroke={selectWhite}
183202
// onClick={() => {
184203
// alert(`clicked: ${JSON.stringify(node.data.name)}`);
185204
// }}
@@ -192,7 +211,7 @@ function SelectorNode({ node }) {
192211
textAnchor="middle"
193212
y = "-20"
194213
style={{ pointerEvents: 'none' }}
195-
fill={orange}
214+
fill={selectWhite}
196215
>
197216
{node.data.name}
198217
</text>

src/app/components/StateRoute.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import {
1414
import Tree from './Tree';
1515
import ComponentMap from './ComponentMap';
1616
// import PerfView from './PerfView';
17-
import AtomsRelationship from './AtomsRelationship.jsx';
18-
import PerformanceVisx from './PerformanceVisx.tsx';
17+
import AtomsRelationship from './AtomsRelationship';
18+
import PerformanceVisx from './PerformanceVisx';
1919

20-
import Example from './AtomsRelationship.jsx';
20+
import Example from './AtomsRelationship';
2121
import { ParentSize } from '@visx/responsive';
2222
import { Console } from 'console';
2323
import Legendary from './legend';
@@ -30,7 +30,7 @@ const NO_STATE_MSG =
3030
'No state change detected. Trigger an event to change state';
3131
// eslint-disable-next-line react/prop-types
3232

33-
interface StateRouteProps {
33+
export interface StateRouteProps {
3434
snapshot: {
3535
name?: string;
3636
componentData?: object;

0 commit comments

Comments
 (0)