Skip to content

Commit 0bbd105

Browse files
committed
working foundation d3 chart w temp data transfer
1 parent 742ec76 commit 0bbd105

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

src/app/components/PerfView.jsx

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,40 @@ import { addNewSnapshots } from '../actions/actions';
1313

1414
// const chartData = {
1515
// name: 'App',
16-
// actualDuration: 35000,
17-
// value: 17010,
1816
// 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 } },
2321
// ],
2422
// };
2523

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+
2641
const PerfView = ({
2742
width = 200,
2843
height = 200,
2944
snapshots
3045
}) => {
31-
// const chartData = snapshots;
32-
console.log("snapshots", snapshots);
46+
console.log('snapshots', snapshots);
3347
const chartData = snapshots[snapshots.length - 1].children[0];
34-
console.log("chartData", chartData);
48+
moveCompData(chartData);
49+
console.log('chartData', chartData);
3550

3651
const svgRef = useRef(null);
3752

@@ -45,8 +60,13 @@ const PerfView = ({
4560
const packFunc = data => d3.pack()
4661
.size([width, height])
4762
.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);
5070

5171
useEffect(() => {
5272
const packedRoot = packFunc(chartData);
@@ -59,8 +79,8 @@ const PerfView = ({
5979

6080
const node = svg.append('g')
6181
.selectAll('circle')
62-
.data(packedRoot.descendants().slice(1))
63-
// .join('circle')
82+
.data(packedRoot.descendants().slice(1))
83+
6484
.enter()
6585
.append('circle')
6686
.attr('fill', d => (d.children ? color(d.depth) : 'white'))
@@ -69,20 +89,20 @@ const PerfView = ({
6989
.on('mouseout', function () { d3.select(this).attr('stroke', null); })
7090
.on('click', d => focus !== d && (zoom(d), d3.event.stopPropagation()));
7191

92+
console.log('PerfView -> node', node);
93+
7294
const label = svg.append('g')
7395
.style('font', '11px sans-serif')
7496
.attr('pointer-events', 'none')
7597
.attr('text-anchor', 'middle')
7698
.selectAll('text')
7799
.data(packedRoot.descendants())
78-
// .join('text')
79100
.enter()
80101
.append('text')
81102
.style('fill-opacity', d => (d.parent === packedRoot ? 1 : 0))
82103
.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`);
84105

85-
console.log('PerfView -> node', node);
86106
zoomTo([packedRoot.x, packedRoot.y, packedRoot.r * 2]);
87107

88108
function zoomTo(v) {

0 commit comments

Comments
 (0)