@@ -5,29 +5,28 @@ import d3Tip from 'd3-tip';
55import { partition , hierarchy } from 'd3-hierarchy' ;
66import 'd3-transition' ;
77
8- let indexOf = [ ] . indexOf || function ( item ) {
9- for ( var i = 0 , l = this . length ; i < l ; i ++ ) { if ( i in this && this [ i ] === item ) return i ; }
10- return - 1 ;
11- } ;
12-
13- let getClassAndMethodName = function ( fqdn ) {
14- let tokens ;
8+ function getClassAndMethodName ( fqdn ) {
159 if ( ! fqdn ) {
1610 return "" ;
1711 }
18- tokens = fqdn . split ( "." ) ;
12+ let tokens = fqdn . split ( "." ) ;
1913 return tokens . slice ( tokens . length - 2 ) . join ( "." ) ;
20- } ;
14+ }
2115
2216// Return a vector (0.0 -> 1.0) that is a hash of the input string.
2317// The hash is computed to favor early characters over later ones, so
2418// that strings with similar starts have similar vectors. Only the first
2519// 6 characters are considered.
26- let hash = function ( name ) {
27- let i , j , maxHash , mod , ref , ref1 , result , weight ;
28- ref = [ 0 , 0 , 1 , 10 ] , result = ref [ 0 ] , maxHash = ref [ 1 ] , weight = ref [ 2 ] , mod = ref [ 3 ] ;
20+ function hash ( name ) {
21+ let ref = [ 0 , 0 , 1 , 10 ] ;
22+ let result = ref [ 0 ] ;
23+ let maxHash = ref [ 1 ] ;
24+ let weight = ref [ 2 ] ;
25+ let mod = ref [ 3 ] ;
26+
2927 name = getClassAndMethodName ( name ) . slice ( 0 , 6 ) ;
30- for ( i = j = 0 , ref1 = name . length - 1 ; 0 <= ref1 ? j <= ref1 : j >= ref1 ; i = 0 <= ref1 ? ++ j : -- j ) {
28+
29+ for ( let i = 0 , j = 0 , ref1 = name . length - 1 ; 0 <= ref1 ? j <= ref1 : j >= ref1 ; i = 0 <= ref1 ? ++ j : -- j ) {
3130 result += weight * ( name . charCodeAt ( i ) % mod ) ;
3231 maxHash += weight * ( mod - 1 ) ;
3332 weight *= 0.7 ;
@@ -37,7 +36,7 @@ let hash = function(name) {
3736 } else {
3837 return result ;
3938 }
40- } ;
39+ }
4140
4241const FlameGraphUtils = {
4342 // augments each node in the tree with the maximum distance
@@ -58,9 +57,7 @@ const FlameGraphUtils = {
5857 node . augmented = true ;
5958 return node ;
6059 }
61- let childSum = children . reduce ( ( function ( sum , child ) {
62- return sum + child . value ;
63- } ) , 0 ) ;
60+ let childSum = children . reduce ( ( sum , child ) => sum + child . value , 0 ) ;
6461 if ( childSum < node . value ) {
6562 children . push ( {
6663 value : node . value - childSum ,
@@ -72,6 +69,7 @@ const FlameGraphUtils = {
7269 node . augmented = true ;
7370 return node ;
7471 } ,
72+
7573 partition ( data ) {
7674 let d3partition = partition ( ) ;
7775
@@ -89,6 +87,7 @@ const FlameGraphUtils = {
8987 } ) ;
9088 return d3partition ( root ) . descendants ( ) ;
9189 } ,
90+
9291 hide ( nodes , unhide ) {
9392 if ( unhide === null ) {
9493 unhide = false ;
@@ -134,7 +133,8 @@ const FlameGraphUtils = {
134133 } ) ;
135134 }
136135} ;
137- class FlameGraph {
136+
137+ export default class FlameGraph {
138138 constructor ( selector , root , debug ) {
139139 this . _selector = selector ;
140140 this . _generateAccessors ( [ 'margin' , 'cellHeight' , 'zoomEnabled' , 'zoomAction' , 'tooltip' , 'tooltipPlugin' , 'color' , 'labelFunction' ] ) ;
@@ -226,7 +226,7 @@ class FlameGraph {
226226 if ( this . tip ) {
227227 this . tip . hide ( ) ;
228228 }
229- if ( indexOf . call ( this . _ancestors , node ) >= 0 ) {
229+ if ( this . _ancestors . indexOf ( node ) >= 0 ) {
230230 this . _ancestors = this . _ancestors . slice ( 0 , this . _ancestors . indexOf ( node ) ) ;
231231 } else {
232232 this . _ancestors . push ( this . _root ) ;
@@ -399,14 +399,14 @@ class FlameGraph {
399399 . attr ( 'class' , 'label' )
400400 . style ( 'font-size' , this . fontSize + "em" )
401401 . transition ( ) . attr ( 'dy' , ( this . fontSize / 2 ) + "em" ) . attr ( 'x' , ( function ( ) {
402- return function ( d ) {
403- return attrs . x ( d ) + 2 ;
404- } ;
405- } ) ( this ) ) . attr ( 'y' , ( function ( _this ) {
406- return function ( d , idx ) {
407- return attrs . y ( d , idx ) + _this . cellHeight ( ) / 2 ;
408- } ;
409- } ) ( this ) ) . text ( attrs . text ) ;
402+ return function ( d ) {
403+ return attrs . x ( d ) + 2 ;
404+ } ;
405+ } ) ( this ) ) . attr ( 'y' , ( function ( _this ) {
406+ return function ( d , idx ) {
407+ return attrs . y ( d , idx ) + _this . cellHeight ( ) / 2 ;
408+ } ;
409+ } ) ( this ) ) . text ( attrs . text ) ;
410410 return this ;
411411 }
412412
@@ -546,5 +546,3 @@ class FlameGraph {
546546 return results ;
547547 }
548548}
549-
550- export default FlameGraph ;
0 commit comments