18
18
19
19
import React , { useEffect , useState , useRef , useCallback } from 'react' ;
20
20
import * as d3 from 'd3' ;
21
+ import { schemeSet1 as colorScheme } from 'd3' ;
22
+
21
23
// import { addNewSnapshots } from '../actions/actions';
22
24
23
25
@@ -33,8 +35,15 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
33
35
// Set up color scaling function
34
36
const colorScale = d3 . scaleLinear ( )
35
37
. domain ( [ 0 , 7 ] )
36
- . range ( [ 'hsl(152,80%,80 %)' , 'hsl(228 ,30%,40 %)' ] )
38
+ . range ( [ 'hsl(200,60%,60 %)' , 'hsl(255 ,30%,30 %)' ] )
37
39
. interpolate ( d3 . interpolateHcl ) ;
40
+ // const colorScale = d3.scaleLinear()
41
+ // .domain([0, 7])
42
+ // .range(['#60c96e', '#4d4193'])
43
+ // .interpolate(d3.interpolateHcl);
44
+
45
+ // d3.quantize(d3.interpolateHcl('#60c96e', '#4d4193'), 10);
46
+ // const colorScale = d3.scaleOrdinal(colorScheme);
38
47
39
48
// Set up circle-packing layout function
40
49
const packFunc = useCallback ( data => {
@@ -47,7 +56,7 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
47
56
48
57
// If indexToDisplay changes, clear old tree nodes
49
58
useEffect ( ( ) => {
50
- console . log ( '***** useEffect - CLEARING' )
59
+ console . log ( '***** useEffect - CLEARING' ) ;
51
60
while ( svgRef . current . hasChildNodes ( ) ) {
52
61
svgRef . current . removeChild ( svgRef . current . lastChild ) ;
53
62
}
@@ -61,7 +70,7 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
61
70
62
71
// Set initial focus root node
63
72
let curFocus = packedRoot ;
64
-
73
+
65
74
// View [x, y, r]
66
75
let view ;
67
76
@@ -75,21 +84,22 @@ const PerfView = ({ snapshots, viewIndex, width = 600, height = 600 }) => {
75
84
. selectAll ( 'circle' )
76
85
. data ( packedRoot . descendants ( ) . slice ( 1 ) )
77
86
. enter ( ) . append ( 'circle' )
78
- . attr ( 'fill' , d => ( d . children ? colorScale ( d . depth ) : 'white' ) )
79
- . attr ( 'pointer-events' , d => ( ! d . children ? 'none' : null ) )
80
- . on ( 'mouseover' , ( ) => d3 . select ( this ) . attr ( 'stroke' , '#000' ) )
81
- . on ( 'mouseout' , ( ) => d3 . select ( this ) . attr ( 'stroke' , null ) )
82
- . on ( 'click' , d => curFocus !== d && ( zoomToNode ( d ) , d3 . event . stopPropagation ( ) ) ) ;
87
+ . attr ( 'fill' , d => ( d . children ? colorScale ( d . depth ) : 'white' ) )
88
+ . attr ( 'pointer-events' , d => ( ! d . children ? 'none' : null ) )
89
+ . on ( 'mouseover' , ( ) => d3 . select ( this ) . attr ( 'stroke' , '#000' ) )
90
+ . on ( 'mouseout' , ( ) => d3 . select ( this ) . attr ( 'stroke' , null ) )
91
+ . on ( 'click' , d => curFocus !== d && ( zoomToNode ( d ) , d3 . event . stopPropagation ( ) ) ) ;
83
92
84
93
// Generate text labels. Set (only) root to visible initially
85
94
const label = svg . append ( 'g' )
86
- . attr ( 'class' , 'perf-chart-labels' )
95
+ // .style('fill', 'rgb(231, 231, 231)')
96
+ . attr ( 'class' , 'perf-chart-labels' )
87
97
. selectAll ( 'text' )
88
98
. data ( packedRoot . descendants ( ) )
89
99
. enter ( ) . append ( 'text' )
90
- . style ( 'fill-opacity' , d => ( d . parent === packedRoot ? 1 : 0 ) )
91
- . style ( 'display' , d => ( d . parent === packedRoot ? 'inline' : 'none' ) )
92
- . text ( d => `${ d . data . name } : \
100
+ . style ( 'fill-opacity' , d => ( d . parent === packedRoot ? 1 : 0 ) )
101
+ . style ( 'display' , d => ( d . parent === packedRoot ? 'inline' : 'none' ) )
102
+ . text ( d => `${ d . data . name } : \
93
103
${ Number . parseFloat ( d . data . componentData . actualDuration ) . toFixed ( 2 ) } ms` ) ;
94
104
95
105
// Remove any unused nodes
0 commit comments