@@ -5,6 +5,8 @@ import { Cluster, hierarchy } from '@visx/hierarchy';
55import { LinkVertical } from '@visx/shape' ;
66import { LinearGradient } from '@visx/gradient' ;
77import { StateRouteProps } from './StateRoute'
8+ import { onHover , onHoverExit } from '../actions/actions'
9+ import { useStoreContext } from '../store'
810import Legend from './AtomsRelationshipLegend'
911
1012export const blue = '#acdbdf' ;
@@ -39,8 +41,10 @@ interface selectorsCache {
3941
4042
4143const clusterData : clusterShape = { } ;
42- const selectorsCache :selectorsCache = { }
43-
44+ const selectorsCache :selectorsCache = { } ;
45+ const bothObj = { } ;
46+
47+
4448let initialFire = false
4549function clusterDataPopulate ( props :StateRouteProps ) {
4650 let atomCompObj = reorganizedCompObj ( props ) ;
@@ -58,10 +62,14 @@ function clusterDataPopulate(props:StateRouteProps) {
5862 let outerobj :outerObjShape = { }
5963 outerobj . name = key
6064 selectorsCache [ key ] = true
65+
66+ if ( ! bothObj [ key ] ) {
67+ bothObj [ key ] = [ ]
68+ }
69+
6170
6271 if ( props [ 0 ] . atomSelectors [ key ] . length ) {
6372 for ( let i = 0 ; i < props [ 0 ] . atomSelectors [ key ] . length ; i ++ ) {
64-
6573 if ( ! outerobj . children ) outerobj . children = [ ]
6674 let innerobj :innerObjShape = { }
6775 innerobj . name = props [ 0 ] . atomSelectors [ key ] [ i ]
@@ -70,8 +78,15 @@ function clusterDataPopulate(props:StateRouteProps) {
7078 //if atoms contain components
7179 if ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] ) {
7280 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+
7386 if ( ! innerobj . children ) innerobj . children = [ ]
7487 innerobj . children . push ( { name :atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] } )
88+ bothObj [ key ] . push ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] [ 0 ] )
89+
7590 }
7691 }
7792 outerobj . children . push ( innerobj )
@@ -82,6 +97,11 @@ function clusterDataPopulate(props:StateRouteProps) {
8297 if ( atomCompObj [ key ] && atomCompObj [ key ] . length ) {
8398 for ( let i = 0 ; i < atomCompObj [ key ] . length ; i ++ ) {
8499 outerobj . children . push ( { name :atomCompObj [ key ] [ i ] } )
100+
101+ if ( ! bothObj [ key ] ) {
102+ bothObj [ key ] = [ ]
103+ }
104+ bothObj [ key ] . push ( atomCompObj [ key ] [ i ] )
85105 }
86106 }
87107
@@ -93,9 +113,11 @@ function clusterDataPopulate(props:StateRouteProps) {
93113 let outObj :outerObjShape = { } ;
94114 if ( ! selectorsCache [ key ] ) {
95115 outObj . name = key
116+ if ( ! bothObj [ key ] ) bothObj [ key ] = [ ]
96117 for ( let i = 0 ; i < atomCompObj [ key ] . length ; i ++ ) {
97118 if ( ! outObj . children ) outObj . children = [ ]
98119 outObj . children . push ( { name :atomCompObj [ key ] [ i ] } )
120+ bothObj [ key ] . push ( atomCompObj [ key ] [ i ] )
99121 }
100122 clusterData . children . push ( outObj )
101123 }
@@ -121,13 +143,14 @@ function reorganizedCompObj(props) {
121143 return reorganizedCompObj ;
122144}
123145
124- function Node ( { node } ) {
146+ function Node ( { node, snapshots, dispatch, bothObj} ) {
147+ // const [dispatch] = useStoreContext();
125148 const selector = node . depth === 1 && node . height === 2
126149 const isRoot = node . depth === 0 ;
127150 const isParent = ! ! node . children ;
128-
151+
129152 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 } /> ;
131154
132155 return (
133156 < Group top = { node . y } left = { node . x } >
@@ -136,9 +159,16 @@ function Node({ node }) {
136159 r = { 12 }
137160 fill = { isParent ? orange : blue }
138161 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+ } }
142172 />
143173 ) }
144174 < text
@@ -157,6 +187,7 @@ function Node({ node }) {
157187}
158188
159189function RootNode ( { node } ) {
190+
160191 const width = 40 ;
161192 const height = 20 ;
162193 const centerX = - width / 2 ;
@@ -190,17 +221,24 @@ function RootNode({ node }) {
190221 ) ;
191222}
192223
193- function SelectorNode ( { node } ) {
224+ function SelectorNode ( { node, snapshots , dispatch , bothObj } ) {
194225 return (
195226 < Group top = { node . y } left = { node . x } >
196227 { node . depth !== 0 && (
197228 < circle
198229 r = { 12 }
199230 fill = { selectWhite }
200231 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+ } }
204242 />
205243 ) }
206244 < text
@@ -218,6 +256,15 @@ function SelectorNode({ node }) {
218256 ) ;
219257}
220258
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+
221268const defaultMargin = { top : 40 , left : 0 , right : 0 , bottom : 40 } ;
222269
223270// export type DendrogramProps = {
@@ -226,13 +273,18 @@ const defaultMargin = { top: 40, left: 0, right: 0, bottom: 40 };
226273// margin?: { top: number; right: number; bottom: number; left: number };
227274// };
228275
229- export default function Example ( {
276+ export default function AtomsRelationship ( {
230277 width,
231278 height,
232279 margin = defaultMargin ,
233280 snapshots,
234281} ) {
235282
283+
284+ let filtered = removeDup ( bothObj )
285+
286+ const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
287+
236288 if ( ! initialFire ) {
237289 clusterDataPopulate ( snapshots ) ;
238290 }
@@ -262,11 +314,15 @@ export default function Example({
262314 stroke = { merlinsbeard }
263315 strokeWidth = "1"
264316 strokeOpacity = { 0.2 }
265- fill = "none"
317+ fill = "none"
266318 />
267319 ) ) }
268320 { 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 } />
270326 ) ) }
271327 </ Group >
272328 ) }
0 commit comments