Fixing dat.gui issues

This commit is contained in:
Tomas Korcak 2015-08-14 22:29:30 +02:00
parent 82ba3fab49
commit 2a8011df34
17 changed files with 1166 additions and 1407 deletions

View File

@ -1,3 +1,8 @@
{ {
"extends": "eslint-config-airbnb" "extends": "eslint-config-airbnb",
"rules": {
"comma-dangle": 0,
"func-names": 0,
"no-alert": 0
}
} }

View File

@ -1,12 +1,12 @@
{ {
"name": "dat-gui", "name": "dat.gui",
"version": "0.5.0", "version": "0.6.0",
"homepage": "https://github.com/dataarts/dat.gui", "homepage": "https://github.com/dataarts/dat.gui",
"authors": [ "authors": [
"Google Data Arts Team <dataarts@google.com>" "Google Data Arts Team <dataarts@google.com>"
], ],
"description": "dat.gui is a lightweight controller library for JavaScript.", "description": "dat.gui is a lightweight controller library for JavaScript.",
"main": "./build/dat.gui.js", "main": "./index.js",
"keywords": [ "keywords": [
"controller", "controller",
"javascript", "javascript",

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

2
build/dat.gui.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,16 @@
}; };
var gui = new dat.gui.GUI(); var gui = new dat.gui.GUI();
gui.add(obj.example, 'message');
gui.remember(obj);
gui.remember(obj.example);
gui.remember(obj.flow);
gui.remember(obj.letters);
gui.add(obj.example, 'message').onFinishChange(function(value) {
// Fires when a controller loses focus.
console.log("obj.example.message = " + value);
});;
gui.add(obj.example, 'speed', -5, 5); gui.add(obj.example, 'speed', -5, 5);
gui.add(obj.example, 'displayOutline'); gui.add(obj.example, 'displayOutline');
gui.add(obj.example, 'explode'); gui.add(obj.example, 'explode');

View File

@ -26,8 +26,11 @@
"babel-eslint": "^4.0.5", "babel-eslint": "^4.0.5",
"babel-loader": "^5.3.2", "babel-loader": "^5.3.2",
"css-loader": "^0.16.0", "css-loader": "^0.16.0",
"esdoc": "^0.2.1",
"esdoc-es7-plugin": "0.0.1",
"eslint": "^1.1.0", "eslint": "^1.1.0",
"eslint-config-airbnb": "0.0.7", "eslint-config-airbnb": "0.0.7",
"eslint-loader": "^1.0.0",
"eslint-plugin-react": "^3.2.2", "eslint-plugin-react": "^3.2.2",
"extend": "^3.0.0", "extend": "^3.0.0",
"html-loader": "^0.3.0", "html-loader": "^0.3.0",

View File

@ -74,7 +74,6 @@ defineHSVComponent(Color.prototype, 's');
defineHSVComponent(Color.prototype, 'v'); defineHSVComponent(Color.prototype, 'v');
Object.defineProperty(Color.prototype, 'a', { Object.defineProperty(Color.prototype, 'a', {
get: function () { get: function () {
return this.__state.a; return this.__state.a;
}, },
@ -100,7 +99,6 @@ Object.defineProperty(Color.prototype, 'hex', {
}); });
function defineRGBComponent(target, component, componentHexIndex) { function defineRGBComponent(target, component, componentHexIndex) {
Object.defineProperty(target, component, { Object.defineProperty(target, component, {
get: function () { get: function () {
if (this.__state.space === 'RGB') { if (this.__state.space === 'RGB') {
@ -126,8 +124,9 @@ function defineRGBComponent(target, component, componentHexIndex) {
function defineHSVComponent(target, component) { function defineHSVComponent(target, component) {
Object.defineProperty(target, component, { Object.defineProperty(target, component, {
get: function () { get: function () {
if (this.__state.space === 'HSV') if (this.__state.space === 'HSV') {
return this.__state[component]; return this.__state[component];
}
Color.recalculateHSV(this); Color.recalculateHSV(this);

View File

@ -11,46 +11,20 @@
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*/ */
import * as toString from './toString'; import toString from './toString';
import common from '../utils/common'; import common from '../utils/common';
var result, toReturn; const INTERPRETATIONS = [
var interpret = function () {
toReturn = false;
var original = arguments.length > 1 ? common.toArray(arguments) : arguments[0];
common.each(INTERPRETATIONS, function (family) {
if (family.litmus(original)) {
common.each(family.conversions, function (conversion, conversionName) {
result = conversion.read(original);
if (toReturn === false && result !== false) {
toReturn = result;
result.conversionName = conversionName;
result.conversion = conversion;
return common.BREAK;
}
});
return common.BREAK;
}
});
return toReturn;
};
var INTERPRETATIONS = [
// Strings // Strings
{ {
litmus: common.isString, litmus: common.isString,
conversions: { conversions: {
THREE_CHAR_HEX: { THREE_CHAR_HEX: {
read: function (original) { read: function(original) {
const test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);
var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i); if (test === null) {
if (test === null) return false; return false;
}
return { return {
space: 'HEX', space: 'HEX',
@ -58,35 +32,35 @@ var INTERPRETATIONS = [
'0x' + '0x' +
test[1].toString() + test[1].toString() + test[1].toString() + test[1].toString() +
test[2].toString() + test[2].toString() + test[2].toString() + test[2].toString() +
test[3].toString() + test[3].toString()) test[3].toString() + test[3].toString(), 0)
}; };
}, },
write: toString write: toString
}, },
SIX_CHAR_HEX: { SIX_CHAR_HEX: {
read: function (original) { read: function(original) {
const test = original.match(/^#([A-F0-9]{6})$/i);
var test = original.match(/^#([A-F0-9]{6})$/i); if (test === null) {
if (test === null) return false; return false;
}
return { return {
space: 'HEX', space: 'HEX',
hex: parseInt('0x' + test[1].toString()) hex: parseInt('0x' + test[1].toString(), 0)
}; };
}, },
write: toString write: toString
}, },
CSS_RGB: { CSS_RGB: {
read: function (original) { read: function(original) {
const test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); if (test === null) {
if (test === null) return false; return false;
}
return { return {
space: 'RGB', space: 'RGB',
@ -94,17 +68,17 @@ var INTERPRETATIONS = [
g: parseFloat(test[2]), g: parseFloat(test[2]),
b: parseFloat(test[3]) b: parseFloat(test[3])
}; };
}, },
write: toString write: toString
}, },
CSS_RGBA: { CSS_RGBA: {
read: function (original) { read: function(original) {
const test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/);
var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/); if (test === null) {
if (test === null) return false; return false;
}
return { return {
space: 'RGB', space: 'RGB',
@ -127,15 +101,15 @@ var INTERPRETATIONS = [
conversions: { conversions: {
HEX: { HEX: {
read: function (original) { read: function(original) {
return { return {
space: 'HEX', space: 'HEX',
hex: original, hex: original,
conversionName: 'HEX' conversionName: 'HEX'
} };
}, },
write: function (color) { write: function(color) {
return color.hex; return color.hex;
} }
} }
@ -148,10 +122,12 @@ var INTERPRETATIONS = [
{ {
litmus: common.isArray, litmus: common.isArray,
conversions: { conversions: {
RGB_ARRAY: { RGB_ARRAY: {
read: function (original) { read: function(original) {
if (original.length != 3) return false; if (original.length !== 3) {
return false;
}
return { return {
space: 'RGB', space: 'RGB',
r: original[0], r: original[0],
@ -160,14 +136,14 @@ var INTERPRETATIONS = [
}; };
}, },
write: function (color) { write: function(color) {
return [color.r, color.g, color.b]; return [color.r, color.g, color.b];
} }
}, },
RGBA_ARRAY: { RGBA_ARRAY: {
read: function (original) { read: function(original) {
if (original.length != 4) return false; if (original.length !== 4) return false;
return { return {
space: 'RGB', space: 'RGB',
r: original[0], r: original[0],
@ -177,7 +153,7 @@ var INTERPRETATIONS = [
}; };
}, },
write: function (color) { write: function(color) {
return [color.r, color.g, color.b, color.a]; return [color.r, color.g, color.b, color.a];
} }
} }
@ -186,13 +162,11 @@ var INTERPRETATIONS = [
// Objects // Objects
{ {
litmus: common.isObject, litmus: common.isObject,
conversions: { conversions: {
RGBA_OBJ: { RGBA_OBJ: {
read: function (original) { read: function(original) {
if (common.isNumber(original.r) && if (common.isNumber(original.r) &&
common.isNumber(original.g) && common.isNumber(original.g) &&
common.isNumber(original.b) && common.isNumber(original.b) &&
@ -203,23 +177,23 @@ var INTERPRETATIONS = [
g: original.g, g: original.g,
b: original.b, b: original.b,
a: original.a a: original.a
} };
} }
return false; return false;
}, },
write: function (color) { write: function(color) {
return { return {
r: color.r, r: color.r,
g: color.g, g: color.g,
b: color.b, b: color.b,
a: color.a a: color.a
} };
} }
}, },
RGB_OBJ: { RGB_OBJ: {
read: function (original) { read: function(original) {
if (common.isNumber(original.r) && if (common.isNumber(original.r) &&
common.isNumber(original.g) && common.isNumber(original.g) &&
common.isNumber(original.b)) { common.isNumber(original.b)) {
@ -228,22 +202,22 @@ var INTERPRETATIONS = [
r: original.r, r: original.r,
g: original.g, g: original.g,
b: original.b b: original.b
} };
} }
return false; return false;
}, },
write: function (color) { write: function(color) {
return { return {
r: color.r, r: color.r,
g: color.g, g: color.g,
b: color.b b: color.b
} };
} }
}, },
HSVA_OBJ: { HSVA_OBJ: {
read: function (original) { read: function(original) {
if (common.isNumber(original.h) && if (common.isNumber(original.h) &&
common.isNumber(original.s) && common.isNumber(original.s) &&
common.isNumber(original.v) && common.isNumber(original.v) &&
@ -254,23 +228,23 @@ var INTERPRETATIONS = [
s: original.s, s: original.s,
v: original.v, v: original.v,
a: original.a a: original.a
} };
} }
return false; return false;
}, },
write: function (color) { write: function(color) {
return { return {
h: color.h, h: color.h,
s: color.s, s: color.s,
v: color.v, v: color.v,
a: color.a a: color.a
} };
} }
}, },
HSV_OBJ: { HSV_OBJ: {
read: function (original) { read: function(original) {
if (common.isNumber(original.h) && if (common.isNumber(original.h) &&
common.isNumber(original.s) && common.isNumber(original.s) &&
common.isNumber(original.v)) { common.isNumber(original.v)) {
@ -279,21 +253,48 @@ var INTERPRETATIONS = [
h: original.h, h: original.h,
s: original.s, s: original.s,
v: original.v v: original.v
} };
} }
return false; return false;
}, },
write: function (color) { write: function(color) {
return { return {
h: color.h, h: color.h,
s: color.s, s: color.s,
v: color.v v: color.v
} };
} }
} }
} }
} }
]; ];
let result;
let toReturn;
const interpret = function() {
toReturn = false;
const original = arguments.length > 1 ? common.toArray(arguments) : arguments[0];
common.each(INTERPRETATIONS, function(family) {
if (family.litmus(original)) {
common.each(family.conversions, function(conversion, conversionName) {
result = conversion.read(original);
if (toReturn === false && result !== false) {
toReturn = result;
result.conversionName = conversionName;
result.conversion = conversion;
return common.BREAK;
}
});
return common.BREAK;
}
});
return toReturn;
};
export default interpret; export default interpret;

View File

@ -13,17 +13,14 @@
import common from '../utils/common'; import common from '../utils/common';
var colorToString = function (color) { export default function(color) {
if (color.a == 1 || common.isUndefined(color.a)) { if (color.a === 1 || common.isUndefined(color.a)) {
var s = color.hex.toString(16); let s = color.hex.toString(16);
while (s.length < 6) { while (s.length < 6) {
s = '0' + s; s = '0' + s;
} }
return '#' + s; return '#' + s;
} else {
return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')';
} }
};
export default colorToString; return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')';
};

View File

@ -64,7 +64,7 @@ class Controller {
* *
* @param {Function} fnc This function will be called whenever the value * @param {Function} fnc This function will be called whenever the value
* is modified via this Controller. * is modified via this Controller.
* @returns {dat.controllers.Controller} this * @returns {Controller} this
*/ */
onChange(fnc) { onChange(fnc) {
this.__onChange = fnc; this.__onChange = fnc;
@ -78,7 +78,7 @@ class Controller {
* *
* @param {Function} fnc This function will be called whenever * @param {Function} fnc This function will be called whenever
* someone "finishes" changing the value via this Controller. * someone "finishes" changing the value via this Controller.
* @returns {dat.controllers.Controller} this * @returns {Controller} this
*/ */
onFinishChange(fnc) { onFinishChange(fnc) {
this.__onFinishChange = fnc; this.__onFinishChange = fnc;
@ -95,6 +95,7 @@ class Controller {
if (this.__onChange) { if (this.__onChange) {
this.__onChange.call(this, newValue); this.__onChange.call(this, newValue);
} }
this.updateDisplay(); this.updateDisplay();
return this; return this;
} }
@ -111,7 +112,7 @@ class Controller {
/** /**
* Refreshes the visual display of a Controller in order to keep sync * Refreshes the visual display of a Controller in order to keep sync
* with the object's current value. * with the object's current value.
* @returns {dat.controllers.Controller} this * @returns {Controller} this
*/ */
updateDisplay() { updateDisplay() {
return this; return this;

View File

@ -33,6 +33,7 @@ class FunctionController extends Controller{
this.__button = document.createElement('div'); this.__button = document.createElement('div');
this.__button.innerHTML = text === undefined ? 'Fire' : text; this.__button.innerHTML = text === undefined ? 'Fire' : text;
dom.bind(this.__button, 'click', function (e) { dom.bind(this.__button, 'click', function (e) {
e.preventDefault(); e.preventDefault();
_this.fire(); _this.fire();

View File

@ -14,7 +14,8 @@
import dom from '../dom/dom'; import dom from '../dom/dom';
import common from '../utils/common'; import common from '../utils/common';
var CenteredDiv = function () { class CenteredDiv {
constructor() {
this.backgroundElement = document.createElement('div'); this.backgroundElement = document.createElement('div');
common.extend(this.backgroundElement.style, { common.extend(this.backgroundElement.style, {
@ -49,12 +50,9 @@ var CenteredDiv = function () {
dom.bind(this.backgroundElement, 'click', function () { dom.bind(this.backgroundElement, 'click', function () {
_this.hide(); _this.hide();
}); });
}
show() {
};
CenteredDiv.prototype.show = function () {
var _this = this; var _this = this;
this.backgroundElement.style.display = 'block'; this.backgroundElement.style.display = 'block';
@ -72,10 +70,12 @@ CenteredDiv.prototype.show = function () {
_this.domElement.style.webkitTransform = 'scale(1)'; _this.domElement.style.webkitTransform = 'scale(1)';
}); });
}; };
CenteredDiv.prototype.hide = function () {
/**
* Hide centered div
*/
hide() {
var _this = this; var _this = this;
var hide = function () { var hide = function () {
@ -98,12 +98,13 @@ CenteredDiv.prototype.hide = function () {
this.domElement.style.opacity = 0; this.domElement.style.opacity = 0;
this.domElement.style.webkitTransform = 'scale(1.1)'; this.domElement.style.webkitTransform = 'scale(1.1)';
}; };
CenteredDiv.prototype.layout = function () { layout() {
this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px'; this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px';
this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px'; this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px';
}; }
}
function lockScroll(e) { function lockScroll(e) {
console.log(e); console.log(e);

File diff suppressed because it is too large Load Diff

View File

@ -67,6 +67,7 @@ const Common = {
obj.forEach(itr, scope); obj.forEach(itr, scope);
} else if (obj.length === obj.length + 0) { // Is number but not NaN } else if (obj.length === obj.length + 0) { // Is number but not NaN
let key; let key;
let l;
for (key = 0, l = obj.length; key < l; key++) { for (key = 0, l = obj.length; key < l; key++) {
if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) { if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {
return; return;

View File

@ -16,16 +16,21 @@ module.exports = {
exclude: /(node_modules|bower_components)/, exclude: /(node_modules|bower_components)/,
loader: 'babel' loader: 'babel'
}, },
/*
{
test: /\.js$/, loader: 'eslint-loader', exclude: /node_modules/
},
//*/
{ {
test: /\.css$/, test: /\.css$/,
loader: "style-loader!css-loader" loader: 'style-loader!css-loader'
}, },
{ {
test: /\.png$/, test: /\.png$/,
loader: "url-loader?limit=100000" loader: 'url-loader?limit=100000'
}, },
{ {
test: /\.jpg$/, loader: "file-loader" test: /\.jpg$/, loader: 'file-loader'
}, },
{ {
test: /\.scss$/, test: /\.scss$/,