diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..52901fb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ + +# http://editorconfig.org + +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{js,ts,html}] +charset = utf-8 +indent_style = tab + +[*.{js,ts}] +trim_trailing_whitespace = true \ No newline at end of file diff --git a/build/stats.js b/build/stats.js index 4875f72..a49dca8 100644 --- a/build/stats.js +++ b/build/stats.js @@ -1,179 +1,179 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - (global.Stats = factory()); -}(this, (function () { 'use strict'; + (global = global || self, global.Stats = factory()); +}(this, function () { 'use strict'; -/** - * @author mrdoob / http://mrdoob.com/ - */ + /** + * @author mrdoob / http://mrdoob.com/ + */ -var Stats = function () { + var Stats = function () { - var mode = 0; + var mode = 0; - var container = document.createElement( 'div' ); - container.style.cssText = 'position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000'; - container.addEventListener( 'click', function ( event ) { + var container = document.createElement( 'div' ); + container.style.cssText = 'position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000'; + container.addEventListener( 'click', function ( event ) { - event.preventDefault(); - showPanel( ++ mode % container.children.length ); + event.preventDefault(); + showPanel( ++ mode % container.children.length ); - }, false ); + }, false ); - // + // - function addPanel( panel ) { + function addPanel( panel ) { - container.appendChild( panel.dom ); - return panel; + container.appendChild( panel.dom ); + return panel; - } + } - function showPanel( id ) { + function showPanel( id ) { - for ( var i = 0; i < container.children.length; i ++ ) { + for ( var i = 0; i < container.children.length; i ++ ) { - container.children[ i ].style.display = i === id ? 'block' : 'none'; + container.children[ i ].style.display = i === id ? 'block' : 'none'; - } + } - mode = id; + mode = id; + + } - } + // - // + var beginTime = ( performance || Date ).now(), prevTime = beginTime, frames = 0; - var beginTime = ( performance || Date ).now(), prevTime = beginTime, frames = 0; + var fpsPanel = addPanel( new Stats.Panel( 'FPS', '#0ff', '#002' ) ); + var msPanel = addPanel( new Stats.Panel( 'MS', '#0f0', '#020' ) ); - var fpsPanel = addPanel( new Stats.Panel( 'FPS', '#0ff', '#002' ) ); - var msPanel = addPanel( new Stats.Panel( 'MS', '#0f0', '#020' ) ); + if ( self.performance && self.performance.memory ) { - if ( self.performance && self.performance.memory ) { + var memPanel = addPanel( new Stats.Panel( 'MB', '#f08', '#201' ) ); - var memPanel = addPanel( new Stats.Panel( 'MB', '#f08', '#201' ) ); + } - } + showPanel( 0 ); - showPanel( 0 ); + return { - return { + REVISION: 16, - REVISION: 16, + dom: container, - dom: container, + addPanel: addPanel, + showPanel: showPanel, - addPanel: addPanel, - showPanel: showPanel, + begin: function () { - begin: function () { + beginTime = ( performance || Date ).now(); - beginTime = ( performance || Date ).now(); + }, - }, + end: function () { - end: function () { + frames ++; - frames ++; + var time = ( performance || Date ).now(); - var time = ( performance || Date ).now(); + msPanel.update( time - beginTime, 200 ); - msPanel.update( time - beginTime, 200 ); + if ( time >= prevTime + 1000 ) { - if ( time >= prevTime + 1000 ) { + fpsPanel.update( ( frames * 1000 ) / ( time - prevTime ), 100 ); - fpsPanel.update( ( frames * 1000 ) / ( time - prevTime ), 100 ); + prevTime = time; + frames = 0; - prevTime = time; - frames = 0; + if ( memPanel ) { - if ( memPanel ) { + var memory = performance.memory; + memPanel.update( memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576 ); - var memory = performance.memory; - memPanel.update( memory.usedJSHeapSize / 1048576, memory.jsHeapSizeLimit / 1048576 ); + } } - } + return time; - return time; + }, - }, + update: function () { - update: function () { + beginTime = this.end(); - beginTime = this.end(); + }, - }, + // Backwards Compatibility - // Backwards Compatibility + domElement: container, + setMode: showPanel - domElement: container, - setMode: showPanel + }; }; -}; + Stats.Panel = function ( name, fg, bg ) { -Stats.Panel = function ( name, fg, bg ) { + var min = Infinity, max = 0, round = Math.round; + var PR = round( window.devicePixelRatio || 1 ); - var min = Infinity, max = 0, round = Math.round; - var PR = round( window.devicePixelRatio || 1 ); + var WIDTH = 80 * PR, HEIGHT = 48 * PR, + TEXT_X = 3 * PR, TEXT_Y = 2 * PR, + GRAPH_X = 3 * PR, GRAPH_Y = 15 * PR, + GRAPH_WIDTH = 74 * PR, GRAPH_HEIGHT = 30 * PR; - var WIDTH = 80 * PR, HEIGHT = 48 * PR, - TEXT_X = 3 * PR, TEXT_Y = 2 * PR, - GRAPH_X = 3 * PR, GRAPH_Y = 15 * PR, - GRAPH_WIDTH = 74 * PR, GRAPH_HEIGHT = 30 * PR; + var canvas = document.createElement( 'canvas' ); + canvas.width = WIDTH; + canvas.height = HEIGHT; + canvas.style.cssText = 'width:80px;height:48px'; - var canvas = document.createElement( 'canvas' ); - canvas.width = WIDTH; - canvas.height = HEIGHT; - canvas.style.cssText = 'width:80px;height:48px'; + var context = canvas.getContext( '2d' ); + context.font = 'bold ' + ( 9 * PR ) + 'px Helvetica,Arial,sans-serif'; + context.textBaseline = 'top'; - var context = canvas.getContext( '2d' ); - context.font = 'bold ' + ( 9 * PR ) + 'px Helvetica,Arial,sans-serif'; - context.textBaseline = 'top'; + context.fillStyle = bg; + context.fillRect( 0, 0, WIDTH, HEIGHT ); - context.fillStyle = bg; - context.fillRect( 0, 0, WIDTH, HEIGHT ); + context.fillStyle = fg; + context.fillText( name, TEXT_X, TEXT_Y ); + context.fillRect( GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT ); - context.fillStyle = fg; - context.fillText( name, TEXT_X, TEXT_Y ); - context.fillRect( GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT ); + context.fillStyle = bg; + context.globalAlpha = 0.9; + context.fillRect( GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT ); - context.fillStyle = bg; - context.globalAlpha = 0.9; - context.fillRect( GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT ); + return { - return { + dom: canvas, - dom: canvas, + update: function ( value, maxValue ) { - update: function ( value, maxValue ) { + min = Math.min( min, value ); + max = Math.max( max, value ); - min = Math.min( min, value ); - max = Math.max( max, value ); + context.fillStyle = bg; + context.globalAlpha = 1; + context.fillRect( 0, 0, WIDTH, GRAPH_Y ); + context.fillStyle = fg; + context.fillText( round( value ) + ' ' + name + ' (' + round( min ) + '-' + round( max ) + ')', TEXT_X, TEXT_Y ); - context.fillStyle = bg; - context.globalAlpha = 1; - context.fillRect( 0, 0, WIDTH, GRAPH_Y ); - context.fillStyle = fg; - context.fillText( round( value ) + ' ' + name + ' (' + round( min ) + '-' + round( max ) + ')', TEXT_X, TEXT_Y ); + context.drawImage( canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT ); - context.drawImage( canvas, GRAPH_X + PR, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT, GRAPH_X, GRAPH_Y, GRAPH_WIDTH - PR, GRAPH_HEIGHT ); + context.fillRect( GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT ); - context.fillRect( GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, GRAPH_HEIGHT ); + context.fillStyle = bg; + context.globalAlpha = 0.9; + context.fillRect( GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round( ( 1 - ( value / maxValue ) ) * GRAPH_HEIGHT ) ); - context.fillStyle = bg; - context.globalAlpha = 0.9; - context.fillRect( GRAPH_X + GRAPH_WIDTH - PR, GRAPH_Y, PR, round( ( 1 - ( value / maxValue ) ) * GRAPH_HEIGHT ) ); + } - } + }; }; -}; - -return Stats; + return Stats; -}))); +})); diff --git a/build/stats.min.js b/build/stats.min.js index 3ddf1e5..65e8b1b 100644 --- a/build/stats.min.js +++ b/build/stats.min.js @@ -1,5 +1,5 @@ // stats.js - http://github.com/mrdoob/stats.js -(function(f,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"===typeof define&&define.amd?define(e):f.Stats=e()})(this,function(){var f=function(){function e(a){c.appendChild(a.dom);return a}function u(a){for(var d=0;d=g+1E3&&(r.update(1E3*a/(c-g),100),g=c,a=0,t)){var d=performance.memory;t.update(d.usedJSHeapSize/ -1048576,d.jsHeapSizeLimit/1048576)}return c},update:function(){k=this.end()},domElement:c,setMode:u}};f.Panel=function(e,f,l){var c=Infinity,k=0,g=Math.round,a=g(window.devicePixelRatio||1),r=80*a,h=48*a,t=3*a,v=2*a,d=3*a,m=15*a,n=74*a,p=30*a,q=document.createElement("canvas");q.width=r;q.height=h;q.style.cssText="width:80px;height:48px";var b=q.getContext("2d");b.font="bold "+9*a+"px Helvetica,Arial,sans-serif";b.textBaseline="top";b.fillStyle=l;b.fillRect(0,0,r,h);b.fillStyle=f;b.fillText(e,t,v); -b.fillRect(d,m,n,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d,m,n,p);return{dom:q,update:function(h,w){c=Math.min(c,h);k=Math.max(k,h);b.fillStyle=l;b.globalAlpha=1;b.fillRect(0,0,r,m);b.fillStyle=f;b.fillText(g(h)+" "+e+" ("+g(c)+"-"+g(k)+")",t,v);b.drawImage(q,d+a,m,n-a,p,d,m,n-a,p);b.fillRect(d+n-a,m,a,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d+n-a,m,a,g((1-h/w)*p))}}};return f}); +'use strict';var Stats=function(){var f=function(){function k(a){c.appendChild(a.dom);return a}function l(a){for(var d=0;d=e+1E3&&(u.update(1E3*a/(c-e),100),e=c,a=0,t)){var d=performance.memory;t.update(d.usedJSHeapSize/1048576,d.jsHeapSizeLimit/1048576)}return c},update:function(){h=this.end()},domElement:c,setMode:l}};f.Panel=function(k,l,m){var c= +Infinity,h=0,e=Math.round,a=e(window.devicePixelRatio||1),f=80*a,g=48*a,t=3*a,v=2*a,d=3*a,n=15*a,p=74*a,q=30*a,r=document.createElement("canvas");r.width=f;r.height=g;r.style.cssText="width:80px;height:48px";var b=r.getContext("2d");b.font="bold "+9*a+"px Helvetica,Arial,sans-serif";b.textBaseline="top";b.fillStyle=m;b.fillRect(0,0,f,g);b.fillStyle=l;b.fillText(k,t,v);b.fillRect(d,n,p,q);b.fillStyle=m;b.globalAlpha=.9;b.fillRect(d,n,p,q);return{dom:r,update:function(g,u){c=Math.min(c,g);h=Math.max(h, +g);b.fillStyle=m;b.globalAlpha=1;b.fillRect(0,0,f,n);b.fillStyle=l;b.fillText(e(g)+" "+k+" ("+e(c)+"-"+e(h)+")",t,v);b.drawImage(r,d+a,n,p-a,q,d,n,p-a,q);b.fillRect(d+p-a,n,a,q);b.fillStyle=m;b.globalAlpha=.9;b.fillRect(d+p-a,n,a,e((1-g/u)*q))}}};return f}(); diff --git a/examples/custom.html b/examples/custom.html index bd42179..4c43554 100644 --- a/examples/custom.html +++ b/examples/custom.html @@ -11,12 +11,21 @@ - +