@@ -487,38 +487,54 @@ function getHeatColors() {
487487 return colors ;
488488}
489489
490- function getDiffColor ( node ) {
490+ function getDiffColors ( ) {
491491 const style = getComputedStyle ( document . documentElement ) ;
492+ return {
493+ elided : style . getPropertyValue ( '--diff-elided' ) . trim ( ) ,
494+ new : style . getPropertyValue ( '--diff-new' ) . trim ( ) ,
495+ neutral : style . getPropertyValue ( '--diff-neutral' ) . trim ( ) ,
496+ regressionDeep : style . getPropertyValue ( '--diff-regression-deep' ) . trim ( ) ,
497+ regressionMedium : style . getPropertyValue ( '--diff-regression-medium' ) . trim ( ) ,
498+ regressionLight : style . getPropertyValue ( '--diff-regression-light' ) . trim ( ) ,
499+ regressionVerylight : style . getPropertyValue ( '--diff-regression-verylight' ) . trim ( ) ,
500+ improvementDeep : style . getPropertyValue ( '--diff-improvement-deep' ) . trim ( ) ,
501+ improvementMedium : style . getPropertyValue ( '--diff-improvement-medium' ) . trim ( ) ,
502+ improvementLight : style . getPropertyValue ( '--diff-improvement-light' ) . trim ( ) ,
503+ improvementVerylight : style . getPropertyValue ( '--diff-improvement-verylight' ) . trim ( ) ,
504+ } ;
505+ }
492506
507+ function getDiffColorForNode ( node , diffColors ) {
493508 if ( isShowingElided ) {
494- return style . getPropertyValue ( '--diff- elided' ) . trim ( ) ;
509+ return diffColors . elided ;
495510 }
496511
497512 const diff_pct = node . data . diff_pct || 0 ;
498513 const diff_samples = node . data . diff || 0 ;
499514 const self_time = node . data . self_time || 0 ;
500515
501516 if ( diff_pct === 100 && self_time > 0 && Math . abs ( diff_samples - self_time ) < 0.1 ) {
502- return style . getPropertyValue ( '--diff- new' ) . trim ( ) ;
517+ return diffColors . new ;
503518 }
504519
505520 // Neutral zone: small percentage change
506521 if ( Math . abs ( diff_pct ) < 15 ) {
507- return style . getPropertyValue ( '--diff- neutral' ) . trim ( ) ;
522+ return diffColors . neutral ;
508523 }
509524
510525 // Regression (red scale)
511526 if ( diff_pct > 0 ) {
512- if ( diff_pct >= 100 ) return style . getPropertyValue ( '--diff-regression-deep' ) . trim ( ) ;
513- if ( diff_pct > 50 ) return style . getPropertyValue ( '--diff-regression-medium' ) . trim ( ) ;
514- if ( diff_pct > 30 ) return style . getPropertyValue ( '--diff-regression-light' ) . trim ( ) ;
515- return style . getPropertyValue ( '--diff-regression-verylight' ) . trim ( ) ;
527+ if ( diff_pct >= 100 ) return diffColors . regressionDeep ;
528+ if ( diff_pct > 50 ) return diffColors . regressionMedium ;
529+ if ( diff_pct > 30 ) return diffColors . regressionLight ;
530+ return diffColors . regressionVerylight ;
516531 }
517532
518533 // Improvement (blue scale)
519- if ( diff_pct < - 50 ) return style . getPropertyValue ( '--diff-improvement-medium' ) . trim ( ) ;
520- if ( diff_pct < - 30 ) return style . getPropertyValue ( '--diff-improvement-light' ) . trim ( ) ;
521- return style . getPropertyValue ( '--diff-improvement-verylight' ) . trim ( ) ;
534+ if ( diff_pct <= - 100 ) return diffColors . improvementDeep ;
535+ if ( diff_pct < - 50 ) return diffColors . improvementMedium ;
536+ if ( diff_pct < - 30 ) return diffColors . improvementLight ;
537+ return diffColors . improvementVerylight ;
522538}
523539
524540function createFlamegraph ( tooltip , rootValue , data ) {
@@ -527,6 +543,7 @@ function createFlamegraph(tooltip, rootValue, data) {
527543 const heatColors = getHeatColors ( ) ;
528544
529545 const isDifferential = data && data . stats && data . stats . is_differential ;
546+ const diffColors = isDifferential ? getDiffColors ( ) : null ;
530547
531548 let chart = flamegraph ( )
532549 . width ( width )
@@ -539,7 +556,7 @@ function createFlamegraph(tooltip, rootValue, data) {
539556 if ( d . depth === 0 ) return 'transparent' ;
540557
541558 if ( isDifferential ) {
542- return getDiffColor ( d ) ;
559+ return getDiffColorForNode ( d , diffColors ) ;
543560 }
544561
545562 const percentage = d . data . value / rootValue ;
0 commit comments