lib/har/viewer/scripts/tabs/pageStats.js in har-0.0.9 vs lib/har/viewer/scripts/tabs/pageStats.js in har-0.1.0
- old
+ new
@@ -1,14 +2 @@
-require.def("tabs/pageStats",["domplate/domplate","core/lib","i18n!nls/pageStats","preview/harSchema","preview/harModel","core/cookies","domplate/infoTip","core/trace"],function(p,f,e,q,r,s,t){with(p){var h=function(){};h.prototype={data:[],title:"",getLabelTooltipText:function(a){return a.label+": "+f.formatSize(a.value)},cleanUp:function(){for(var a=0;a<this.data.length;a++){this.data[a].value=0;this.data[a].count=0}}};p=function(){};p.prototype=f.extend(h.prototype,{title:"Summary of request times.",
-data:[{value:0,label:e.pieLabelDNS,color:"rgb(119, 192, 203)"},{value:0,label:e.pieLabelSSL,color:"rgb(168, 196, 173)"},{value:0,label:e.pieLabelConnect,color:"rgb(179, 222, 93)"},{value:0,label:e.pieLabelBlocked,color:"rgb(228, 214, 193)"},{value:0,label:e.pieLabelSend,color:"rgb(224, 171, 157)"},{value:0,label:e.pieLabelWait,color:"rgb(163, 150, 190)"},{value:0,label:e.pieLabelReceive,color:"rgb(194, 194, 194)"}],getLabelTooltipText:function(a){return a.label+": "+f.formatTime(a.value)}});q=function(){};
-q.prototype=f.extend(h.prototype,{title:"Summary of content types.",data:[{value:0,label:e.pieLabelHTMLText,color:"rgb(174, 234, 218)"},{value:0,label:e.pieLabelJavaScript,color:"rgb(245, 230, 186)"},{value:0,label:e.pieLabelCSS,color:"rgb(212, 204, 219)"},{value:0,label:e.pieLabelImage,color:"rgb(220, 171, 181)"},{value:0,label:e.pieLabelFlash,color:"rgb(166, 156, 222)"},{value:0,label:e.pieLabelOthers,color:"rgb(229, 171, 255)"}],getLabelTooltipText:function(a){return a.count+"x "+a.label+": "+
-f.formatSize(a.value)}});r=function(){};r.prototype=f.extend(h.prototype,{title:"Summary of sent and received bodies & headers.",data:[{value:0,label:e.pieLabelHeadersSent,color:"rgb(247, 179, 227)"},{value:0,label:e.pieLabelBodiesSent,color:"rgb(226, 160, 241)"},{value:0,label:e.pieLabelHeadersReceived,color:"rgb(166, 232, 166)"},{value:0,label:e.pieLabelBodiesReceived,color:"rgb(168, 196, 173)"}]});s=function(){};s.prototype=f.extend(h.prototype,{title:"Comparison of downloaded data from the server and browser cache.",
-data:[{value:0,label:e.pieLabelDownloaded,color:"rgb(182, 182, 182)"},{value:0,label:e.pieLabelPartial,color:"rgb(218, 218, 218)"},{value:0,label:e.pieLabelFromCache,color:"rgb(239, 239, 239)"}],getLabelTooltipText:function(a){return a.count+"x "+a.label+": "+f.formatSize(a.value)}});var k=new p,i=new q,o=new r,l=new s,u={"text/javascript":1,"text/jscript":1,"application/javascript":1,"application/x-javascript":1,"text/js":1},v={"text/plain":1,"text/html":1},w={"text/css":1},x={"image/png":1,"image/jpeg":1},
-y={"application/x-shockwave-flash":1};e=function(a,d){this.model=a;this.timeline=d;this.timeline.addListener(this)};e.prototype=domplate({element:null,tag:DIV({"class":"pageStatsBody",style:"height: auto; display: none"}),update:function(a){if(this.isVisible()){this.cleanUp();a.length||a.push(null);for(var d=0;d<a.length;d++){var b=a[d];b=b?this.model.getPageEntries(b):this.model.getAllEntries();for(var m=0;m<b.length;m++){var c=b[m];k.data[0].value+=c.timings.dns;k.data[1].value+=c.timings.ssl?c.timings.ssl:
--1;k.data[2].value+=c.timings.connect;k.data[3].value+=c.timings.blocked;k.data[4].value+=c.timings.send;k.data[5].value+=c.timings.wait;k.data[6].value+=c.timings.receive;if(c.timings.ssl>0)k.data[2].value-=c.timings.ssl;var n=c.response,g=n.bodySize>0?n.bodySize:0,j=n.content.mimeType;j=(j=j?j.match(/^([^;]+)/)[1]:null)?j:n.content.mimeType;if(v[j]){i.data[0].value+=g;i.data[0].count++}else if(u[j]){i.data[1].value+=g;i.data[1].count++}else if(w[j]){i.data[2].value+=g;i.data[2].count++}else if(x[j]){i.data[3].value+=
-g;i.data[3].count++}else if(y[j]){i.data[4].value+=g;i.data[4].count++}else{i.data[5].value+=g;i.data[5].count++}o.data[0].value+=c.request.headersSize>0?c.request.headersSize:0;o.data[1].value+=c.request.bodySize>0?c.request.bodySize:0;o.data[2].value+=c.response.headersSize>0?c.response.headersSize:0;o.data[3].value+=g;if(c.response.status==206){l.data[1].value+=g;l.data[1].count++}else if(c.response.status==304){l.data[2].value+=g;l.data[2].count++}else if(g>0){l.data[0].value+=g;l.data[0].count++}}}h.draw(f.$(this.timingPie,
-"pieGraph"),k);h.draw(f.$(this.contentPie,"pieGraph"),i);h.draw(f.$(this.trafficPie,"pieGraph"),o);h.draw(f.$(this.cachePie,"pieGraph"),l)}},cleanUp:function(){k.cleanUp();i.cleanUp();o.cleanUp();l.cleanUp()},showInfoTip:function(a,d,b,m){return h.showInfoTip(a,d,b,m)},onSelectionChange:function(a){this.update(a)},show:function(a){if(!this.isVisible()){t.addListener(this);f.setClass(this.element,"opened");if(!a||$.browser.msie)this.element.style.display="block";else $(this.element).slideDown();this.update(this.timeline.getSelection())}},
-hide:function(a){if(this.isVisible()){t.removeListener(this);f.removeClass(this.element,"opened");if(!a||$.browser.msie)this.element.style.display="none";else $(this.element).slideUp()}},isVisible:function(){return f.hasClass(this.element,"opened")},toggle:function(a){this.isVisible()?this.hide(a):this.show(a)},render:function(a){this.element=this.tag.replace({},a);this.timingPie=h.render(k,this.element);this.contentPie=h.render(i,this.element);this.trafficPie=h.render(o,this.element);this.cachePie=
-h.render(l,this.element);this.cachePie.style.borderRight=0;return this.element}});h=domplate({tag:TABLE({"class":"pagePieTable",cellpadding:0,cellspacing:0,_repObject:"$pie"},TBODY(TR(TD({"class":"pieBox",title:"$pie.title"}),TD(FOR("item","$pie.data",DIV({"class":"pieLabel",_repObject:"$item"},SPAN({"class":"box",style:"background-color: $item.color"}," "),SPAN({"class":"label"},"$item.label"))))))),render:function(a,d){a=this.tag.append({pie:a},d);d=f.$(a,"pieBox");var b=document.createElement("canvas");
-b.setAttribute("class","pieGraph ");b.setAttribute("height","100");b.setAttribute("width","100");d.appendChild(b);typeof G_vmlCanvasManager!="undefined"&&G_vmlCanvasManager.initElement(b);return a},draw:function(a,d){if(a&&a.getContext){var b=a.getContext("2d"),m=Math.min(a.width,a.height)/2,c=[a.width/2,a.height/2];b.clearRect(0,0,a.width,a.height);a=0;d=d.data;var n=0;for(var g in d)n+=d[g].value;if(n)for(g=0;g<d.length;g++){var j=d[g].value/n;b.beginPath();b.moveTo(c[0],c[1]);b.arc(c[0],c[1],m,
-Math.PI*(-0.5+2*a),Math.PI*(-0.5+2*(a+j)),false);b.lineTo(c[0],c[1]);b.closePath();b.fillStyle=d[g].color;b.fill();a+=j}else{b.beginPath();b.moveTo(c[0],c[1]);b.arc(c[0],c[1],m,0,Math.PI*2,false);b.closePath();b.fillStyle="rgb(229,236,238)";b.lineStyle="lightgray";b.fill()}}},showInfoTip:function(a,d){var b=f.getAncestorByClass(d,"pagePieTable");if(!b)return false;if(d=f.getAncestorByClass(d,"pieLabel")){z.render(b.repObject,d.repObject,a);return true}}});var z=domplate({tag:DIV({"class":"pieLabelInfoTip"},
-"$text"),getText:function(a){return a.label+": "+formatTime(a.value)},render:function(a,d,b){this.tag.replace({text:a.getLabelTooltipText(d)},b)}});return e}});
+require.def("tabs/pageStats",["domplate/domplate","core/lib","i18n!nls/pageStats","preview/harSchema","preview/harModel","core/cookies","domplate/infoTip","core/trace"],function(Domplate,Lib,Strings,HarSchema,HarModel,Cookies,InfoTip,Trace){with(Domplate){function Pie(){}Pie.prototype={data:[],title:"",getLabelTooltipText:function(a){return a.label+": "+Lib.formatSize(a.value)},cleanUp:function(){for(var a=0;a<this.data.length;a++)this.data[a].value=0,this.data[a].count=0}};function TimingPie(){}TimingPie.prototype=Lib.extend(Pie.prototype,{title:"Summary of request times.",data:[{value:0,label:Strings.pieLabelBlocked,color:"rgb(228, 214, 193)"},{value:0,label:Strings.pieLabelDNS,color:"rgb(119, 192, 203)"},{value:0,label:Strings.pieLabelSSL,color:"rgb(168, 196, 173)"},{value:0,label:Strings.pieLabelConnect,color:"rgb(179, 222, 93)"},{value:0,label:Strings.pieLabelSend,color:"rgb(224, 171, 157)"},{value:0,label:Strings.pieLabelWait,color:"rgb(163, 150, 190)"},{value:0,label:Strings.pieLabelReceive,color:"rgb(194, 194, 194)"}],getLabelTooltipText:function(a){return a.label+": "+Lib.formatTime(a.value)}});function ContentPie(){}ContentPie.prototype=Lib.extend(Pie.prototype,{title:"Summary of content types.",data:[{value:0,label:Strings.pieLabelHTMLText,color:"rgb(174, 234, 218)"},{value:0,label:Strings.pieLabelJavaScript,color:"rgb(245, 230, 186)"},{value:0,label:Strings.pieLabelCSS,color:"rgb(212, 204, 219)"},{value:0,label:Strings.pieLabelImage,color:"rgb(220, 171, 181)"},{value:0,label:Strings.pieLabelFlash,color:"rgb(166, 156, 222)"},{value:0,label:Strings.pieLabelOthers,color:"rgb(229, 171, 255)"}],getLabelTooltipText:function(a){return a.count+"x "+a.label+": "+Lib.formatSize(a.value)}});function TrafficPie(){}TrafficPie.prototype=Lib.extend(Pie.prototype,{title:"Summary of sent and received bodies & headers.",data:[{value:0,label:Strings.pieLabelHeadersSent,color:"rgb(247, 179, 227)"},{value:0,label:Strings.pieLabelBodiesSent,color:"rgb(226, 160, 241)"},{value:0,label:Strings.pieLabelHeadersReceived,color:"rgb(166, 232, 166)"},{value:0,label:Strings.pieLabelBodiesReceived,color:"rgb(168, 196, 173)"}]});function CachePie(){}CachePie.prototype=Lib.extend(Pie.prototype,{title:"Comparison of downloaded data from the server and browser cache.",data:[{value:0,label:Strings.pieLabelDownloaded,color:"rgb(182, 182, 182)"},{value:0,label:Strings.pieLabelPartial,color:"rgb(218, 218, 218)"},{value:0,label:Strings.pieLabelFromCache,color:"rgb(239, 239, 239)"}],getLabelTooltipText:function(a){return a.count+"x "+a.label+": "+Lib.formatSize(a.value)}});var timingPie=new TimingPie,contentPie=new ContentPie,trafficPie=new TrafficPie,cachePie=new CachePie,jsTypes={"text/javascript":1,"text/jscript":1,"application/javascript":1,"application/x-javascript":1,"text/js":1},htmlTypes={"text/plain":1,"text/html":1},cssTypes={"text/css":1},imageTypes={"image/png":1,"image/jpeg":1,"image/gif":1},flashTypes={"application/x-shockwave-flash":1},jsonTypes={"text/x-json":1,"text/x-js":1,"application/json":1,"application/x-js":1},xmlTypes={"application/xml":1,"application/xhtml+xml":1,"application/vnd.mozilla.xul+xml":1,"text/xml":1,"text/xul":1,"application/rdf+xml":1},unknownTypes={"text/xsl":1,"text/sgml":1,"text/rtf":1,"text/x-setext":1,"text/richtext":1,"text/tab-separated-values":1,"text/rdf":1,"text/xif":1,"text/ecmascript":1,"text/vnd.curl":1,"text/vbscript":1,"view-source":1,"view-fragment":1,"application/x-httpd-php":1,"application/ecmascript":1,"application/http-index-format":1};function Stats(a,b){this.model=a,this.timeline=b,this.timeline.addListener(this)}Stats.prototype=domplate({element:null,tag:DIV({"class":"pageStatsBody",style:"height: auto; display: none"}),update:function(a){if(this.isVisible()){this.cleanUp();var b=HarSchema.timingsType.properties;a.length||a.push(null);for(var c=0;c<a.length;c++){var d=a[c],e=d?this.model.getPageEntries(d):this.model.getAllEntries();for(var f=0;f<e.length;f++){var g=e[f];if(!g.timings)continue;timingPie.data[0].value+=g.timings.blocked,timingPie.data[1].value+=g.timings.dns,timingPie.data[2].value+=g.timings.ssl>0?g.timings.ssl:0,timingPie.data[3].value+=g.timings.connect,timingPie.data[4].value+=g.timings.send,timingPie.data[5].value+=g.timings.wait,timingPie.data[6].value+=g.timings.receive,g.timings.ssl>0&&(timingPie.data[3].value-=g.timings.ssl);var h=g.response,i=h.bodySize>0?h.bodySize:0,j=h.content.mimeType,k=j?j.match(/^([^;]+)/)[1]:null,j=k?k:h.content.mimeType;htmlTypes[j]?(contentPie.data[0].value+=i,contentPie.data[0].count++):jsTypes[j]?(contentPie.data[1].value+=i,contentPie.data[1].count++):cssTypes[j]?(contentPie.data[2].value+=i,contentPie.data[2].count++):imageTypes[j]?(contentPie.data[3].value+=i,contentPie.data[3].count++):flashTypes[j]?(contentPie.data[4].value+=i,contentPie.data[4].count++):(contentPie.data[5].value+=i,contentPie.data[5].count++),trafficPie.data[0].value+=g.request.headersSize>0?g.request.headersSize:0,trafficPie.data[1].value+=g.request.bodySize>0?g.request.bodySize:0,trafficPie.data[2].value+=g.response.headersSize>0?g.response.headersSize:0,trafficPie.data[3].value+=i,g.response.status==206?(cachePie.data[1].value+=i,cachePie.data[1].count++):g.response.status==304?(cachePie.data[2].value+=i,cachePie.data[2].count++):i>0&&(cachePie.data[0].value+=i,cachePie.data[0].count++)}}Pie.draw(Lib.$(this.timingPie,"pieGraph"),timingPie),Pie.draw(Lib.$(this.contentPie,"pieGraph"),contentPie),Pie.draw(Lib.$(this.trafficPie,"pieGraph"),trafficPie),Pie.draw(Lib.$(this.cachePie,"pieGraph"),cachePie)}},cleanUp:function(){timingPie.cleanUp(),contentPie.cleanUp(),trafficPie.cleanUp(),cachePie.cleanUp()},showInfoTip:function(a,b,c,d){return Pie.showInfoTip(a,b,c,d)},onSelectionChange:function(a){this.update(a)},show:function(a){if(!this.isVisible()){InfoTip.addListener(this),Lib.setClass(this.element,"opened"),!a||$.browser.msie?this.element.style.display="block":$(this.element).slideDown();var b=this.timeline.getSelection();this.update(b)}},hide:function(a){this.isVisible()&&(InfoTip.removeListener(this),Lib.removeClass(this.element,"opened"),!a||$.browser.msie?this.element.style.display="none":$(this.element).slideUp())},isVisible:function(){return Lib.hasClass(this.element,"opened")},toggle:function(a){this.isVisible()?this.hide(a):this.show(a)},render:function(a){this.element=this.tag.replace({},a),this.timingPie=Pie.render(timingPie,this.element),this.contentPie=Pie.render(contentPie,this.element),this.trafficPie=Pie.render(trafficPie,this.element),this.cachePie=Pie.render(cachePie,this.element),this.cachePie.style.borderRight=0;return this.element}});var Pie=domplate({tag:TABLE({"class":"pagePieTable",cellpadding:0,cellspacing:0,_repObject:"$pie"},TBODY(TR(TD({"class":"pieBox",title:"$pie.title"}),TD(FOR("item","$pie.data",DIV({"class":"pieLabel",_repObject:"$item"},SPAN({"class":"box",style:"background-color: $item.color"}," "),SPAN({"class":"label"},"$item.label"))))))),render:function(a,b){var c=this.tag.append({pie:a},b),d=Lib.$(c,"pieBox"),e=document.createElement("canvas");e.setAttribute("class","pieGraph "),e.setAttribute("height","100"),e.setAttribute("width","100"),d.appendChild(e),typeof G_vmlCanvasManager!="undefined"&&G_vmlCanvasManager.initElement(e);return c},draw:function(a,b){if(a&&a.getContext){var c=a.getContext("2d"),d=Math.min(a.width,a.height)/2,e=[a.width/2,a.height/2];c.clearRect(0,0,a.width,a.height);var f=0,g=b.data,h=0;for(var i in g)h+=g[i].value;if(!h){c.beginPath(),c.moveTo(e[0],e[1]),c.arc(e[0],e[1],d,0,Math.PI*2,!1),c.closePath(),c.fillStyle="rgb(229,236,238)",c.lineStyle="lightgray",c.fill();return}for(var i=0;i<g.length;i++){var j=g[i].value/h;c.beginPath(),c.moveTo(e[0],e[1]),c.arc(e[0],e[1],d,Math.PI*(-.5+2*f),Math.PI*(-.5+2*(f+j)),!1),c.lineTo(e[0],e[1]),c.closePath(),c.fillStyle=g[i].color,c.fill(),f+=j}}},showInfoTip:function(a,b,c,d){var e=Lib.getAncestorByClass(b,"pagePieTable");if(!e)return!1;var f=Lib.getAncestorByClass(b,"pieLabel");if(f){PieInfoTip.render(e.repObject,f.repObject,a);return!0}}}),PieInfoTip=domplate({tag:DIV({"class":"pieLabelInfoTip"},"$text"),getText:function(a){return a.label+": "+formatTime(a.value)},render:function(a,b,c){var d=a.getLabelTooltipText(b);this.tag.replace({text:d},c)}});return Stats}})
\ No newline at end of file