@@ -5,17 +5,20 @@ 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'
10+ import Legend from './AtomsRelationshipLegend'
811
9- const blue = '#acdbdf' ;
10- const selectWhite = '#f0ece2' ;
12+ export const blue = '#acdbdf' ;
13+ export const selectWhite = '#f0ece2' ;
1114
1215export const lightgreen = '#0BAB64' ;
13- const green = '#3BB78F'
14- const orange = '#FED8B1' ;
16+ export const green = '#3BB78F'
17+ export const orange = '#FED8B1' ;
1518
16- const merlinsbeard = '#f7f7f3' ;
19+ export const merlinsbeard = '#f7f7f3' ;
1720export const background = '#242529' ;
18- const root = '#d2f5e3' ;
21+ export const root = '#d2f5e3' ;
1922
2023interface clusterShape {
2124 name ?:string ;
@@ -38,8 +41,10 @@ interface selectorsCache {
3841
3942
4043const clusterData : clusterShape = { } ;
41- const selectorsCache :selectorsCache = { }
42-
44+ const selectorsCache :selectorsCache = { } ;
45+ const bothObj = { } ;
46+
47+
4348let initialFire = false
4449function clusterDataPopulate ( props :StateRouteProps ) {
4550 let atomCompObj = reorganizedCompObj ( props ) ;
@@ -57,10 +62,14 @@ function clusterDataPopulate(props:StateRouteProps) {
5762 let outerobj :outerObjShape = { }
5863 outerobj . name = key
5964 selectorsCache [ key ] = true
65+
66+ if ( ! bothObj [ key ] ) {
67+ bothObj [ key ] = [ ]
68+ }
69+
6070
6171 if ( props [ 0 ] . atomSelectors [ key ] . length ) {
6272 for ( let i = 0 ; i < props [ 0 ] . atomSelectors [ key ] . length ; i ++ ) {
63-
6473 if ( ! outerobj . children ) outerobj . children = [ ]
6574 let innerobj :innerObjShape = { }
6675 innerobj . name = props [ 0 ] . atomSelectors [ key ] [ i ]
@@ -69,8 +78,15 @@ function clusterDataPopulate(props:StateRouteProps) {
6978 //if atoms contain components
7079 if ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] ) {
7180 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+
7286 if ( ! innerobj . children ) innerobj . children = [ ]
7387 innerobj . children . push ( { name :atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] } )
88+ bothObj [ key ] . push ( atomCompObj [ props [ 0 ] . atomSelectors [ key ] [ i ] ] [ 0 ] )
89+
7490 }
7591 }
7692 outerobj . children . push ( innerobj )
@@ -81,6 +97,11 @@ function clusterDataPopulate(props:StateRouteProps) {
8197 if ( atomCompObj [ key ] && atomCompObj [ key ] . length ) {
8298 for ( let i = 0 ; i < atomCompObj [ key ] . length ; i ++ ) {
8399 outerobj . children . push ( { name :atomCompObj [ key ] [ i ] } )
100+
101+ if ( ! bothObj [ key ] ) {
102+ bothObj [ key ] = [ ]
103+ }
104+ bothObj [ key ] . push ( atomCompObj [ key ] [ i ] )
84105 }
85106 }
86107
@@ -92,9 +113,11 @@ function clusterDataPopulate(props:StateRouteProps) {
92113 let outObj :outerObjShape = { } ;
93114 if ( ! selectorsCache [ key ] ) {
94115 outObj . name = key
116+ if ( ! bothObj [ key ] ) bothObj [ key ] = [ ]
95117 for ( let i = 0 ; i < atomCompObj [ key ] . length ; i ++ ) {
96118 if ( ! outObj . children ) outObj . children = [ ]
97119 outObj . children . push ( { name :atomCompObj [ key ] [ i ] } )
120+ bothObj [ key ] . push ( atomCompObj [ key ] [ i ] )
98121 }
99122 clusterData . children . push ( outObj )
100123 }
@@ -120,13 +143,14 @@ function reorganizedCompObj(props) {
120143 return reorganizedCompObj ;
121144}
122145
123- function Node ( { node } ) {
146+ function Node ( { node, snapshots, dispatch, bothObj} ) {
147+ // const [dispatch] = useStoreContext();
124148 const selector = node . depth === 1 && node . height === 2
125149 const isRoot = node . depth === 0 ;
126150 const isParent = ! ! node . children ;
127-
151+
128152 if ( isRoot ) return < RootNode node = { node } /> ;
129- if ( selector ) return < SelectorNode node = { node } /> ;
153+ if ( selector ) return < SelectorNode node = { node } snapshots = { snapshots } bothObj = { bothObj } dispatch = { dispatch } /> ;
130154
131155 return (
132156 < Group top = { node . y } left = { node . x } >
@@ -135,9 +159,16 @@ function Node({ node }) {
135159 r = { 12 }
136160 fill = { isParent ? orange : blue }
137161 stroke = { isParent ? orange : blue }
138- // onClick={() => {
139- // alert(`clicked: ${JSON.stringify(node.data.name)}`);
140- // }}
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+ } }
141172 />
142173 ) }
143174 < text
@@ -156,6 +187,7 @@ function Node({ node }) {
156187}
157188
158189function RootNode ( { node } ) {
190+
159191 const width = 40 ;
160192 const height = 20 ;
161193 const centerX = - width / 2 ;
@@ -189,18 +221,24 @@ function RootNode({ node }) {
189221 ) ;
190222}
191223
192- function SelectorNode ( { node } ) {
193-
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 }
@@ -242,11 +294,16 @@ export default function Example({
242294 const yMax = height - margin . top - margin . bottom ;
243295
244296 return width < 10 ? null : (
297+ < >
298+ < div >
299+ < Legend
300+ hierarchy = { hierarchy } />
301+ </ div >
245302 < svg width = { width } height = { height } >
303+
246304 < LinearGradient id = "top" from = { lightgreen } to = { green } />
247305
248306 < rect width = { width } height = { height } rx = { 14 } fill = { background } />
249-
250307 < Cluster root = { data } size = { [ xMax , yMax ] } >
251308 { ( cluster ) => (
252309 < Group top = { margin . top } left = { margin . left } >
@@ -257,15 +314,20 @@ export default function Example({
257314 stroke = { merlinsbeard }
258315 strokeWidth = "1"
259316 strokeOpacity = { 0.2 }
260- fill = "none"
317+ fill = "none"
261318 />
262319 ) ) }
263320 { cluster . descendants ( ) . map ( ( node , i ) => (
264- < 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 } />
265326 ) ) }
266327 </ Group >
267328 ) }
268329 </ Cluster >
269330 </ svg >
331+ </ >
270332 ) ;
271- }
333+ }
0 commit comments