mirror of
https://github.com/konvajs/konva.git
synced 2026-01-21 18:51:52 +08:00
setup prettier and make all code better
This commit is contained in:
10666
test/lib/blanket.js
10666
test/lib/blanket.js
File diff suppressed because one or more lines are too long
@@ -4,15 +4,16 @@
|
||||
// For original source and documentation visit:
|
||||
// http://www.github.com/HumbleSoftware/js-imagediff
|
||||
|
||||
(function (name, definition) {
|
||||
(function(name, definition) {
|
||||
var root = this;
|
||||
if (typeof module !== 'undefined') {
|
||||
try {
|
||||
var Canvas = require('canvas');
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
e.message + '\n' +
|
||||
'Please see https://github.com/HumbleSoftware/js-imagediff#cannot-find-module-canvas\n'
|
||||
e.message +
|
||||
'\n' +
|
||||
'Please see https://github.com/HumbleSoftware/js-imagediff#cannot-find-module-canvas\n'
|
||||
);
|
||||
}
|
||||
module.exports = definition(root, name, Canvas);
|
||||
@@ -21,122 +22,115 @@
|
||||
} else {
|
||||
root[name] = definition(root, name);
|
||||
}
|
||||
})('imagediff', function (root, name, Canvas) {
|
||||
|
||||
var
|
||||
TYPE_ARRAY = /\[object Array\]/i,
|
||||
TYPE_CANVAS = /\[object (Canvas|HTMLCanvasElement)\]/i,
|
||||
TYPE_CONTEXT = /\[object CanvasRenderingContext2D\]/i,
|
||||
TYPE_IMAGE = /\[object (Image|HTMLImageElement)\]/i,
|
||||
TYPE_IMAGE_DATA = /\[object ImageData\]/i,
|
||||
|
||||
UNDEFINED = 'undefined',
|
||||
|
||||
canvas = getCanvas(),
|
||||
context = canvas.getContext('2d'),
|
||||
previous = root[name],
|
||||
imagediff, jasmine;
|
||||
})('imagediff', function(root, name, Canvas) {
|
||||
var TYPE_ARRAY = /\[object Array\]/i,
|
||||
TYPE_CANVAS = /\[object (Canvas|HTMLCanvasElement)\]/i,
|
||||
TYPE_CONTEXT = /\[object CanvasRenderingContext2D\]/i,
|
||||
TYPE_IMAGE = /\[object (Image|HTMLImageElement)\]/i,
|
||||
TYPE_IMAGE_DATA = /\[object ImageData\]/i,
|
||||
UNDEFINED = 'undefined',
|
||||
canvas = getCanvas(),
|
||||
context = canvas.getContext('2d'),
|
||||
previous = root[name],
|
||||
imagediff,
|
||||
jasmine;
|
||||
|
||||
// Creation
|
||||
function getCanvas (width, height) {
|
||||
var
|
||||
canvas = Canvas ?
|
||||
new Canvas() :
|
||||
document.createElement('canvas');
|
||||
function getCanvas(width, height) {
|
||||
var canvas = Canvas ? new Canvas() : document.createElement('canvas');
|
||||
if (width) canvas.width = width;
|
||||
if (height) canvas.height = height;
|
||||
return canvas;
|
||||
}
|
||||
function getImageData (width, height) {
|
||||
function getImageData(width, height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
context.clearRect(0, 0, width, height);
|
||||
return context.createImageData(width, height);
|
||||
}
|
||||
|
||||
|
||||
// Type Checking
|
||||
function isImage (object) {
|
||||
function isImage(object) {
|
||||
return isType(object, TYPE_IMAGE);
|
||||
}
|
||||
function isCanvas (object) {
|
||||
function isCanvas(object) {
|
||||
return isType(object, TYPE_CANVAS);
|
||||
}
|
||||
function isContext (object) {
|
||||
function isContext(object) {
|
||||
return isType(object, TYPE_CONTEXT);
|
||||
}
|
||||
function isImageData (object) {
|
||||
function isImageData(object) {
|
||||
return !!(object &&
|
||||
isType(object, TYPE_IMAGE_DATA) &&
|
||||
typeof(object.width) !== UNDEFINED &&
|
||||
typeof(object.height) !== UNDEFINED &&
|
||||
typeof(object.data) !== UNDEFINED);
|
||||
typeof object.width !== UNDEFINED &&
|
||||
typeof object.height !== UNDEFINED &&
|
||||
typeof object.data !== UNDEFINED);
|
||||
}
|
||||
function isImageType (object) {
|
||||
return (
|
||||
isImage(object) ||
|
||||
function isImageType(object) {
|
||||
return isImage(object) ||
|
||||
isCanvas(object) ||
|
||||
isContext(object) ||
|
||||
isImageData(object)
|
||||
);
|
||||
isImageData(object);
|
||||
}
|
||||
function isType (object, type) {
|
||||
return typeof (object) === 'object' && !!Object.prototype.toString.apply(object).match(type);
|
||||
function isType(object, type) {
|
||||
return typeof object === 'object' &&
|
||||
!!Object.prototype.toString.apply(object).match(type);
|
||||
}
|
||||
|
||||
|
||||
// Type Conversion
|
||||
function copyImageData (imageData) {
|
||||
var
|
||||
height = imageData.height,
|
||||
function copyImageData(imageData) {
|
||||
var height = imageData.height,
|
||||
width = imageData.width,
|
||||
data = imageData.data,
|
||||
newImageData, newData, i;
|
||||
newImageData,
|
||||
newData,
|
||||
i;
|
||||
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
newImageData = context.getImageData(0, 0, width, height);
|
||||
newData = newImageData.data;
|
||||
|
||||
for (i = imageData.data.length; i--;) {
|
||||
newData[i] = data[i];
|
||||
for (i = imageData.data.length; i--; ) {
|
||||
newData[i] = data[i];
|
||||
}
|
||||
|
||||
return newImageData;
|
||||
}
|
||||
function toImageData (object) {
|
||||
if (isImage(object)) { return toImageDataFromImage(object); }
|
||||
if (isCanvas(object)) { return toImageDataFromCanvas(object); }
|
||||
if (isContext(object)) { return toImageDataFromContext(object); }
|
||||
if (isImageData(object)) { return object; }
|
||||
function toImageData(object) {
|
||||
if (isImage(object)) {
|
||||
return toImageDataFromImage(object);
|
||||
}
|
||||
if (isCanvas(object)) {
|
||||
return toImageDataFromCanvas(object);
|
||||
}
|
||||
if (isContext(object)) {
|
||||
return toImageDataFromContext(object);
|
||||
}
|
||||
if (isImageData(object)) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
function toImageDataFromImage (image) {
|
||||
var
|
||||
height = image.height,
|
||||
width = image.width;
|
||||
function toImageDataFromImage(image) {
|
||||
var height = image.height, width = image.width;
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
context.clearRect(0, 0, width, height);
|
||||
context.drawImage(image, 0, 0);
|
||||
return context.getImageData(0, 0, width, height);
|
||||
}
|
||||
function toImageDataFromCanvas (canvas) {
|
||||
var
|
||||
height = canvas.height,
|
||||
function toImageDataFromCanvas(canvas) {
|
||||
var height = canvas.height,
|
||||
width = canvas.width,
|
||||
context = canvas.getContext('2d');
|
||||
return context.getImageData(0, 0, width, height);
|
||||
}
|
||||
function toImageDataFromContext (context) {
|
||||
var
|
||||
canvas = context.canvas,
|
||||
height = canvas.height,
|
||||
width = canvas.width;
|
||||
function toImageDataFromContext(context) {
|
||||
var canvas = context.canvas, height = canvas.height, width = canvas.width;
|
||||
return context.getImageData(0, 0, width, height);
|
||||
}
|
||||
function toCanvas (object) {
|
||||
var
|
||||
data = toImageData(object),
|
||||
function toCanvas(object) {
|
||||
var data = toImageData(object),
|
||||
canvas = getCanvas(data.width, data.height),
|
||||
context = canvas.getContext('2d');
|
||||
|
||||
@@ -144,80 +138,76 @@
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
||||
// ImageData Equality Operators
|
||||
function equalWidth (a, b) {
|
||||
function equalWidth(a, b) {
|
||||
return a.width === b.width;
|
||||
}
|
||||
function equalHeight (a, b) {
|
||||
function equalHeight(a, b) {
|
||||
return a.height === b.height;
|
||||
}
|
||||
function equalDimensions (a, b) {
|
||||
function equalDimensions(a, b) {
|
||||
return equalHeight(a, b) && equalWidth(a, b);
|
||||
}
|
||||
function equal (a, b, tolerance) {
|
||||
|
||||
var
|
||||
aData = a.data,
|
||||
bData = b.data,
|
||||
length = aData.length,
|
||||
i;
|
||||
function equal(a, b, tolerance) {
|
||||
var aData = a.data, bData = b.data, length = aData.length, i;
|
||||
|
||||
tolerance = tolerance || 0;
|
||||
|
||||
if (!equalDimensions(a, b)) return false;
|
||||
for (i = length; i--;) {
|
||||
if (aData[i] !== bData[i] && Math.abs(aData[i] - bData[i]) > tolerance) {
|
||||
console.log('Difference', Math.abs(aData[i] - bData[i]));
|
||||
return false;
|
||||
}
|
||||
for (i = length; i--; ) {
|
||||
if (aData[i] !== bData[i] && Math.abs(aData[i] - bData[i]) > tolerance) {
|
||||
console.log('Difference', Math.abs(aData[i] - bData[i]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Diff
|
||||
function diff (a, b, options) {
|
||||
function diff(a, b, options) {
|
||||
return (equalDimensions(a, b) ? diffEqual : diffUnequal)(a, b, options);
|
||||
}
|
||||
function diffEqual (a, b, options) {
|
||||
|
||||
var
|
||||
height = a.height,
|
||||
width = a.width,
|
||||
c = getImageData(width, height), // c = a - b
|
||||
aData = a.data,
|
||||
bData = b.data,
|
||||
cData = c.data,
|
||||
length = cData.length,
|
||||
row, column,
|
||||
i, j, k, v;
|
||||
function diffEqual(a, b, options) {
|
||||
var height = a.height,
|
||||
width = a.width,
|
||||
c = getImageData(width, height), // c = a - b
|
||||
aData = a.data,
|
||||
bData = b.data,
|
||||
cData = c.data,
|
||||
length = cData.length,
|
||||
row,
|
||||
column,
|
||||
i,
|
||||
j,
|
||||
k,
|
||||
v;
|
||||
|
||||
for (i = 0; i < length; i += 4) {
|
||||
cData[i] = Math.abs(aData[i] - bData[i]);
|
||||
cData[i+1] = Math.abs(aData[i+1] - bData[i+1]);
|
||||
cData[i+2] = Math.abs(aData[i+2] - bData[i+2]);
|
||||
cData[i+3] = Math.abs(255 - Math.abs(aData[i+3] - bData[i+3]));
|
||||
cData[i + 1] = Math.abs(aData[i + 1] - bData[i + 1]);
|
||||
cData[i + 2] = Math.abs(aData[i + 2] - bData[i + 2]);
|
||||
cData[i + 3] = Math.abs(255 - Math.abs(aData[i + 3] - bData[i + 3]));
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
function diffUnequal (a, b, options) {
|
||||
|
||||
var
|
||||
height = Math.max(a.height, b.height),
|
||||
width = Math.max(a.width, b.width),
|
||||
c = getImageData(width, height), // c = a - b
|
||||
aData = a.data,
|
||||
bData = b.data,
|
||||
cData = c.data,
|
||||
align = options && options.align,
|
||||
function diffUnequal(a, b, options) {
|
||||
var height = Math.max(a.height, b.height),
|
||||
width = Math.max(a.width, b.width),
|
||||
c = getImageData(width, height), // c = a - b
|
||||
aData = a.data,
|
||||
bData = b.data,
|
||||
cData = c.data,
|
||||
align = options && options.align,
|
||||
rowOffset,
|
||||
columnOffset,
|
||||
row, column,
|
||||
i, j, k, v;
|
||||
|
||||
row,
|
||||
column,
|
||||
i,
|
||||
j,
|
||||
k,
|
||||
v;
|
||||
|
||||
for (i = cData.length - 1; i > 0; i = i - 4) {
|
||||
cData[i] = 255;
|
||||
@@ -225,31 +215,31 @@
|
||||
|
||||
// Add First Image
|
||||
offsets(a);
|
||||
for (row = a.height; row--;){
|
||||
for (column = a.width; column--;) {
|
||||
for (row = a.height; row--; ) {
|
||||
for (column = a.width; column--; ) {
|
||||
i = 4 * ((row + rowOffset) * width + (column + columnOffset));
|
||||
j = 4 * (row * a.width + column);
|
||||
cData[i+0] = aData[j+0]; // r
|
||||
cData[i+1] = aData[j+1]; // g
|
||||
cData[i+2] = aData[j+2]; // b
|
||||
cData[i + 0] = aData[j + 0]; // r
|
||||
cData[i + 1] = aData[j + 1]; // g
|
||||
cData[i + 2] = aData[j + 2]; // b
|
||||
// cData[i+3] = aData[j+3]; // a
|
||||
}
|
||||
}
|
||||
|
||||
// Subtract Second Image
|
||||
offsets(b);
|
||||
for (row = b.height; row--;){
|
||||
for (column = b.width; column--;) {
|
||||
for (row = b.height; row--; ) {
|
||||
for (column = b.width; column--; ) {
|
||||
i = 4 * ((row + rowOffset) * width + (column + columnOffset));
|
||||
j = 4 * (row * b.width + column);
|
||||
cData[i+0] = Math.abs(cData[i+0] - bData[j+0]); // r
|
||||
cData[i+1] = Math.abs(cData[i+1] - bData[j+1]); // g
|
||||
cData[i+2] = Math.abs(cData[i+2] - bData[j+2]); // b
|
||||
cData[i + 0] = Math.abs(cData[i + 0] - bData[j + 0]); // r
|
||||
cData[i + 1] = Math.abs(cData[i + 1] - bData[j + 1]); // g
|
||||
cData[i + 2] = Math.abs(cData[i + 2] - bData[j + 2]); // b
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers
|
||||
function offsets (imageData) {
|
||||
function offsets(imageData) {
|
||||
if (align === 'top') {
|
||||
rowOffset = 0;
|
||||
columnOffset = 0;
|
||||
@@ -262,23 +252,21 @@
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// Validation
|
||||
function checkType () {
|
||||
function checkType() {
|
||||
var i;
|
||||
for (i = 0; i < arguments.length; i++) {
|
||||
if (!isImageType(arguments[i])) {
|
||||
throw {
|
||||
name : 'ImageTypeError',
|
||||
message : 'Submitted object was not an image.'
|
||||
name: 'ImageTypeError',
|
||||
message: 'Submitted object was not an image.'
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Jasmine Matchers
|
||||
function get (element, content) {
|
||||
function get(element, content) {
|
||||
element = document.createElement(element);
|
||||
if (element && content) {
|
||||
element.innerHTML = content;
|
||||
@@ -287,26 +275,23 @@
|
||||
}
|
||||
|
||||
jasmine = {
|
||||
|
||||
toBeImageData : function () {
|
||||
toBeImageData: function() {
|
||||
return imagediff.isImageData(this.actual);
|
||||
},
|
||||
|
||||
toImageDiffEqual : function (expected, tolerance) {
|
||||
|
||||
if (typeof (document) !== UNDEFINED) {
|
||||
this.message = function () {
|
||||
var
|
||||
div = get('div'),
|
||||
a = get('div', '<div>Actual:</div>'),
|
||||
b = get('div', '<div>Expected:</div>'),
|
||||
c = get('div', '<div>Diff:</div>'),
|
||||
diff = imagediff.diff(this.actual, expected),
|
||||
canvas = getCanvas(),
|
||||
toImageDiffEqual: function(expected, tolerance) {
|
||||
if (typeof document !== UNDEFINED) {
|
||||
this.message = function() {
|
||||
var div = get('div'),
|
||||
a = get('div', '<div>Actual:</div>'),
|
||||
b = get('div', '<div>Expected:</div>'),
|
||||
c = get('div', '<div>Diff:</div>'),
|
||||
diff = imagediff.diff(this.actual, expected),
|
||||
canvas = getCanvas(),
|
||||
context;
|
||||
|
||||
canvas.height = diff.height;
|
||||
canvas.width = diff.width;
|
||||
canvas.width = diff.width;
|
||||
|
||||
div.style.overflow = 'hidden';
|
||||
a.style.float = 'left';
|
||||
@@ -324,10 +309,7 @@
|
||||
div.appendChild(b);
|
||||
div.appendChild(c);
|
||||
|
||||
return [
|
||||
div,
|
||||
"Expected not to be equal."
|
||||
];
|
||||
return [div, 'Expected not to be equal.'];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -335,58 +317,53 @@
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Image Output
|
||||
function imageDataToPNG (imageData, outputFile, callback) {
|
||||
|
||||
var
|
||||
canvas = toCanvas(imageData),
|
||||
base64Data,
|
||||
decodedImage;
|
||||
function imageDataToPNG(imageData, outputFile, callback) {
|
||||
var canvas = toCanvas(imageData), base64Data, decodedImage;
|
||||
|
||||
callback = callback || Function;
|
||||
|
||||
base64Data = canvas.toDataURL().replace(/^data:image\/\w+;base64,/,"");
|
||||
base64Data = canvas.toDataURL().replace(/^data:image\/\w+;base64,/, '');
|
||||
decodedImage = new Buffer(base64Data, 'base64');
|
||||
require('fs').writeFile(outputFile, decodedImage, callback);
|
||||
}
|
||||
|
||||
|
||||
// Definition
|
||||
imagediff = {
|
||||
createCanvas: getCanvas,
|
||||
createImageData: getImageData,
|
||||
|
||||
createCanvas : getCanvas,
|
||||
createImageData : getImageData,
|
||||
isImage: isImage,
|
||||
isCanvas: isCanvas,
|
||||
isContext: isContext,
|
||||
isImageData: isImageData,
|
||||
isImageType: isImageType,
|
||||
|
||||
isImage : isImage,
|
||||
isCanvas : isCanvas,
|
||||
isContext : isContext,
|
||||
isImageData : isImageData,
|
||||
isImageType : isImageType,
|
||||
|
||||
toImageData : function (object) {
|
||||
toImageData: function(object) {
|
||||
checkType(object);
|
||||
if (isImageData(object)) { return copyImageData(object); }
|
||||
if (isImageData(object)) {
|
||||
return copyImageData(object);
|
||||
}
|
||||
return toImageData(object);
|
||||
},
|
||||
|
||||
equal : function (a, b, tolerance) {
|
||||
equal: function(a, b, tolerance) {
|
||||
checkType(a, b);
|
||||
a = toImageData(a);
|
||||
b = toImageData(b);
|
||||
return equal(a, b, tolerance);
|
||||
},
|
||||
diff : function (a, b, options) {
|
||||
diff: function(a, b, options) {
|
||||
checkType(a, b);
|
||||
a = toImageData(a);
|
||||
b = toImageData(b);
|
||||
return diff(a, b, options);
|
||||
},
|
||||
|
||||
jasmine : jasmine,
|
||||
jasmine: jasmine,
|
||||
|
||||
// Compatibility
|
||||
noConflict : function () {
|
||||
noConflict: function() {
|
||||
root[name] = previous;
|
||||
return imagediff;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,100 @@
|
||||
// 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 = 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();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user