@@ -11,26 +11,36 @@ import React, { useEffect, useRef } from 'react';
11
11
import * as d3 from 'd3' ;
12
12
import { addNewSnapshots } from '../actions/actions' ;
13
13
14
+ const chartData = {
15
+ name : 'App' ,
16
+ actualDuration : 35000 ,
17
+ value : 17010 ,
18
+ 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 } ,
23
+ ] ,
24
+ } ;
25
+
14
26
const PerfView = ( {
15
27
width = 200 ,
16
28
height = 200 ,
17
- snapshots
29
+ // snapshots
18
30
} ) => {
19
- console . log ( 'this is snapshots at PerfView' , snapshots ) ;
20
- console . log ( 'this is snapshots[snapshots.length-1] at PerfView' , snapshots [ snapshots . length - 1 ] ) ;
21
- const chartData = snapshots [ snapshots . length - 1 ] ;
31
+ // const chartData = snapshots;
32
+ // const chartData = snapshots[snapshots.length - 1].children[0];
33
+ // console.log("snapshots", snapshots);
34
+ console . log ( "chartData" , chartData ) ;
35
+
22
36
const svgRef = useRef ( null ) ;
37
+
23
38
// returns color scale function
24
39
const color = d3 . scaleLinear ( )
25
40
. domain ( [ 0 , 5 ] )
26
41
. range ( [ 'hsl(152,80%,80%)' , 'hsl(228,30%,40%)' ] )
27
42
. interpolate ( d3 . interpolateHcl ) ;
28
43
29
- // returns a function that formats numbers
30
- const numFormat = d3 . format ( ',d' ) ;
31
-
32
- const margin = { top : 0 , right : 60 , bottom : 200 , left : 120 , } ;
33
-
34
44
// create a new circle packing layout function
35
45
const packFunc = data => d3 . pack ( )
36
46
. size ( [ width , height ] )
@@ -70,7 +80,7 @@ const PerfView = ({
70
80
. append ( 'text' )
71
81
. style ( 'fill-opacity' , d => ( d . parent === packedRoot ? 1 : 0 ) )
72
82
. style ( 'display' , d => ( d . parent === packedRoot ? 'inline' : 'none' ) )
73
- . text ( d => `${ d . data . name } : ${ Number . parseFloat ( d . data . actualDuration ) . toFixed ( 2 ) } ms` ) ;
83
+ . text ( d => `${ d . name } : ${ Number . parseFloat ( d . actualDuration ) . toFixed ( 2 ) } ms` ) ;
74
84
75
85
console . log ( 'PerfView -> node' , node ) ;
76
86
zoomTo ( [ packedRoot . x , packedRoot . y , packedRoot . r * 2 ] ) ;
@@ -105,123 +115,8 @@ const PerfView = ({
105
115
}
106
116
} , [ chartData ] ) ;
107
117
108
- return < div className = "d3divContainer" > < svg viewBox = "-250 -250 500 500" className = "perfContainer" ref = { svgRef } /> </ div > ;
118
+ return < svg viewBox = "-250 -250 500 500" className = "perfContainer" ref = { svgRef } /> ;
109
119
} ;
110
120
111
- // class PerfView extends React.Component {
112
- // constructor(props) {
113
- // super(props);
114
- // this.svgRef = React.createRef(null);
115
- // // returns color scale function
116
- // this.color = d3.scaleLinear()
117
- // .domain([0, 5])
118
- // .range(['hsl(152,80%,80%)', 'hsl(228,30%,40%)'])
119
- // .interpolate(d3.interpolateHcl);
120
-
121
- // // returns a function that formats numbers
122
- // this.numFormat = d3.format(',d');
123
-
124
- // this.margin = { top: 0, right: 60, bottom: 200, left: 120, };
125
-
126
- // // create a new circle packing layout function
127
- // this.packFunc = data => d3.pack()
128
- // .size([this.props.width, this.props.height])
129
- // .padding(3)(d3.hierarchy(data)
130
- // .sum(d => d.value)
131
- // .sort((a, b) => b.value - a.value));
132
-
133
- // this.drawChart = this.drawChart.bind(this);
134
- // }
135
-
136
- // componentDidMount() {
137
- // this.drawChart();
138
- // }
139
-
140
- // componentDidUpdate() {
141
- // this.drawChart();
142
- // }
143
-
144
- // drawChart() {
145
- // console.log("PerfView -> drawChart -> chartData", chartData)
146
- // console.log("PerfView -> drawChart -> this.props.width", this.props.width)
147
- // const packedRoot = this.packFunc(chartData);
148
- // // console.log('** PerfView -> packedRoot', packedRoot);
149
- // let focus = packedRoot;
150
- // let view;
151
- // console.log('packedRoot.descendents().slice(1)', packedRoot.descendants().slice(1));
152
-
153
- // const svg = d3.select(this.svgRef.current)
154
- // .attr('class', 'd3Container')
155
- // .attr('viewBox', `-${this.props.width / 2} -${this.props.height / 2} ${this.props.width} ${this.props.height}`)
156
- // .style('display', 'block')
157
- // .style('margin', '0 -14px')
158
- // .style('background', this.color(0))
159
- // .style('cursor', 'pointer')
160
- // .on('click', () => zoom(packedRoot));
161
-
162
-
163
- // const node = svg.append('g')
164
- // .selectAll('circle')
165
- // .data(packedRoot.descendants().slice(1))
166
- // // .join('circle')
167
- // .enter()
168
- // .append('circle')
169
- // .attr('fill', d => (d.children ? this.color(d.depth) : 'white'))
170
- // .attr('pointer-events', d => (!d.children ? 'none' : null))
171
- // .on('mouseover', function () { d3.select(this).attr('stroke', '#000'); })
172
- // .on('mouseout', function () { d3.select(this).attr('stroke', null); })
173
- // .on('click', d => focus !== d && (zoom(d), d3.event.stopPropagation()));
174
-
175
- // const label = svg.append('g')
176
- // .style('font', '10px sans-serif')
177
- // .attr('pointer-events', 'none')
178
- // .attr('text-anchor', 'middle')
179
- // .selectAll('text')
180
- // .data(packedRoot.descendants())
181
- // // .join('text')
182
- // .enter()
183
- // .append('text')
184
- // .style('fill-opacity', d => (d.parent === packedRoot ? 1 : 0))
185
- // .style('display', d => (d.parent === packedRoot ? 'inline' : 'none'))
186
- // .text(d => d.data.name);
187
-
188
- // console.log('PerfView -> node', node);
189
-
190
- // zoomTo([packedRoot.x, packedRoot.y, packedRoot.r * 2], this.props.width);
191
-
192
- // function zoomTo(v, width) {
193
- // const k = width / v[2];
194
- // view = v;
195
-
196
- // label.attr('transform', d => `translate(${(d.x - v[0]) * k},${(d.y - v[1]) * k})`);
197
- // node.attr('transform', d => `translate(${(d.x - v[0]) * k},${(d.y - v[1]) * k})`);
198
- // node.attr('r', d => d.r * k);
199
- // }
200
-
201
- // function zoom(d) {
202
- // const focus0 = focus;
203
-
204
- // focus = d;
205
-
206
- // const transition = svg.transition()
207
- // .duration(d3.event.altKey ? 7500 : 750)
208
- // .tween('zoom', d => {
209
- // const i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2]);
210
- // return t => zoomTo(i(t));
211
- // });
212
-
213
- // label
214
- // .filter(function (d) { return d.parent === focus || this.style.display === 'inline'; })
215
- // .transition(transition)
216
- // .style('fill-opacity', d => (d.parent === focus ? 1 : 0))
217
- // .on('start', function (d) { if (d.parent === focus) this.style.display = 'inline'; })
218
- // .on('end', function (d) { if (d.parent !== focus) this.style.display = 'none'; });
219
- // }
220
- // }
221
-
222
- // render() {
223
- // return <svg ref={this.svgRef} />;
224
- // }
225
- // }
226
121
227
122
export default PerfView ;
0 commit comments