1
+ /* eslint-disable class-methods-use-this */
2
+ // eslint-disable-next-line object-curly-newline
3
+ /* eslint-disable comma-dangle */
1
4
/* eslint-disable indent */
2
5
/* eslint-disable react/destructuring-assignment */
3
6
/* eslint-disable react/prop-types */
4
7
/* eslint-disable no-console */
5
8
import React , { useEffect , useRef } from 'react' ;
6
9
import * as d3 from 'd3' ;
7
10
8
-
9
- // let root = {};
10
11
const chartData = {
11
12
name : 'App' ,
12
13
children : [
@@ -38,8 +39,7 @@ const chartData = {
38
39
] ,
39
40
} ;
40
41
41
-
42
- const PerfView = ( { width, height } ) => {
42
+ const PerfView = ( { width= 200 , height= 200 } ) => {
43
43
const svgRef = useRef ( null ) ;
44
44
// returns color scale function
45
45
const color = d3 . scaleLinear ( )
@@ -50,9 +50,7 @@ const PerfView = ({ width, height }) => {
50
50
// returns a function that formats numbers
51
51
const numFormat = d3 . format ( ',d' ) ;
52
52
53
- const margin = {
54
- top : 0 , right : 60 , bottom : 200 , left : 120 ,
55
- } ;
53
+ const margin = { top : 0 , right : 60 , bottom : 200 , left : 120 , } ;
56
54
57
55
// create a new circle packing layout function
58
56
const packFunc = data => d3 . pack ( )
@@ -140,112 +138,120 @@ const PerfView = ({ width, height }) => {
140
138
return < svg ref = { svgRef } /> ;
141
139
} ;
142
140
143
- export default PerfView ;
144
-
145
-
146
141
// class PerfView extends React.Component {
147
142
// constructor(props) {
148
143
// super(props);
149
- // this.svgRef = React.createRef();
150
-
144
+ // this.svgRef = React.createRef(null);
151
145
// // returns color scale function
152
146
// this.color = d3.scaleLinear()
153
147
// .domain([0, 5])
154
148
// .range(['hsl(152,80%,80%)', 'hsl(228,30%,40%)'])
155
149
// .interpolate(d3.interpolateHcl);
156
-
150
+
151
+ // // returns a function that formats numbers
152
+ // this.numFormat = d3.format(',d');
153
+
154
+ // this.margin = { top: 0, right: 60, bottom: 200, left: 120, };
155
+
157
156
// // create a new circle packing layout function
158
- // this.pack = data => d3.pack()
157
+ // this.packFunc = data => d3.pack()
159
158
// .size([this.props.width, this.props.height])
160
159
// .padding(3)(d3.hierarchy(data)
161
- // .sum(d => d.value)
162
- // .sort((a, b) => b.value - a.value));
163
-
164
- // // this.drawChart = this.drawChart.bind(this);
160
+ // .sum(d => d.value)
161
+ // .sort((a, b) => b.value - a.value));
162
+
163
+ // this.drawChart = this.drawChart.bind(this);
165
164
// }
166
165
167
166
// componentDidMount() {
168
- // const { width, height } = this.props;
169
-
170
- // const hierarchy = d3.hierarchy(chartData);
171
- // console.log('PerfView -> hierarchy', hierarchy);
172
- // // const dataRoot = pack(chartData);
173
- // const dataRoot = d3.pack(hierarchy);
174
- // console.log('PerfView -> dataRoot', dataRoot);
167
+ // this.drawChart();
168
+ // }
169
+
170
+ // componentDidUpdate() {
171
+ // this.drawChart();
172
+ // }
175
173
176
- // const focus = dataRoot;
174
+ // drawChart() {
175
+ // console.log("PerfView -> drawChart -> chartData", chartData)
176
+ // console.log("PerfView -> drawChart -> this.props.width", this.props.width)
177
+ // const packedRoot = this.packFunc(chartData);
178
+ // // console.log('** PerfView -> packedRoot', packedRoot);
179
+ // let focus = packedRoot;
177
180
// let view;
181
+ // console.log('packedRoot.descendents().slice(1)', packedRoot.descendants().slice(1));
178
182
179
- // const svg = d3.select(this.svgRef.current);
180
- // svg
183
+ // const svg = d3.select(this.svgRef.current)
181
184
// .attr('class', 'd3Container')
182
- // .attr('viewBox', `-${width / 2} -${height / 2} ${width} ${height}`)
185
+ // .attr('viewBox', `-${this.props. width / 2} -${this.props. height / 2} ${this.props. width} ${this.props. height}`)
183
186
// .style('display', 'block')
184
187
// .style('margin', '0 -14px')
185
188
// .style('background', this.color(0))
186
- // .style('cursor', 'pointer');
187
- // // .on("click", () => zoom(root));
189
+ // .style('cursor', 'pointer')
190
+ // .on('click', () => zoom(packedRoot));
191
+
192
+
193
+ // const node = svg.append('g')
194
+ // .selectAll('circle')
195
+ // .data(packedRoot.descendants().slice(1))
196
+ // // .join('circle')
197
+ // .enter()
198
+ // .append('circle')
199
+ // .attr('fill', d => (d.children ? this.color(d.depth) : 'white'))
200
+ // .attr('pointer-events', d => (!d.children ? 'none' : null))
201
+ // .on('mouseover', function () { d3.select(this).attr('stroke', '#000'); })
202
+ // .on('mouseout', function () { d3.select(this).attr('stroke', null); })
203
+ // .on('click', d => focus !== d && (zoom(d), d3.event.stopPropagation()));
204
+
205
+ // const label = svg.append('g')
206
+ // .style('font', '10px sans-serif')
207
+ // .attr('pointer-events', 'none')
208
+ // .attr('text-anchor', 'middle')
209
+ // .selectAll('text')
210
+ // .data(packedRoot.descendants())
211
+ // // .join('text')
212
+ // .enter()
213
+ // .append('text')
214
+ // .style('fill-opacity', d => (d.parent === packedRoot ? 1 : 0))
215
+ // .style('display', d => (d.parent === packedRoot ? 'inline' : 'none'))
216
+ // .text(d => d.data.name);
217
+
218
+ // console.log('PerfView -> node', node);
219
+
220
+ // zoomTo([packedRoot.x, packedRoot.y, packedRoot.r * 2], this.props.width);
221
+
222
+ // function zoomTo(v, width) {
223
+ // const k = width / v[2];
224
+ // view = v;
225
+
226
+ // label.attr('transform', d => `translate(${(d.x - v[0]) * k},${(d.y - v[1]) * k})`);
227
+ // node.attr('transform', d => `translate(${(d.x - v[0]) * k},${(d.y - v[1]) * k})`);
228
+ // node.attr('r', d => d.r * k);
229
+ // }
230
+
231
+ // function zoom(d) {
232
+ // const focus0 = focus;
233
+
234
+ // focus = d;
235
+
236
+ // const transition = svg.transition()
237
+ // .duration(d3.event.altKey ? 7500 : 750)
238
+ // .tween('zoom', d => {
239
+ // const i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2]);
240
+ // return t => zoomTo(i(t));
241
+ // });
242
+
243
+ // label
244
+ // .filter(function (d) { return d.parent === focus || this.style.display === 'inline'; })
245
+ // .transition(transition)
246
+ // .style('fill-opacity', d => (d.parent === focus ? 1 : 0))
247
+ // .on('start', function (d) { if (d.parent === focus) this.style.display = 'inline'; })
248
+ // .on('end', function (d) { if (d.parent !== focus) this.style.display = 'none'; });
249
+ // }
188
250
// }
189
251
190
- // componentDidUpdate() {
191
- // const svg = d3.select(this.ref.current);
192
- // }
193
-
194
- // // drawChart() {
195
- // // // const hierarchy = d3.hierarchy(chartData);
196
- // // // const dataRoot = this.pack(hierarchy);
197
-
198
- // // d3.create("svg").attr("viewBox", );
199
-
200
- // // }
201
-
202
252
// render() {
203
- // return (
204
- // <svg ref={this.svgRef} />
205
- // );
253
+ // return <svg ref={this.svgRef} />;
206
254
// }
207
255
// }
208
256
209
- /* eslint-disable indent */
210
-
211
-
212
- // const data = {
213
- // type,
214
- // elementType,
215
- // children,
216
- // pendingProps,
217
- // memoizedProps,
218
- // stateNode,
219
- // memoizedState,
220
- // actualDuration,
221
- // actualStartTime,
222
- // selfBaseDuration,
223
- // treeBaseDuration
224
- // }
225
-
226
- // const dataMax = d3.max(props.data);
227
-
228
- // const yScale = d3.scaleLinear()
229
- // .domain([0, dataMax])
230
- // .range([0, props.size[1]]);
231
-
232
- // d3.select(thisRef.current)
233
- // .selectAll('rect')
234
- // .data(props.data)
235
- // .enter()
236
- // .append('rect');
237
-
238
- // d3.select(thisRef.current)
239
- // .selectAll('rect')
240
- // .data(props.data)
241
- // .exit()
242
- // .remove();
243
-
244
- // d3.select(thisRef.current)
245
- // .selectAll('rect')
246
- // .data(props.data)
247
- // .style('fill', '#fe9922')
248
- // .attr('x', (d, i) => i * 25)
249
- // .attr('y', d => props.size[1] - yScale(d))
250
- // .attr('height', d => yScale(d))
251
- // .attr('width', 25);
257
+ export default PerfView ;
0 commit comments