@@ -507,9 +507,15 @@ export function positionEllipse(ellipse, cx: number, cy: number,
507
507
508
508
/**
509
509
* @param {number } stat A stat for a health pill (such as mean or variance).
510
+ * @param {boolean } shouldRoundOnesDigit Whether to round this number to the
511
+ * ones digit. Useful for say int, uint, and bool output types.
510
512
* @return {string } A human-friendly string representation of that stat.
511
513
*/
512
- function _humanizeHealthPillStat ( stat ) {
514
+ export function humanizeHealthPillStat ( stat , shouldRoundOnesDigit ) {
515
+ if ( shouldRoundOnesDigit ) {
516
+ return stat . toFixed ( 0 ) ;
517
+ }
518
+
513
519
if ( Math . abs ( stat ) >= 1 ) {
514
520
return stat . toFixed ( 1 ) ;
515
521
}
@@ -521,7 +527,7 @@ function _humanizeHealthPillStat(stat) {
521
527
*/
522
528
function _addHealthPill (
523
529
nodeGroupElement : SVGElement , healthPill : HealthPill ,
524
- nodeInfo : render . RenderGroupNodeInfo ) {
530
+ nodeInfo : render . RenderNodeInfo ) {
525
531
// Check if text already exists at location.
526
532
d3 . select ( nodeGroupElement . parentNode ) . selectAll ( '.health-pill' ) . remove ( ) ;
527
533
@@ -605,13 +611,33 @@ function _addHealthPill(
605
611
healthPillY += nodeInfo . labelOffset ;
606
612
}
607
613
608
- if ( lastHealthPillOverview [ 4 ] || lastHealthPillOverview [ 5 ] ||
609
- lastHealthPillOverview [ 6 ] ) {
610
- // At least 1 "non-Inf and non-NaN" value exists. Show stats on tensor
611
- // values.
614
+ if ( lastHealthPillOverview [ 2 ] || lastHealthPillOverview [ 3 ] ||
615
+ lastHealthPillOverview [ 4 ] ) {
616
+ // At least 1 "non-Inf and non-NaN" value exists (a -, 0, or + value). Show
617
+ // stats on tensor values.
618
+
619
+ // Determine if we should display the output range as integers.
620
+ let shouldRoundOnesDigit = false ;
621
+ let node = nodeInfo . node as OpNode ;
622
+ let attributes = node . attr ;
623
+ if ( attributes && attributes . length ) {
624
+ // Find the attribute for output type if there is one.
625
+ for ( let i = 0 ; i < attributes . length ; i ++ ) {
626
+ if ( attributes [ i ] . key === 'T' ) {
627
+ // Note whether the output type is an integer.
628
+ let outputType = attributes [ i ] . value [ 'type' ] ;
629
+ shouldRoundOnesDigit =
630
+ outputType && / ^ D T _ ( B O O L | I N T | U I N T ) / . test ( outputType ) ;
631
+ break ;
632
+ }
633
+ }
634
+ }
635
+
612
636
let statsSvg = document . createElementNS ( svgNamespace , 'text' ) ;
613
- const minString = _humanizeHealthPillStat ( lastHealthPillData [ 8 ] ) ;
614
- const maxString = _humanizeHealthPillStat ( lastHealthPillData [ 9 ] ) ;
637
+ const minString =
638
+ humanizeHealthPillStat ( lastHealthPillData [ 8 ] , shouldRoundOnesDigit ) ;
639
+ const maxString =
640
+ humanizeHealthPillStat ( lastHealthPillData [ 9 ] , shouldRoundOnesDigit ) ;
615
641
statsSvg . textContent = minString + ' ~ ' + maxString ;
616
642
statsSvg . classList . add ( 'health-pill-stats' ) ;
617
643
statsSvg . setAttribute ( 'x' , String ( healthPillWidth / 2 ) ) ;
@@ -641,7 +667,7 @@ export function addHealthPills(
641
667
642
668
let svgRootSelection = d3 . select ( svgRoot ) ;
643
669
svgRootSelection . selectAll ( 'g.nodeshape' )
644
- . each ( function ( nodeInfo : render . RenderGroupNodeInfo ) {
670
+ . each ( function ( nodeInfo : render . RenderNodeInfo ) {
645
671
// Only show health pill data for this node if it is available.
646
672
let healthPills = nodeNamesToHealthPills [ nodeInfo . node . name ] ;
647
673
let healthPill = healthPills ? healthPills [ healthPillStepIndex ] : null ;
0 commit comments