@@ -13,25 +13,40 @@ import { addNewSnapshots } from '../actions/actions';
13
13
14
14
// const chartData = {
15
15
// name: 'App',
16
- // actualDuration: 35000,
17
- // value: 17010,
18
16
// children: [
19
- // { name: 'DisplayPanel', actualDuration: 35000, value: 17010 },
20
- // { name: 'AltDisplay', actualDuration: 35000, value: 5842 },
21
- // { name: 'MarketSContainer', actualDuration: 35000, value: 1041 },
22
- // { name: 'MainSlider', actualDuration: 35000, value: 5176 },
17
+ // { name: 'DisplayPanel', componentData: { actualDuration: 5000 } },
18
+ // { name: 'AltDisplay', componentData: { actualDuration: 2000 } },
19
+ // { name: 'MarketSContainer', componentData: { actualDuration: 4000 } },
20
+ // { name: 'MainSlider', componentData: { actualDuration: 3000 } },
23
21
// ],
24
22
// };
25
23
24
+ const moveCompData = node => {
25
+ if ( node === null ) return node ;
26
+
27
+ if ( node . componentData . actualDuration ) {
28
+ node . val = node . componentData . actualDuration ;
29
+ }
30
+ else {
31
+ node . val = 1 ;
32
+ }
33
+ if ( node . children . length > 0 ) {
34
+ node . children . forEach ( elem => copyToProp ( elem ) ) ;
35
+ }
36
+ else {
37
+ return ;
38
+ }
39
+ } ;
40
+
26
41
const PerfView = ( {
27
42
width = 200 ,
28
43
height = 200 ,
29
44
snapshots
30
45
} ) => {
31
- // const chartData = snapshots;
32
- console . log ( "snapshots" , snapshots ) ;
46
+ console . log ( 'snapshots' , snapshots ) ;
33
47
const chartData = snapshots [ snapshots . length - 1 ] . children [ 0 ] ;
34
- console . log ( "chartData" , chartData ) ;
48
+ moveCompData ( chartData ) ;
49
+ console . log ( 'chartData' , chartData ) ;
35
50
36
51
const svgRef = useRef ( null ) ;
37
52
@@ -45,8 +60,13 @@ const PerfView = ({
45
60
const packFunc = data => d3 . pack ( )
46
61
. size ( [ width , height ] )
47
62
. padding ( 3 ) ( d3 . hierarchy ( data )
48
- . sum ( d => d . componentData . actualDuration )
49
- . sort ( ( a , b ) => b . componentData . actualDuration - a . componentData . actualDuration ) ) ;
63
+ . sum ( d => {
64
+ console . log ( 'in pack func. d=' , d ) ;
65
+ return d . val ;
66
+ } )
67
+ . sort ( ( a , b ) => b . val - a . val ) ) ;
68
+
69
+ console . log ( 'packFunc' , packFunc ) ;
50
70
51
71
useEffect ( ( ) => {
52
72
const packedRoot = packFunc ( chartData ) ;
@@ -59,8 +79,8 @@ const PerfView = ({
59
79
60
80
const node = svg . append ( 'g' )
61
81
. selectAll ( 'circle' )
62
- . data ( packedRoot . descendants ( ) . slice ( 1 ) )
63
- // .join('circle')
82
+ . data ( packedRoot . descendants ( ) . slice ( 1 ) )
83
+
64
84
. enter ( )
65
85
. append ( 'circle' )
66
86
. attr ( 'fill' , d => ( d . children ? color ( d . depth ) : 'white' ) )
@@ -69,20 +89,20 @@ const PerfView = ({
69
89
. on ( 'mouseout' , function ( ) { d3 . select ( this ) . attr ( 'stroke' , null ) ; } )
70
90
. on ( 'click' , d => focus !== d && ( zoom ( d ) , d3 . event . stopPropagation ( ) ) ) ;
71
91
92
+ console . log ( 'PerfView -> node' , node ) ;
93
+
72
94
const label = svg . append ( 'g' )
73
95
. style ( 'font' , '11px sans-serif' )
74
96
. attr ( 'pointer-events' , 'none' )
75
97
. attr ( 'text-anchor' , 'middle' )
76
98
. selectAll ( 'text' )
77
99
. data ( packedRoot . descendants ( ) )
78
- // .join('text')
79
100
. enter ( )
80
101
. append ( 'text' )
81
102
. style ( 'fill-opacity' , d => ( d . parent === packedRoot ? 1 : 0 ) )
82
103
. style ( 'display' , d => ( d . parent === packedRoot ? 'inline' : 'none' ) )
83
- . text ( d => `${ d . data . name } : ${ Number . parseFloat ( d . data . actualDuration ) . toFixed ( 2 ) } ms` ) ;
104
+ . text ( d => `${ d . data . name } : ${ Number . parseFloat ( d . data . val ) . toFixed ( 2 ) } ms` ) ;
84
105
85
- console . log ( 'PerfView -> node' , node ) ;
86
106
zoomTo ( [ packedRoot . x , packedRoot . y , packedRoot . r * 2 ] ) ;
87
107
88
108
function zoomTo ( v ) {
0 commit comments