@@ -5,6 +5,8 @@ import { Cluster, hierarchy } from '@visx/hierarchy';
5
5
import { LinkVertical } from '@visx/shape' ;
6
6
import { LinearGradient } from '@visx/gradient' ;
7
7
import { StateRouteProps } from './StateRoute'
8
+ import { onHover , onHoverExit } from '../actions/actions'
9
+ import { useStoreContext } from '../store'
8
10
import Legend from './AtomsRelationshipLegend'
9
11
10
12
export const blue = '#acdbdf' ;
@@ -39,8 +41,10 @@ interface selectorsCache {
39
41
40
42
41
43
const clusterData : clusterShape = { } ;
42
- const selectorsCache :selectorsCache = { }
43
-
44
+ const selectorsCache :selectorsCache = { } ;
45
+ const bothObj = { } ;
46
+
47
+
44
48
let initialFire = false
45
49
function clusterDataPopulate ( props :StateRouteProps ) {
46
50
let atomCompObj = reorganizedCompObj ( props ) ;
@@ -58,10 +62,14 @@ function clusterDataPopulate(props:StateRouteProps) {
58
62
let outerobj :outerObjShape = { }
59
63
outerobj . name = key
60
64
selectorsCache [ key ] = true
65
+
66
+ if ( ! bothObj [ key ] ) {
67
+ bothObj [ key ] = [ ]
68
+ }
69
+
61
70
62
71
if ( props [ 0 ] . atomSelectors [ key ] . length ) {
63
72
for ( let i = 0 ; i < props [ 0 ] . atomSelectors [ key ] . length ; i ++ ) {
64
-
65
73
if ( ! outerobj . children ) outerobj . children = [ ]
66
74
let innerobj :innerObjShape = { }
67
75
innerobj . name = props [ 0 ] . atomSelectors [ key ] [ i ]
@@ -70,8 +78,15 @@ function clusterDataPopulate(props:StateRouteProps) {
70
78
//if atoms contain components
71
79
if ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] ) {
72
80
for ( let j = 0 ; j < atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] . length ; j ++ ) {
81
+ if ( ! bothObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] ) {
82
+ bothObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] = [ ]
83
+ }
84
+ bothObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] . push ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] [ 0 ] )
85
+
73
86
if ( ! innerobj . children ) innerobj . children = [ ]
74
87
innerobj . children . push ( { name :atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] } )
88
+ bothObj [ key ] . push ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] [ 0 ] )
89
+
75
90
}
76
91
}
77
92
outerobj . children . push ( innerobj )
@@ -82,6 +97,11 @@ function clusterDataPopulate(props:StateRouteProps) {
82
97
if ( atomCompObj [ key ] && atomCompObj [ key ] . length ) {
83
98
for ( let i = 0 ; i < atomCompObj [ key ] . length ; i ++ ) {
84
99
outerobj . children . push ( { name :atomCompObj [ key ] [ i ] } )
100
+
101
+ if ( ! bothObj [ key ] ) {
102
+ bothObj [ key ] = [ ]
103
+ }
104
+ bothObj [ key ] . push ( atomCompObj [ key ] [ i ] )
85
105
}
86
106
}
87
107
@@ -93,9 +113,11 @@ function clusterDataPopulate(props:StateRouteProps) {
93
113
let outObj :outerObjShape = { } ;
94
114
if ( ! selectorsCache [ key ] ) {
95
115
outObj . name = key
116
+ if ( ! bothObj [ key ] ) bothObj [ key ] = [ ]
96
117
for ( let i = 0 ; i < atomCompObj [ key ] . length ; i ++ ) {
97
118
if ( ! outObj . children ) outObj . children = [ ]
98
119
outObj . children . push ( { name :atomCompObj [ key ] [ i ] } )
120
+ bothObj [ key ] . push ( atomCompObj [ key ] [ i ] )
99
121
}
100
122
clusterData . children . push ( outObj )
101
123
}
@@ -121,13 +143,14 @@ function reorganizedCompObj(props) {
121
143
return reorganizedCompObj ;
122
144
}
123
145
124
- function Node ( { node } ) {
146
+ function Node ( { node, snapshots, dispatch, bothObj} ) {
147
+ // const [dispatch] = useStoreContext();
125
148
const selector = node . depth === 1 && node . height === 2
126
149
const isRoot = node . depth === 0 ;
127
150
const isParent = ! ! node . children ;
128
-
151
+
129
152
if ( isRoot ) return < RootNode node = { node } /> ;
130
- if ( selector ) return < SelectorNode node = { node } /> ;
153
+ if ( selector ) return < SelectorNode node = { node } snapshots = { snapshots } bothObj = { bothObj } dispatch = { dispatch } /> ;
131
154
132
155
return (
133
156
< Group top = { node . y } left = { node . x } >
@@ -136,9 +159,16 @@ function Node({ node }) {
136
159
r = { 12 }
137
160
fill = { isParent ? orange : blue }
138
161
stroke = { isParent ? orange : blue }
139
- // onClick={() => {
140
- // alert(`clicked: ${JSON.stringify(node.data.name)}`);
141
- // }}
162
+ onMouseLeave = { ( ) => {
163
+ for ( let i = 0 ; i < bothObj [ node . data . name ] . length ; i ++ ) {
164
+ dispatch ( onHoverExit ( snapshots [ 0 ] . recoilDomNode [ bothObj [ node . data . name ] [ i ] ] ) )
165
+ }
166
+ } }
167
+ onMouseEnter = { ( ) => {
168
+ for ( let i = 0 ; i < bothObj [ node . data . name ] . length ; i ++ ) {
169
+ dispatch ( onHover ( snapshots [ 0 ] . recoilDomNode [ bothObj [ node . data . name ] [ i ] ] ) )
170
+ }
171
+ } }
142
172
/>
143
173
) }
144
174
< text
@@ -157,6 +187,7 @@ function Node({ node }) {
157
187
}
158
188
159
189
function RootNode ( { node } ) {
190
+
160
191
const width = 40 ;
161
192
const height = 20 ;
162
193
const centerX = - width / 2 ;
@@ -190,17 +221,24 @@ function RootNode({ node }) {
190
221
) ;
191
222
}
192
223
193
- function SelectorNode ( { node } ) {
224
+ function SelectorNode ( { node, snapshots , dispatch , bothObj } ) {
194
225
return (
195
226
< Group top = { node . y } left = { node . x } >
196
227
{ node . depth !== 0 && (
197
228
< circle
198
229
r = { 12 }
199
230
fill = { selectWhite }
200
231
stroke = { selectWhite }
201
- // onClick={() => {
202
- // alert(`clicked: ${JSON.stringify(node.data.name)}`);
203
- // }}
232
+ onMouseLeave = { ( ) => {
233
+ for ( let i = 0 ; i < bothObj [ node . data . name ] . length ; i ++ ) {
234
+ dispatch ( onHoverExit ( snapshots [ 0 ] . recoilDomNode [ bothObj [ node . data . name ] [ i ] ] ) )
235
+ }
236
+ } }
237
+ onMouseEnter = { ( ) => {
238
+ for ( let i = 0 ; i < bothObj [ node . data . name ] . length ; i ++ ) {
239
+ dispatch ( onHover ( snapshots [ 0 ] . recoilDomNode [ bothObj [ node . data . name ] [ i ] ] ) )
240
+ }
241
+ } }
204
242
/>
205
243
) }
206
244
< text
@@ -218,6 +256,15 @@ function SelectorNode({ node }) {
218
256
) ;
219
257
}
220
258
259
+ function removeDup ( bothObj ) {
260
+ let filteredObj = { }
261
+ for ( let key in bothObj ) {
262
+ let array = bothObj [ key ] . filter ( ( a , b ) => bothObj [ key ] . indexOf ( a ) === b )
263
+ filteredObj [ key ] = array
264
+ }
265
+ return filteredObj
266
+ }
267
+
221
268
const defaultMargin = { top : 40 , left : 0 , right : 0 , bottom : 40 } ;
222
269
223
270
// export type DendrogramProps = {
@@ -226,13 +273,18 @@ const defaultMargin = { top: 40, left: 0, right: 0, bottom: 40 };
226
273
// margin?: { top: number; right: number; bottom: number; left: number };
227
274
// };
228
275
229
- export default function Example ( {
276
+ export default function AtomsRelationship ( {
230
277
width,
231
278
height,
232
279
margin = defaultMargin ,
233
280
snapshots,
234
281
} ) {
235
282
283
+
284
+ let filtered = removeDup ( bothObj )
285
+
286
+ const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
287
+
236
288
if ( ! initialFire ) {
237
289
clusterDataPopulate ( snapshots ) ;
238
290
}
@@ -262,11 +314,15 @@ export default function Example({
262
314
stroke = { merlinsbeard }
263
315
strokeWidth = "1"
264
316
strokeOpacity = { 0.2 }
265
- fill = "none"
317
+ fill = "none"
266
318
/>
267
319
) ) }
268
320
{ cluster . descendants ( ) . map ( ( node , i ) => (
269
- < Node key = { `cluster-node-${ i } ` } node = { node } />
321
+ < Node key = { `cluster-node-${ i } ` }
322
+ node = { node }
323
+ bothObj = { filtered }
324
+ snapshots = { snapshots }
325
+ dispatch = { dispatch } />
270
326
) ) }
271
327
</ Group >
272
328
) }
0 commit comments