Skip to content

Commit

Permalink
Adds stats.js
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardolundgren committed Jul 24, 2014
1 parent 736596a commit 6470b8a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
File renamed without changes.
41 changes: 41 additions & 0 deletions examples/assets/stats.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// stats.js - http://github.com/mrdoob/stats.js
var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";
i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div");
k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display=
"block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:11,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height=
a+"px",m=b,r=0);return b},update:function(){l=this.end()}}};

var stats = new Stats();
stats.setMode(2);
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
document.addEventListener('DOMContentLoaded', function(event) {
document.body.appendChild(stats.domElement);
});

var objectTrack_ = tracking.ObjectTracker.prototype.track;
var objectEmit_ = tracking.ObjectTracker.prototype.emit;
var colorTrack_ = tracking.ColorTracker.prototype.track;
var colorEmit_ = tracking.ColorTracker.prototype.emit;

tracking.ObjectTracker.prototype.emit = function() {
stats.end();
objectEmit_.apply(this, arguments);
};

tracking.ObjectTracker.prototype.track = function() {
stats.begin();
objectTrack_.apply(this, arguments);
};

tracking.ColorTracker.prototype.emit = function() {
stats.end();
colorEmit_.apply(this, arguments);
};

tracking.ColorTracker.prototype.track = function() {
stats.begin();
colorTrack_.apply(this, arguments);
};
3 changes: 3 additions & 0 deletions examples/brief_camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<meta charset="utf-8">

<script src="../build/tracking.js"></script>
<script src="assets/stats.min.js"></script>

<style>
#boundingBox {
Expand Down Expand Up @@ -76,6 +77,8 @@
var tracker = new BoundingBoxTracker();

tracker.on('track', function(event) {
stats.end();

if (capturing) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions examples/color_camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="assets/demo.css">

<script src="../build/tracking-min.js"></script>
<script src="assets/stats.min.js"></script>

<style>
video, canvas {
Expand Down
3 changes: 2 additions & 1 deletion examples/color_draw_something.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<meta charset="utf-8">

<script src="../build/tracking.js"></script>
<script src="js/splines.min.js"></script>
<script src="assets/splines.min.js"></script>
<script src="assets/stats.min.js"></script>

<style>
#canvas,
Expand Down
1 change: 1 addition & 0 deletions examples/color_video.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="assets/demo.css">

<script src="../build/tracking-min.js"></script>
<script src="assets/stats.min.js"></script>

<style>
#rectangle {
Expand Down
1 change: 1 addition & 0 deletions examples/face_camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<script src="../build/tracking-min.js"></script>
<script src="../build/data/face-min.js"></script>
<script src="assets/stats.min.js"></script>

<style>
video, canvas {
Expand Down

0 comments on commit 6470b8a

Please sign in to comment.