Skip to content

Commit 3b49ad4

Browse files
committed
arbitrary width and height of stats via options object
1 parent 73905e2 commit 3b49ad4

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/Stats.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

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;
611

712
var startTime = Date.now(), prevTime = startTime;
813
var ms = 0, msMin = Infinity, msMax = 0;
@@ -11,53 +16,51 @@ var Stats = function () {
1116

1217
var container = document.createElement( 'div' );
1318
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';
1621

1722
var fpsDiv = document.createElement( 'div' );
1823
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';
2025
container.appendChild( fpsDiv );
2126

2227
var fpsText = document.createElement( 'div' );
2328
fpsText.id = 'fpsText';
24-
fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
2529
fpsText.innerHTML = 'FPS';
2630
fpsDiv.appendChild( fpsText );
2731

2832
var fpsGraph = document.createElement( 'div' );
2933
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';
3135
fpsDiv.appendChild( fpsGraph );
3236

33-
while ( fpsGraph.children.length < 74 ) {
37+
while ( fpsGraph.children.length < bars ) {
3438

3539
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';
3741
fpsGraph.appendChild( bar );
3842

3943
}
4044

4145
var msDiv = document.createElement( 'div' );
4246
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;';
4448
container.appendChild( msDiv );
4549

4650
var msText = document.createElement( 'div' );
4751
msText.id = 'msText';
48-
msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
4952
msText.innerHTML = 'MS';
5053
msDiv.appendChild( msText );
5154

5255
var msGraph = document.createElement( 'div' );
5356
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';
5558
msDiv.appendChild( msGraph );
5659

57-
while ( msGraph.children.length < 74 ) {
60+
while ( msGraph.children.length < bars ) {
5861

5962
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';
6164
msGraph.appendChild( bar );
6265

6366
}
@@ -110,7 +113,7 @@ var Stats = function () {
110113
msMax = Math.max( msMax, ms );
111114

112115
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 ) );
114117

115118
frames ++;
116119

@@ -121,7 +124,7 @@ var Stats = function () {
121124
fpsMax = Math.max( fpsMax, fps );
122125

123126
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 ) );
125128

126129
prevTime = time;
127130
frames = 0;
@@ -138,7 +141,7 @@ var Stats = function () {
138141

139142
}
140143

141-
}
144+
};
142145

143146
};
144147

0 commit comments

Comments
 (0)