4
4
import React , { useEffect , useRef } from 'react' ;
5
5
import * as d3 from 'd3' ;
6
6
7
- const PerfView = props => {
8
- console . log ( 'Rendering Tab - snapshot: ' , props . snapshot ) ;
7
+ // let root = {};
8
+ const chartData = {
9
+ name : 'flare' ,
10
+ children : [
11
+ {
12
+ name : 'analytics' ,
13
+ children : [
14
+ {
15
+ name : 'cluster' ,
16
+ children : [
17
+ { name : 'AgglomerativeCluster' , size : 3938 } ,
18
+ { name : 'CommunityStructure' , size : 3812 } ,
19
+ { name : 'MergeEdge' , size : 743 } ,
20
+ ] ,
21
+ } ,
22
+ {
23
+ name : 'graph' ,
24
+ children : [
25
+ { name : 'BetweennessCentrality' , size : 3534 } ,
26
+ { name : 'LinkDistance' , size : 5731 } ,
27
+ ] ,
28
+ } ,
29
+ ] ,
30
+ } ,
31
+ ] ,
32
+ } ;
33
+
34
+ const PerfView = ( { width, height } ) => {
35
+ console . log ( 'Rendering Performance - chartData: ' , chartData ) ;
36
+
37
+ const d3gRef = useRef ( null ) ;
38
+ // returns color scale function
39
+ const color = d3 . scaleLinear ( )
40
+ . domain ( [ 0 , 5 ] )
41
+ . range ( [ 'hsl(152,80%,80%)' , 'hsl(228,30%,40%)' ] )
42
+ . interpolate ( d3 . interpolateHcl ) ;
43
+
44
+ // returns a function that formats numbers
45
+ const numFormat = d3 . format ( ',d' ) ;
46
+
47
+ const margin = {
48
+ top : 0 , right : 60 , bottom : 200 , left : 120 ,
49
+ } ;
50
+
51
+ // create a new circle packing layout function
52
+ const pack = data => d3 . pack ( )
53
+ . size ( [ width , height ] )
54
+ . padding ( 3 ) ( d3 . hierarchy ( data )
55
+ . sum ( d => d . value )
56
+ . sort ( ( a , b ) => b . value - a . value ) ) ;
9
57
10
- const thisRef = useRef ( null ) ;
11
-
12
58
useEffect ( ( ) => {
59
+ const hierarchy = d3 . hierarchy ( chartData ) ;
60
+ console . log ( 'PerfView -> hierarchy' , hierarchy ) ;
61
+
62
+ const dataRoot = pack ( hierarchy ) ;
63
+ console . log ( 'PerfView -> dataRoot' , dataRoot ) ;
13
64
14
- const dataMax = d3 . max ( props . data ) ;
15
-
16
- const yScale = d3 . scaleLinear ( )
17
- . domain ( [ 0 , dataMax ] )
18
- . range ( [ 0 , props . size [ 1 ] ] ) ;
19
-
20
- d3 . select ( thisRef . current )
21
- . selectAll ( 'rect' )
22
- . data ( props . data )
23
- . enter ( )
24
- . append ( 'rect' ) ;
25
-
26
- d3 . select ( thisRef . current )
27
- . selectAll ( 'rect' )
28
- . data ( props . data )
29
- . exit ( )
30
- . remove ( ) ;
31
-
32
- d3 . select ( thisRef . current )
33
- . selectAll ( 'rect' )
34
- . data ( props . data )
35
- . style ( 'fill' , '#fe9922' )
36
- . attr ( 'x' , ( d , i ) => i * 25 )
37
- . attr ( 'y' , d => props . size [ 1 ] - yScale ( d ) )
38
- . attr ( 'height' , d => yScale ( d ) )
39
- . attr ( 'width' , 25 ) ;
40
- } ) ;
41
-
42
- return ( < svg ref = { thisRef } width = { 500 } height = { 500 } /> ) ;
65
+ const gElem = d3 . select ( d3gRef ) ;
66
+
67
+ gElem . selectAll ( 'circle' )
68
+ . data ( dataRoot . descendants ( ) . slice ( 1 ) )
69
+ . enter ( ) . append ( 'circle' )
70
+ . attr ( 'fill' , d => ( d . children ? color ( d . depth ) : 'white' ) ) ;
71
+ } , [ chartData ] ) ;
72
+
73
+ return (
74
+ < svg width = { width } height = { height } className = "d3Container" >
75
+ < g ref = { d3gRef } transform = { `translate(${ 50 } ${ 50 } )` } />
76
+ < rect width = "100" height = "100" x = "50" y = "20" />
77
+ </ svg >
78
+ ) ;
43
79
} ;
44
80
45
81
export default PerfView ;
46
82
83
+ /* eslint-disable indent */
84
+
47
85
48
86
// const data = {
49
87
// type,
@@ -58,3 +96,133 @@ export default PerfView;
58
96
// selfBaseDuration,
59
97
// treeBaseDuration
60
98
// }
99
+
100
+
101
+ // const dataMax = d3.max(props.data);
102
+
103
+ // const yScale = d3.scaleLinear()
104
+ // .domain([0, dataMax])
105
+ // .range([0, props.size[1]]);
106
+
107
+ // d3.select(thisRef.current)
108
+ // .selectAll('rect')
109
+ // .data(props.data)
110
+ // .enter()
111
+ // .append('rect');
112
+
113
+ // d3.select(thisRef.current)
114
+ // .selectAll('rect')
115
+ // .data(props.data)
116
+ // .exit()
117
+ // .remove();
118
+
119
+ // d3.select(thisRef.current)
120
+ // .selectAll('rect')
121
+ // .data(props.data)
122
+ // .style('fill', '#fe9922')
123
+ // .attr('x', (d, i) => i * 25)
124
+ // .attr('y', d => props.size[1] - yScale(d))
125
+ // .attr('height', d => yScale(d))
126
+ // .attr('width', 25);
127
+
128
+
129
+ // const PerfView = ({ width, height }) => {
130
+ // const chartData = {
131
+ // name: 'flare',
132
+ // children: [
133
+ // {
134
+ // name: 'analytics',
135
+ // children: [
136
+ // {
137
+ // name: 'cluster',
138
+ // children: [
139
+ // { name: 'AgglomerativeCluster', size: 3938 },
140
+ // { name: 'CommunityStructure', size: 3812 },
141
+ // { name: 'MergeEdge', size: 743 },
142
+ // ],
143
+ // },
144
+ // {
145
+ // name: 'graph',
146
+ // children: [
147
+ // { name: 'BetweennessCentrality', size: 3534 },
148
+ // { name: 'LinkDistance', size: 5731 },
149
+ // ],
150
+ // },
151
+ // ],
152
+ // },
153
+ // ],
154
+ // };
155
+ // console.log('Rendering Performance - chartData: ', chartData);
156
+
157
+ // const d3gRef = useRef(null);
158
+ // // returns color scale function
159
+ // const color = d3.scaleLinear()
160
+ // .domain([0, 5])
161
+ // .range(['hsl(152,80%,80%)', 'hsl(228,30%,40%)'])
162
+ // .interpolate(d3.interpolateHcl);
163
+
164
+ // // returns a function that formats numbers
165
+ // const numFormat = d3.format(',d');
166
+
167
+ // const margin = {
168
+ // top: 0, right: 60, bottom: 200, left: 120,
169
+ // };
170
+
171
+ // // create a new circle packing layout function
172
+ // const pack = data => d3.pack()
173
+ // .size([width, height])
174
+ // .padding(3)(d3.hierarchy(data)
175
+ // .sum(d => d.value)
176
+ // .sort((a, b) => b.value - a.value));
177
+
178
+ // useEffect(() => {
179
+ // const hierarchy = d3.hierarchy(chartData);
180
+ // console.log('PerfView -> hierarchy', hierarchy);
181
+ // // const dataRoot = pack(chartData);
182
+ // const dataRoot = pack(hierarchy);
183
+ // console.log('PerfView -> dataRoot', dataRoot);
184
+ // // const focus = dataRoot;
185
+ // // let view;
186
+
187
+ // // const svg = d3.create('svg')
188
+ // // .attr('viewBox', `-${width / 2} -${height / 2} ${width} ${height}`)
189
+ // // .style('display', 'block')
190
+ // // .style('margin', '0 -14px')
191
+ // // .style('background', color(0))
192
+ // // .style('cursor', 'pointer');
193
+ // // .on('click', () => zoom(dataRoot));
194
+
195
+ // const gElem = d3.select(d3gRef);
196
+ // // const node = g.append('g')
197
+ // const node = gElem.selectAll('circle')
198
+ // .data(dataRoot.descendants().slice(1));
199
+ // // .join('circle')
200
+ // node.enter().append('circle')
201
+ // .attr('fill', d => (d.children ? color(d.depth) : 'white'));
202
+ // // .attr('pointer-events', d => (!d.children ? 'none' : null))
203
+ // // .on('mouseover', function () { d3.select(this).attr('stroke', '#000'); })
204
+ // // .on('mouseout', function () { d3.select(this).attr('stroke', null); })
205
+ // // .on('click', d => focus !== d && (zoom(d), d3.event.stopPropagation()));
206
+
207
+ // // const label = g.append('g')
208
+ // // .style('font', '10px sans-serif')
209
+ // // .attr('pointer-events', 'none')
210
+ // // .attr('text-anchor', 'middle')
211
+ // // .selectAll('text')
212
+ // // .data(dataRoot.descendants())
213
+ // // // .join('text')
214
+ // // .enter()
215
+ // // .append('text')
216
+ // // .style('fill-opacity', d => (d.parent === dataRoot ? 1 : 0))
217
+ // // .style('display', d => (d.parent === dataRoot ? 'inline' : 'none'))
218
+ // // .text(d => d.data.name);
219
+ // }, [chartData]);
220
+
221
+ // // return (<svg ref={d3svgRef} width={width} height={height} />);
222
+ // return (
223
+ // <svg width={width} height={height} className="d3Container">
224
+ // <g ref={d3gRef} transform={`translate(${50} ${50})`} />
225
+ // <rect width="100" height="100" x="50" y="20" />
226
+ // </svg>
227
+ // );
228
+ // };
0 commit comments