browserscripts/timings/rumSpeedIndex.js
function() {
      var paints = {'0':0};
      var total = 0;
      for (var i = 0; i < rects.length; i++) {
        var tm = firstPaint;
        if ('tm' in rects[i] && rects[i].tm > firstPaint)
          tm = rects[i].tm;
        if (paints[tm] === undefined)
          paints[tm] = 0;
        paints[tm] += rects[i].area;
        total += rects[i].area;
      }
      // Add a paint area for the page background (count 10% of the pixels not
      // covered by existing paint rects.
      var pixels = Math.max(doc.documentElement.clientWidth, win.innerWidth || 0) *
                   Math.max(doc.documentElement.clientHeight, win.innerHeight || 0);
      if (pixels > 0 ) {
        pixels = Math.max(pixels - total, 0) * pageBackgroundWeight;
        if (paints[firstPaint] === undefined)
          paints[firstPaint] = 0;
        paints[firstPaint] += pixels;
        total += pixels;
      }
      // Calculate the visual progress
      if (total) {
        for (var time in paints) {
          if (paints.hasOwnProperty(time)) {
            progress.push({'tm': time, 'area': paints[time]});
          }
        }
        progress.sort(function(a,b){return a.tm - b.tm;});
        var accumulated = 0;
        for (var j = 0; j < progress.length; j++) {
          accumulated += progress[j].area;
          progress[j].progress = accumulated / total;
        }
      }
    }
function() {
      var paints = {'0':0};
      var total = 0;
      for (var i = 0; i < rects.length; i++) {
        var tm = firstPaint;
        if ('tm' in rects[i] && rects[i].tm > firstPaint)
          tm = rects[i].tm;
        if (paints[tm] === undefined)
          paints[tm] = 0;
        paints[tm] += rects[i].area;
        total += rects[i].area;
      }
      // Add a paint area for the page background (count 10% of the pixels not
      // covered by existing paint rects.
      var pixels = Math.max(doc.documentElement.clientWidth, win.innerWidth || 0) *
                   Math.max(doc.documentElement.clientHeight, win.innerHeight || 0);
      if (pixels > 0 ) {
        pixels = Math.max(pixels - total, 0) * pageBackgroundWeight;
        if (paints[firstPaint] === undefined)
          paints[firstPaint] = 0;
        paints[firstPaint] += pixels;
        total += pixels;
      }
      // Calculate the visual progress
      if (total) {
        for (var time in paints) {
          if (paints.hasOwnProperty(time)) {
            progress.push({'tm': time, 'area': paints[time]});
          }
        }
        progress.sort(function(a,b){return a.tm - b.tm;});
        var accumulated = 0;
        for (var j = 0; j < progress.length; j++) {
          accumulated += progress[j].area;
          progress[j].progress = accumulated / total;
        }
      }
    }
function ( ) { var paints = { '0' : 0 } ; var total = 0 ; for ( var i = 0 ; i < rects . length ; i ++ ) { var tm = firstPaint ; if ( 'tm' in rects [ i ] && rects [ i ] . tm > firstPaint ) tm = rects [ i ] . tm ; if ( paints [ tm ] === undefined ) paints [ tm ] = 0 ; paints [ tm ] += rects [ i ] . area ; total += rects [ i ] . area ; } // Add a paint area for the page background (count 10% of the pixels not // covered by existing paint rects. var pixels = Math . max ( doc . documentElement . clientWidth , win . innerWidth || 0 ) * Math . max ( doc . documentElement . clientHeight , win . innerHeight || 0 ) ; if ( pixels > 0 ) { pixels = Math . max ( pixels - total , 0 ) * pageBackgroundWeight ; if ( paints [ firstPaint ] === undefined ) paints [ firstPaint ] = 0 ; paints [ firstPaint ] += pixels ; total += pixels ; } // Calculate the visual progress if ( total ) { for ( var time in paints ) { if ( paints . hasOwnProperty ( time ) ) { progress . push ( { 'tm' : time , 'area' : paints [ time ] } ) ; } } progress . sort ( function ( a , b ) { return a . tm - b . tm ; } ) ; var accumulated = 0 ; for ( var j = 0 ; j < progress . length ; j ++ ) { accumulated += progress [ j ] . area ; progress [ j ] . progress = accumulated / total ; } } }
Sort and group all of the paint rects by time and use them to calculate the visual progress
Sort and group all of the paint rects by time and use them to calculate the visual progress