2
2
* @author mrdoob / http://mrdoob.com/
3
3
*/
4
4
5
- var Stats = function ( ) {
5
+ var Stats = function ( options ) {
6
+
7
+ options = options || { } ;
8
+
9
+ var barHeight = options . barHeight || 30 ;
10
+ var bars = options . bars || 74 ;
6
11
7
12
var startTime = Date . now ( ) , prevTime = startTime ;
8
13
var ms = 0 , msMin = Infinity , msMax = 0 ;
@@ -11,53 +16,51 @@ var Stats = function () {
11
16
12
17
var container = document . createElement ( 'div' ) ;
13
18
container . id = 'stats' ;
14
- container . addEventListener ( 'mousedown' , function ( event ) { event . preventDefault ( ) ; setMode ( ++ mode % 2 ) } , false ) ;
15
- container . style . cssText = 'width:80px ;opacity:0.9;cursor:pointer' ;
19
+ container . addEventListener ( 'mousedown' , function ( event ) { event . preventDefault ( ) ; setMode ( ++ mode % 2 ) ; } , false ) ;
20
+ container . style . cssText = 'width:' + ( bars + 6 ) + 'px ;opacity:0.9;cursor:pointer;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px;text-align:left ';
16
21
17
22
var fpsDiv = document . createElement ( 'div' ) ;
18
23
fpsDiv . id = 'fps' ;
19
- fpsDiv . style . cssText = 'padding:0 0 3px 3px;text-align:left; background-color:#002' ;
24
+ fpsDiv . style . cssText = 'padding:0 0 3px 3px;background-color:#002;color:#0ff ' ;
20
25
container . appendChild ( fpsDiv ) ;
21
26
22
27
var fpsText = document . createElement ( 'div' ) ;
23
28
fpsText . id = 'fpsText' ;
24
- fpsText . style . cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px' ;
25
29
fpsText . innerHTML = 'FPS' ;
26
30
fpsDiv . appendChild ( fpsText ) ;
27
31
28
32
var fpsGraph = document . createElement ( 'div' ) ;
29
33
fpsGraph . id = 'fpsGraph' ;
30
- fpsGraph . style . cssText = 'position:relative;width:74px ;height:30px ;background-color:#0ff' ;
34
+ fpsGraph . style . cssText = 'position:relative;width:' + bars + 'px ;height:' + barHeight + 'px ;background-color:#0ff';
31
35
fpsDiv . appendChild ( fpsGraph ) ;
32
36
33
- while ( fpsGraph . children . length < 74 ) {
37
+ while ( fpsGraph . children . length < bars ) {
34
38
35
39
var bar = document . createElement ( 'span' ) ;
36
- bar . style . cssText = 'width:1px;height:30px ;float:left;background-color:#113' ;
40
+ bar . style . cssText = 'width:1px;height:' + barHeight + 'px ;float:left;background-color:#113';
37
41
fpsGraph . appendChild ( bar ) ;
38
42
39
43
}
40
44
41
45
var msDiv = document . createElement ( 'div' ) ;
42
46
msDiv . id = 'ms' ;
43
- msDiv . style . cssText = 'padding:0 0 3px 3px;text-align:left; background-color:#020;display:none' ;
47
+ msDiv . style . cssText = 'padding:0 0 3px 3px;background-color:#020;display:none;color:#0f0; ' ;
44
48
container . appendChild ( msDiv ) ;
45
49
46
50
var msText = document . createElement ( 'div' ) ;
47
51
msText . id = 'msText' ;
48
- msText . style . cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px' ;
49
52
msText . innerHTML = 'MS' ;
50
53
msDiv . appendChild ( msText ) ;
51
54
52
55
var msGraph = document . createElement ( 'div' ) ;
53
56
msGraph . id = 'msGraph' ;
54
- msGraph . style . cssText = 'position:relative;width:74px ;height:30px ;background-color:#0f0' ;
57
+ msGraph . style . cssText = 'position:relative;width:' + bars + 'px ;height:' + barHeight + 'px ;background-color:#0f0';
55
58
msDiv . appendChild ( msGraph ) ;
56
59
57
- while ( msGraph . children . length < 74 ) {
60
+ while ( msGraph . children . length < bars ) {
58
61
59
62
var bar = document . createElement ( 'span' ) ;
60
- bar . style . cssText = 'width:1px;height:30px ;float:left;background-color:#131' ;
63
+ bar . style . cssText = 'width:1px;height: ' + barHeight + 'px ;float:left;background-color:#131';
61
64
msGraph . appendChild ( bar ) ;
62
65
63
66
}
@@ -110,7 +113,7 @@ var Stats = function () {
110
113
msMax = Math . max ( msMax , ms ) ;
111
114
112
115
msText . textContent = ms + ' MS (' + msMin + '-' + msMax + ')' ;
113
- updateGraph ( msGraph , Math . min ( 30 , 30 - ( ms / 200 ) * 30 ) ) ;
116
+ updateGraph ( msGraph , Math . min ( barHeight , barHeight - ( ms / 200 ) * barHeight ) ) ;
114
117
115
118
frames ++ ;
116
119
@@ -121,7 +124,7 @@ var Stats = function () {
121
124
fpsMax = Math . max ( fpsMax , fps ) ;
122
125
123
126
fpsText . textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')' ;
124
- updateGraph ( fpsGraph , Math . min ( 30 , 30 - ( fps / 100 ) * 30 ) ) ;
127
+ updateGraph ( fpsGraph , Math . min ( barHeight , barHeight - ( fps / 100 ) * barHeight ) ) ;
125
128
126
129
prevTime = time ;
127
130
frames = 0 ;
@@ -138,7 +141,7 @@ var Stats = function () {
138
141
139
142
}
140
143
141
- }
144
+ } ;
142
145
143
146
} ;
144
147
0 commit comments