@@ -8,7 +8,14 @@ import * as d3 from 'd3';
8
8
import { changeView , changeSlider , setCurrentTabInApp } from '../actions/actions' ;
9
9
import { useStoreContext } from '../store' ;
10
10
11
- const defaultMargin = {
11
+ interface defaultMargin {
12
+ top : number ,
13
+ left : number ,
14
+ right : number ,
15
+ bottom : number ,
16
+ }
17
+
18
+ const defaultMargin : defaultMargin = {
12
19
top : 30 , left : 30 , right : 55 , bottom : 70 ,
13
20
} ;
14
21
@@ -30,16 +37,8 @@ function History(props: Record<string, unknown>): JSX.Element {
30
37
const root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
31
38
32
39
// setting the margins for the Map to render in the tab window.
33
- const innerWidth = totalWidth - margin . left - margin . right ;
34
- const innerHeight = totalHeight - margin . top - margin . bottom - 60 ;
35
-
36
- useEffect ( ( ) => {
37
- makeD3Tree ( ) ;
38
- } , [ root , currLocation ] ) ;
39
-
40
- useEffect ( ( ) => {
41
- dispatch ( setCurrentTabInApp ( 'history' ) ) ;
42
- } , [ ] ) ;
40
+ const innerWidth : number = totalWidth - margin . left - margin . right ;
41
+ const innerHeight : number = totalHeight - margin . top - margin . bottom - 60 ;
43
42
44
43
function labelCurrentNode ( d3root ) {
45
44
if ( d3root . data . index === currLocation . index ) {
@@ -63,6 +62,74 @@ function History(props: Record<string, unknown>): JSX.Element {
63
62
return found ;
64
63
}
65
64
65
+ // findDiff function uses same logic as ActionContainer.tsx
66
+ function findDiff ( index ) {
67
+ const statelessCleanning = ( obj : {
68
+ name ?: string ;
69
+ componentData ?: object ;
70
+ state ?: string | any ;
71
+ stateSnaphot ?: object ;
72
+ children ?: any [ ] ;
73
+ } ) => {
74
+ const newObj = { ...obj } ;
75
+ if ( newObj . name === 'nameless' ) {
76
+ delete newObj . name ;
77
+ }
78
+ if ( newObj . componentData ) {
79
+ delete newObj . componentData ;
80
+ }
81
+ if ( newObj . state === 'stateless' ) {
82
+ delete newObj . state ;
83
+ }
84
+ if ( newObj . stateSnaphot ) {
85
+ newObj . stateSnaphot = statelessCleanning ( obj . stateSnaphot ) ;
86
+ }
87
+ if ( newObj . children ) {
88
+ newObj . children = [ ] ;
89
+ if ( obj . children . length > 0 ) {
90
+ obj . children . forEach (
91
+ ( element : { state ?: object | string ; children ?: [ ] } ) => {
92
+ if (
93
+ element . state !== 'stateless'
94
+ || element . children . length > 0
95
+ ) {
96
+ const clean = statelessCleanning ( element ) ;
97
+ newObj . children . push ( clean ) ;
98
+ }
99
+ } ,
100
+ ) ;
101
+ }
102
+ }
103
+ return newObj ;
104
+ } ;
105
+
106
+ function findStateChangeObj ( delta , changedState = [ ] ) {
107
+ if ( ! delta . children && ! delta . state ) {
108
+ return changedState ;
109
+ }
110
+ if ( delta . state && delta . state [ 0 ] !== 'stateless' ) {
111
+ changedState . push ( delta . state ) ;
112
+ }
113
+ if ( ! delta . children ) {
114
+ return changedState ;
115
+ }
116
+ Object . keys ( delta . children ) . forEach ( child => {
117
+ // if (isNaN(child) === false) {
118
+ changedState . push ( ...findStateChangeObj ( delta . children [ child ] ) ) ;
119
+ // }
120
+ } ) ;
121
+ return changedState ;
122
+ }
123
+
124
+ const delta = diff ( statelessCleanning ( snapshots [ index - 1 ] ) , statelessCleanning ( snapshots [ index ] ) ) ;
125
+ const changedState = findStateChangeObj ( delta ) ;
126
+ // figured out the formatting for hover, applying diff.csss
127
+ const html = formatters . html . format ( changedState [ 0 ] ) ;
128
+ // uneeded, not returning a react component in SVG div
129
+ // const output = ReactHtmlParser(html);
130
+ return html ;
131
+ }
132
+
66
133
/**
67
134
* @method makeD3Tree :Creates a new D3 Tree
68
135
*/
@@ -144,75 +211,14 @@ function History(props: Record<string, unknown>): JSX.Element {
144
211
return svg . node ( ) ;
145
212
} ;
146
213
147
- // findDiff function uses same logic as ActionContainer.tsx
148
- function findDiff ( index ) {
149
- const statelessCleanning = ( obj : {
150
- name ?: string ;
151
- componentData ?: object ;
152
- state ?: string | any ;
153
- stateSnaphot ?: object ;
154
- children ?: any [ ] ;
155
- } ) => {
156
- const newObj = { ...obj } ;
157
- if ( newObj . name === 'nameless' ) {
158
- delete newObj . name ;
159
- }
160
- if ( newObj . componentData ) {
161
- delete newObj . componentData ;
162
- }
163
- if ( newObj . state === 'stateless' ) {
164
- delete newObj . state ;
165
- }
166
- if ( newObj . stateSnaphot ) {
167
- newObj . stateSnaphot = statelessCleanning ( obj . stateSnaphot ) ;
168
- }
169
- if ( newObj . children ) {
170
- newObj . children = [ ] ;
171
- if ( obj . children . length > 0 ) {
172
- obj . children . forEach (
173
- ( element : { state ?: object | string ; children ?: [ ] } ) => {
174
- if (
175
- element . state !== 'stateless'
176
- || element . children . length > 0
177
- ) {
178
- const clean = statelessCleanning ( element ) ;
179
- newObj . children . push ( clean ) ;
180
- }
181
- } ,
182
- ) ;
183
- }
184
- }
185
- return newObj ;
186
- } ;
187
-
188
- function findStateChangeObj ( delta , changedState = [ ] ) {
189
- if ( ! delta . children && ! delta . state ) {
190
- return changedState ;
191
- }
192
- if ( delta . state && delta . state [ 0 ] !== 'stateless' ) {
193
- changedState . push ( delta . state ) ;
194
- }
195
- if ( ! delta . children ) {
196
- return changedState ;
197
- }
198
- Object . keys ( delta . children ) . forEach ( child => {
199
- // if (isNaN(child) === false) {
200
- changedState . push ( ...findStateChangeObj ( delta . children [ child ] ) ) ;
201
- // }
202
- } ) ;
203
- return changedState ;
204
- }
205
-
206
- const delta = diff ( statelessCleanning ( snapshots [ index - 1 ] ) , statelessCleanning ( snapshots [ index ] ) ) ;
207
- const changedState = findStateChangeObj ( delta ) ;
208
- // figured out the formatting for hover, applying diff.csss
209
- const html = formatters . html . format ( changedState [ 0 ] ) ;
210
- // uneeded, not returning a react component in SVG div
211
- // const output = ReactHtmlParser(html);
212
- return html ;
213
- }
214
+ useEffect ( ( ) => {
215
+ makeD3Tree ( ) ;
216
+ } , [ root , currLocation ] ) ;
214
217
215
- // then rendering each node in History tab to render using D3, which will share area with LegendKey
218
+ useEffect ( ( ) => {
219
+ dispatch ( setCurrentTabInApp ( 'history' ) ) ;
220
+ } , [ ] ) ;
221
+ // then rendering each node in History tab to render using D3, which will share area with LegendKey
216
222
return (
217
223
< div className = "display" >
218
224
< svg
0 commit comments