From 71f04ff6a9b425ffcb64dc0c65f09bfd03d8c1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Arroyo=20Torrens?= Date: Thu, 19 Dec 2019 00:37:43 +0100 Subject: [PATCH 1/2] Fix bestSubPalette detection --- .../viz/expressions/color/palettes/Palette.js | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/renderer/viz/expressions/color/palettes/Palette.js b/src/renderer/viz/expressions/color/palettes/Palette.js index 0b8a9c5c3..65c0ff62f 100644 --- a/src/renderer/viz/expressions/color/palettes/Palette.js +++ b/src/renderer/viz/expressions/color/palettes/Palette.js @@ -3,8 +3,6 @@ import { hexToRgb } from '../../utils'; import { RGBA } from '../rgb'; import { constant } from '../../../expressions'; -const MIN_CARTOCOLOR_SUBPALETTE_SIZE = 2; - /** * Color palettes. * @@ -70,23 +68,33 @@ export default class Palette extends BaseExpression { } _getBestSubPalette (subPaletteIndex) { - subPaletteIndex = subPaletteIndex <= MIN_CARTOCOLOR_SUBPALETTE_SIZE - ? MIN_CARTOCOLOR_SUBPALETTE_SIZE - : subPaletteIndex; - const longestSubPalette = this.getLongestSubPalette(); - const subPalette = (subPaletteIndex < longestSubPalette.length - ? [...this.subPalettes[subPaletteIndex]] - : [...longestSubPalette]); + const longestSubPaletteIndex = this.getLongestSubPaletteIndex(); + const smallestSubPaletteIndex = this.getSmallestSubPaletteIndex(); + if (!Number.isInteger(subPaletteIndex) || subPaletteIndex > longestSubPaletteIndex) { + subPaletteIndex = longestSubPaletteIndex; + } else if (subPaletteIndex < smallestSubPaletteIndex) { + subPaletteIndex = smallestSubPaletteIndex; + } + const subPalette = [...this.subPalettes[subPaletteIndex]]; return subPalette.map(color => new RGBA(constant(color.r), constant(color.g), constant(color.b), constant(color.a)) ); } - getLongestSubPalette () { + getSmallestSubPaletteIndex () { + const s = this.subPalettes; + for (let i = 0; i <= 20; i++) { + if (s[i]) { + return i; + } + } + } + + getLongestSubPaletteIndex () { const s = this.subPalettes; for (let i = 20; i >= 0; i--) { if (s[i]) { - return s[i]; + return i; } } } From 3192d7aab718e77e664e30e274b04e2e91c1d763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Arroyo=20Torrens?= Date: Thu, 19 Dec 2019 00:42:26 +0100 Subject: [PATCH 2/2] Add regression test --- .../cartocolor-subpalette/reference.png | Bin 0 -> 7627 bytes .../cartocolor-subpalette/scenario.js | 19 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/integration/render/scenarios/regression/cartocolor-subpalette/reference.png create mode 100644 test/integration/render/scenarios/regression/cartocolor-subpalette/scenario.js diff --git a/test/integration/render/scenarios/regression/cartocolor-subpalette/reference.png b/test/integration/render/scenarios/regression/cartocolor-subpalette/reference.png new file mode 100644 index 0000000000000000000000000000000000000000..0bb3efe724cc96717f241d961b0ecb845138f8d2 GIT binary patch literal 7627 zcmeHM_fu1Ax5i3QK@p^b0#ZT~A<~P8bO|K^q($H;ga9fKdO3Iyk0{|#0!meS3W+F1 z0t68u3L;WM6oiOKjr1hcz}a8f$=Mbjv%?}ko*a#ZX^i5p5EL`raX)6Ti(JWbERIT#4~UTo|* z8};JLaVwR#!k)*4M=SH2~;|Gkmtg=vphVf|FifH2>(YWtV)?2_}=+bA3Zo-oa;QG z&E6#|;uJZR{9X{o&OW=lJ6%$y5ARv)5c3!cstmbQeKyNUBn>1Y01{bCFAK7uwh-|S zO29{fz7AE*$Mk0ghlGT@jaW&5e~5IuEU#*d%e4oIt_$F4{F$c|v+b&0t^H;0EP^w3 zgJM0Lq^YN656Qs~9}cXa?#*WwAc+I#^S#SHeRAx3qJ8D5gH_3_ZT1g+w+2tz%E}A0 zoEcHZC~B@t3_d*5S4bNgDvwkuN0M4D>oLOdBSas3bHpvR!oHpj69e=*G9a~QcHJ1GJDP29X+LjuGB|EiBMgA zT>^JUXb$7*3YZdd}9fW$83|k&{9G^|H4Nj0~EW0xgiTpL^eBK4&v-05tnYAEQ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