From a7ef57b6eef9e0b82e59d7217e96fb1c9539aaef Mon Sep 17 00:00:00 2001 From: jdescottes Date: Fri, 26 Sep 2014 00:03:24 +0200 Subject: [PATCH] fixed color sorting for desaturated colors --- src/js/service/CurrentColorsService.js | 4 +++- src/js/service/color/ColorSorter.js | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/js/service/CurrentColorsService.js b/src/js/service/CurrentColorsService.js index fe71c4eb..d32f1aa4 100644 --- a/src/js/service/CurrentColorsService.js +++ b/src/js/service/CurrentColorsService.js @@ -15,6 +15,8 @@ ns.CurrentColorsService.prototype.init = function () { $.subscribe(Events.PISKEL_RESET, this.onPiskelUpdated_.bind(this)); $.subscribe(Events.TOOL_RELEASED, this.onPiskelUpdated_.bind(this)); + + // this.updateTimer = window.setInterval(this.updateCurrentColors_.bind(this)); }; ns.CurrentColorsService.prototype.getCurrentColors = function () { @@ -34,7 +36,7 @@ var layers = this.piskelController.getLayers(); var frames = layers.map(function (l) {return l.getFrames();}).reduce(function (p, n) {return p.concat(n);}); var colors = {}; - + frames.forEach(function (f) { var frameColors = this.cachedFrameProcessor.get(f); Object.keys(frameColors).slice(0, Constants.MAX_CURRENT_COLORS_DISPLAYED).forEach(function (color) { diff --git a/src/js/service/color/ColorSorter.js b/src/js/service/color/ColorSorter.js index a2ab027f..0f8e80c1 100644 --- a/src/js/service/color/ColorSorter.js +++ b/src/js/service/color/ColorSorter.js @@ -1,7 +1,7 @@ (function () { var ns = $.namespace('pskl.service.color'); - var LOW_SAT = 0.3; + var LOW_SAT = 0.1; var LOW_LUM = 0.1; var HI_LUM = 0.9; @@ -36,6 +36,8 @@ }.bind(this)); var desaturatedColors = colors.filter(function (c) { + return brightColors.indexOf(c) === -1 && darkColors.indexOf(c) === -1; + }).filter(function (c) { var hsl = this.colorsHslMap_[c]; return hsl.s <= LOW_SAT; }.bind(this)); @@ -44,22 +46,20 @@ brightColors = this.sortOnHslProperty_(brightColors, 'l'); desaturatedColors = this.sortOnHslProperty_(desaturatedColors, 'h'); - var sortedColors = darkColors.concat(brightColors).concat(desaturatedColors); - + var sortedColors = darkColors.concat(brightColors, desaturatedColors); + var regularColors = colors.filter(function (c) { return sortedColors.indexOf(c) === -1; }); - var regularColorsBags = []; - for (var i = 0 ; i < HUE_BOUNDS.length ; i++) { - var hue = HUE_BOUNDS[i]; + var regularColorsBags = HUE_BOUNDS.map(function (hue) { var bagColors = regularColors.filter(function (color) { var hsl = this.colorsHslMap_[color]; return (hsl.h >= hue && hsl.h < hue + HUE_STEP); }.bind(this)); - regularColorsBags[i] = this.sortRegularColors_(bagColors); - } + return this.sortRegularColors_(bagColors); + }.bind(this)); return Array.prototype.concat.apply(sortedColors, regularColorsBags); };