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",
"version": "0.5.0",
"name": "dat.gui",
"version": "0.6.0",
"homepage": "https://github.com/dataarts/dat.gui",
"authors": [
"Google Data Arts Team <dataarts@google.com>"
],
"description": "dat.gui is a lightweight controller library for JavaScript.",
"main": "./build/dat.gui.js",
"main": "./index.js",
"keywords": [
"controller",
"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();
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, 'displayOutline');
gui.add(obj.example, 'explode');

View File

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

View File

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

View File

@ -11,46 +11,20 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
import * as toString from './toString';
import toString from './toString';
import common from '../utils/common';
var result, toReturn;
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 = [
const INTERPRETATIONS = [
// Strings
{
litmus: common.isString,
conversions: {
THREE_CHAR_HEX: {
read: function(original) {
var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);
if (test === null) return false;
const test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);
if (test === null) {
return false;
}
return {
space: 'HEX',
@ -58,9 +32,8 @@ var INTERPRETATIONS = [
'0x' +
test[1].toString() + test[1].toString() +
test[2].toString() + test[2].toString() +
test[3].toString() + test[3].toString())
test[3].toString() + test[3].toString(), 0)
};
},
write: toString
@ -68,15 +41,15 @@ var INTERPRETATIONS = [
SIX_CHAR_HEX: {
read: function(original) {
var test = original.match(/^#([A-F0-9]{6})$/i);
if (test === null) return false;
const test = original.match(/^#([A-F0-9]{6})$/i);
if (test === null) {
return false;
}
return {
space: 'HEX',
hex: parseInt('0x' + test[1].toString())
hex: parseInt('0x' + test[1].toString(), 0)
};
},
write: toString
@ -84,9 +57,10 @@ var INTERPRETATIONS = [
CSS_RGB: {
read: function(original) {
var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
if (test === null) return false;
const test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
if (test === null) {
return false;
}
return {
space: 'RGB',
@ -94,7 +68,6 @@ var INTERPRETATIONS = [
g: parseFloat(test[2]),
b: parseFloat(test[3])
};
},
write: toString
@ -102,9 +75,10 @@ var INTERPRETATIONS = [
CSS_RGBA: {
read: function(original) {
var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/);
if (test === null) return false;
const test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\,\s*(.+)\s*\)/);
if (test === null) {
return false;
}
return {
space: 'RGB',
@ -132,7 +106,7 @@ var INTERPRETATIONS = [
space: 'HEX',
hex: original,
conversionName: 'HEX'
}
};
},
write: function(color) {
@ -148,10 +122,12 @@ var INTERPRETATIONS = [
{
litmus: common.isArray,
conversions: {
RGB_ARRAY: {
read: function(original) {
if (original.length != 3) return false;
if (original.length !== 3) {
return false;
}
return {
space: 'RGB',
r: original[0],
@ -167,7 +143,7 @@ var INTERPRETATIONS = [
RGBA_ARRAY: {
read: function(original) {
if (original.length != 4) return false;
if (original.length !== 4) return false;
return {
space: 'RGB',
r: original[0],
@ -186,9 +162,7 @@ var INTERPRETATIONS = [
// Objects
{
litmus: common.isObject,
conversions: {
RGBA_OBJ: {
@ -203,7 +177,7 @@ var INTERPRETATIONS = [
g: original.g,
b: original.b,
a: original.a
}
};
}
return false;
},
@ -214,7 +188,7 @@ var INTERPRETATIONS = [
g: color.g,
b: color.b,
a: color.a
}
};
}
},
@ -228,7 +202,7 @@ var INTERPRETATIONS = [
r: original.r,
g: original.g,
b: original.b
}
};
}
return false;
},
@ -238,7 +212,7 @@ var INTERPRETATIONS = [
r: color.r,
g: color.g,
b: color.b
}
};
}
},
@ -254,7 +228,7 @@ var INTERPRETATIONS = [
s: original.s,
v: original.v,
a: original.a
}
};
}
return false;
},
@ -265,7 +239,7 @@ var INTERPRETATIONS = [
s: color.s,
v: color.v,
a: color.a
}
};
}
},
@ -279,7 +253,7 @@ var INTERPRETATIONS = [
h: original.h,
s: original.s,
v: original.v
}
};
}
return false;
},
@ -289,11 +263,38 @@ var INTERPRETATIONS = [
h: color.h,
s: color.s,
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;

View File

@ -13,17 +13,14 @@
import common from '../utils/common';
var colorToString = function (color) {
if (color.a == 1 || common.isUndefined(color.a)) {
var s = color.hex.toString(16);
export default function(color) {
if (color.a === 1 || common.isUndefined(color.a)) {
let s = color.hex.toString(16);
while (s.length < 6) {
s = '0' + 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
* is modified via this Controller.
* @returns {dat.controllers.Controller} this
* @returns {Controller} this
*/
onChange(fnc) {
this.__onChange = fnc;
@ -78,7 +78,7 @@ class Controller {
*
* @param {Function} fnc This function will be called whenever
* someone "finishes" changing the value via this Controller.
* @returns {dat.controllers.Controller} this
* @returns {Controller} this
*/
onFinishChange(fnc) {
this.__onFinishChange = fnc;
@ -95,6 +95,7 @@ class Controller {
if (this.__onChange) {
this.__onChange.call(this, newValue);
}
this.updateDisplay();
return this;
}
@ -111,7 +112,7 @@ class Controller {
/**
* Refreshes the visual display of a Controller in order to keep sync
* with the object's current value.
* @returns {dat.controllers.Controller} this
* @returns {Controller} this
*/
updateDisplay() {
return this;

View File

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

View File

@ -14,7 +14,8 @@
import dom from '../dom/dom';
import common from '../utils/common';
var CenteredDiv = function () {
class CenteredDiv {
constructor() {
this.backgroundElement = document.createElement('div');
common.extend(this.backgroundElement.style, {
@ -49,12 +50,9 @@ var CenteredDiv = function () {
dom.bind(this.backgroundElement, 'click', function () {
_this.hide();
});
}
};
CenteredDiv.prototype.show = function () {
show() {
var _this = this;
this.backgroundElement.style.display = 'block';
@ -74,8 +72,10 @@ CenteredDiv.prototype.show = function () {
};
CenteredDiv.prototype.hide = function () {
/**
* Hide centered div
*/
hide() {
var _this = this;
var hide = function () {
@ -100,10 +100,11 @@ CenteredDiv.prototype.hide = function () {
};
CenteredDiv.prototype.layout = function () {
layout() {
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';
};
}
}
function lockScroll(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);
} else if (obj.length === obj.length + 0) { // Is number but not NaN
let key;
let l;
for (key = 0, l = obj.length; key < l; key++) {
if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {
return;

View File

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