From c85f591f93b1366f9153747cbce1e94c9e4357e4 Mon Sep 17 00:00:00 2001 From: Tomas Korcak Date: Fri, 14 Aug 2015 22:53:46 +0200 Subject: [PATCH] Fixed eslint issues --- src/dat/color/Color.js | 23 +++++++++---------- src/dat/color/math.js | 48 +++++++++++++++++++-------------------- src/dat/color/toString.js | 2 +- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/dat/color/Color.js b/src/dat/color/Color.js index 3353631..8401f6e 100644 --- a/src/dat/color/Color.js +++ b/src/dat/color/Color.js @@ -21,7 +21,7 @@ class Color { this.__state = interpret.apply(this, arguments); if (this.__state === false) { - throw 'Failed to interpret color arguments'; + throw new Error('Failed to interpret color arguments'); } this.__state.a = this.__state.a || 1; @@ -42,12 +42,12 @@ Color.recalculateRGB = function(color, component, componentHexIndex) { } else if (color.__state.space === 'HSV') { common.extend(color.__state, math.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v)); } else { - throw 'Corrupted color state'; + throw new Error('Corrupted color state'); } }; Color.recalculateHSV = function(color) { - var result = math.rgb_to_hsv(color.r, color.g, color.b); + const result = math.rgb_to_hsv(color.r, color.g, color.b); common.extend(color.__state, { @@ -74,17 +74,17 @@ defineHSVComponent(Color.prototype, 's'); defineHSVComponent(Color.prototype, 'v'); Object.defineProperty(Color.prototype, 'a', { - get: function () { + get: function() { return this.__state.a; }, - set: function (v) { + set: function(v) { this.__state.a = v; } }); Object.defineProperty(Color.prototype, 'hex', { - get: function () { + get: function() { if (!this.__state.space !== 'HEX') { this.__state.hex = math.rgb_to_hex(this.r, this.g, this.b); } @@ -92,7 +92,7 @@ Object.defineProperty(Color.prototype, 'hex', { return this.__state.hex; }, - set: function (v) { + set: function(v) { this.__state.space = 'HEX'; this.__state.hex = v; } @@ -100,7 +100,7 @@ Object.defineProperty(Color.prototype, 'hex', { function defineRGBComponent(target, component, componentHexIndex) { Object.defineProperty(target, component, { - get: function () { + get: function() { if (this.__state.space === 'RGB') { return this.__state[component]; } @@ -110,7 +110,7 @@ function defineRGBComponent(target, component, componentHexIndex) { return this.__state[component]; }, - set: function (v) { + set: function(v) { if (this.__state.space !== 'RGB') { Color.recalculateRGB(this, component, componentHexIndex); this.__state.space = 'RGB'; @@ -123,7 +123,7 @@ function defineRGBComponent(target, component, componentHexIndex) { function defineHSVComponent(target, component) { Object.defineProperty(target, component, { - get: function () { + get: function() { if (this.__state.space === 'HSV') { return this.__state[component]; } @@ -131,10 +131,9 @@ function defineHSVComponent(target, component) { Color.recalculateHSV(this); return this.__state[component]; - }, - set: function (v) { + set: function(v) { if (this.__state.space !== 'HSV') { Color.recalculateHSV(this); this.__state.space = 'HSV'; diff --git a/src/dat/color/math.js b/src/dat/color/math.js index 2d4c4df..e9f02d5 100644 --- a/src/dat/color/math.js +++ b/src/dat/color/math.js @@ -11,19 +11,18 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -var tmpComponent; +let tmpComponent; -var ColorMath = { +const ColorMath = { + hsv_to_rgb: function(h, s, v) { + const hi = Math.floor(h / 60) % 6; - hsv_to_rgb: function (h, s, v) { + const f = h / 60 - Math.floor(h / 60); + const p = v * (1.0 - s); + const q = v * (1.0 - (f * s)); + const t = v * (1.0 - ((1.0 - f) * s)); - var hi = Math.floor(h / 60) % 6; - - var f = h / 60 - Math.floor(h / 60); - var p = v * (1.0 - s); - var q = v * (1.0 - (f * s)); - var t = v * (1.0 - ((1.0 - f) * s)); - var c = [ + const c = [ [v, t, p], [q, v, p], [p, v, t], @@ -37,17 +36,16 @@ var ColorMath = { g: c[1] * 255, b: c[2] * 255 }; - }, - rgb_to_hsv: function (r, g, b) { + rgb_to_hsv: function(r, g, b) { + const min = Math.min(r, g, b); + const max = Math.max(r, g, b); + const delta = max - min; + let h; + let s; - var min = Math.min(r, g, b), - max = Math.max(r, g, b), - delta = max - min, - h, s; - - if (max != 0) { + if (max !== 0) { s = delta / max; } else { return { @@ -57,9 +55,9 @@ var ColorMath = { }; } - if (r == max) { + if (r === max) { h = (g - b) / delta; - } else if (g == max) { + } else if (g === max) { h = 2 + (b - r) / delta; } else { h = 4 + (r - g) / delta; @@ -76,20 +74,20 @@ var ColorMath = { }; }, - rgb_to_hex: function (r, g, b) { - var hex = this.hex_with_component(0, 2, r); + rgb_to_hex: function(r, g, b) { + let hex = this.hex_with_component(0, 2, r); hex = this.hex_with_component(hex, 1, g); hex = this.hex_with_component(hex, 0, b); return hex; }, - component_from_hex: function (hex, componentIndex) { + component_from_hex: function(hex, componentIndex) { return (hex >> (componentIndex * 8)) & 0xFF; }, - hex_with_component: function (hex, componentIndex, value) { + hex_with_component: function(hex, componentIndex, value) { return value << (tmpComponent = componentIndex * 8) | (hex & ~(0xFF << tmpComponent)); } -} +}; export default ColorMath; diff --git a/src/dat/color/toString.js b/src/dat/color/toString.js index 81825d6..ec87966 100644 --- a/src/dat/color/toString.js +++ b/src/dat/color/toString.js @@ -23,4 +23,4 @@ export default function(color) { } return 'rgba(' + Math.round(color.r) + ',' + Math.round(color.g) + ',' + Math.round(color.b) + ',' + color.a + ')'; -}; \ No newline at end of file +}