From bca79237f2712b59bf9be8133c0ed22f32fa56ce Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 14:50:30 -0500 Subject: [PATCH 01/10] Add faster color parsing --- src/lib/gl_format_color.js | 8 ++++---- src/lib/str2rgbarray.js | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index ac3f08aeb3e..5af6cd8850f 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -9,8 +9,8 @@ 'use strict'; -var tinycolor = require('tinycolor2'); var isNumeric = require('fast-isnumeric'); +var rgba = require('color-rgba'); var Colorscale = require('../components/colorscale'); var colorDflt = require('../components/color/attributes').defaultLine; @@ -20,13 +20,13 @@ var str2RgbaArray = require('./str2rgbarray'); var opacityDflt = 1; function calculateColor(colorIn, opacityIn) { - var colorOut = str2RgbaArray(colorIn); + var colorOut = colorIn; colorOut[3] *= opacityIn; return colorOut; } function validateColor(colorIn) { - return tinycolor(colorIn).isValid() ? colorIn : colorDflt; + return rgba(colorIn) || rgba(colorDflt); } function validateOpacity(opacityIn) { @@ -73,7 +73,7 @@ function formatColor(containerIn, opacityIn, len) { colorOut[i] = calculateColor(colori, opacityi); } } - else colorOut = calculateColor(colorIn, opacityIn); + else colorOut = calculateColor(rgba(colorIn), opacityIn); return colorOut; } diff --git a/src/lib/str2rgbarray.js b/src/lib/str2rgbarray.js index 0dd3c027fce..ca642cb17a3 100644 --- a/src/lib/str2rgbarray.js +++ b/src/lib/str2rgbarray.js @@ -9,12 +9,11 @@ 'use strict'; -var tinycolor = require('tinycolor2'); -var arrtools = require('arraytools'); +var rgba = require('color-rgba'); function str2RgbaArray(color) { - color = tinycolor(color); - return arrtools.str2RgbaArray(color.toRgbString()); + return rgba(color) || [0, 0, 0, 1]; } module.exports = str2RgbaArray; + From a15a0078eec0e513f02d9f2cd4b4c80f0232cdad Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 14:53:15 -0500 Subject: [PATCH 02/10] Lintify --- src/lib/gl_format_color.js | 2 -- src/lib/str2rgbarray.js | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index 5af6cd8850f..53e9439b3ed 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -15,8 +15,6 @@ var rgba = require('color-rgba'); var Colorscale = require('../components/colorscale'); var colorDflt = require('../components/color/attributes').defaultLine; -var str2RgbaArray = require('./str2rgbarray'); - var opacityDflt = 1; function calculateColor(colorIn, opacityIn) { diff --git a/src/lib/str2rgbarray.js b/src/lib/str2rgbarray.js index ca642cb17a3..4f32f630ca3 100644 --- a/src/lib/str2rgbarray.js +++ b/src/lib/str2rgbarray.js @@ -12,8 +12,7 @@ var rgba = require('color-rgba'); function str2RgbaArray(color) { - return rgba(color) || [0, 0, 0, 1]; + return rgba(color) || [0, 0, 0, 1]; } module.exports = str2RgbaArray; - From 9c5683d279397a16533a70b3d069cb946197fa03 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 15:31:34 -0500 Subject: [PATCH 03/10] Add dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 38afbf7bf86..ed7e39981a0 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "3d-view": "^2.0.0", "alpha-shape": "^1.0.0", "arraytools": "^1.0.0", + "color-rgba": "^1.0.3", "convex-hull": "^1.0.3", "country-regex": "^1.1.0", "d3": "^3.5.12", From 5aa4d57c581b059040abd9a97cf1bd9bcedaaf1d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 15:49:32 -0500 Subject: [PATCH 04/10] Fix possible edge cases --- src/lib/gl_format_color.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index 53e9439b3ed..a09ba49dbd6 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -15,6 +15,7 @@ var rgba = require('color-rgba'); var Colorscale = require('../components/colorscale'); var colorDflt = require('../components/color/attributes').defaultLine; +var colorDfltRgba = rgba(colorDflt); var opacityDflt = 1; function calculateColor(colorIn, opacityIn) { @@ -24,7 +25,7 @@ function calculateColor(colorIn, opacityIn) { } function validateColor(colorIn) { - return rgba(colorIn) || rgba(colorDflt); + return rgba(colorIn) || colorDfltRgba; } function validateOpacity(opacityIn) { @@ -48,11 +49,15 @@ function formatColor(containerIn, opacityIn, len) { ) ); } - else sclFunc = validateColor; + else { + sclFunc = function (c) { + return c; + }; + } if(isArrayColorIn) { getColor = function(c, i) { - return c[i] === undefined ? colorDflt : sclFunc(c[i]); + return c[i] === undefined ? colorDfltRgba : rgba(sclFunc(c[i])); }; } else getColor = validateColor; From 39e2d6c659c18d20ca5b76ed413203dee0cb1b70 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 15:50:39 -0500 Subject: [PATCH 05/10] Fix lint --- src/lib/gl_format_color.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index a09ba49dbd6..d64dea4a452 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -50,7 +50,7 @@ function formatColor(containerIn, opacityIn, len) { ); } else { - sclFunc = function (c) { + sclFunc = function(c) { return c; }; } From feda0d55f8b8e6630ea152c0f1e035d04d0a4895 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 16:56:32 -0500 Subject: [PATCH 06/10] Ignore numeric color format --- src/lib/gl_format_color.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index d64dea4a452..8e067e66467 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -25,7 +25,7 @@ function calculateColor(colorIn, opacityIn) { } function validateColor(colorIn) { - return rgba(colorIn) || colorDfltRgba; + return isNumeric(colorIn) ? colorDfltRgba : (rgba(colorIn) || colorDfltRgba); } function validateOpacity(opacityIn) { @@ -50,9 +50,7 @@ function formatColor(containerIn, opacityIn, len) { ); } else { - sclFunc = function(c) { - return c; - }; + sclFunc = validateColor; } if(isArrayColorIn) { From a68373122050d34374fbadd285be40d3f58673e0 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 3 Mar 2017 16:58:07 -0500 Subject: [PATCH 07/10] Force version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed7e39981a0..eef90d23af4 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "3d-view": "^2.0.0", "alpha-shape": "^1.0.0", "arraytools": "^1.0.0", - "color-rgba": "^1.0.3", + "color-rgba": "^1.0.4", "convex-hull": "^1.0.3", "country-regex": "^1.1.0", "d3": "^3.5.12", From 22eacec5a6aec3cb3294e93daabb0abaf45107f1 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 4 Mar 2017 10:34:24 -0500 Subject: [PATCH 08/10] Update color-rgba use --- src/lib/gl_format_color.js | 6 +++++- src/lib/str2rgbarray.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index 8e067e66467..e1c7cb28faa 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -25,7 +25,11 @@ function calculateColor(colorIn, opacityIn) { } function validateColor(colorIn) { - return isNumeric(colorIn) ? colorDfltRgba : (rgba(colorIn) || colorDfltRgba); + if (isNumeric(colorIn)) return colorDfltRgba; + + var colorOut = rgba(colorIn); + + return colorOut.length ? colorOut : colorDfltRgba; } function validateOpacity(opacityIn) { diff --git a/src/lib/str2rgbarray.js b/src/lib/str2rgbarray.js index 4f32f630ca3..6f30820fe5d 100644 --- a/src/lib/str2rgbarray.js +++ b/src/lib/str2rgbarray.js @@ -12,7 +12,8 @@ var rgba = require('color-rgba'); function str2RgbaArray(color) { - return rgba(color) || [0, 0, 0, 1]; + var colorOut = rgba(color); + return colorOut.length ? colorOut : [0, 0, 0, 1]; } module.exports = str2RgbaArray; From 5c1537945aae21d0b76a4a12554912982fbe72b2 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 6 Mar 2017 12:36:20 -0500 Subject: [PATCH 09/10] Lintify --- src/lib/gl_format_color.js | 28 ++++++++++++++-------------- src/lib/str2rgbarray.js | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index e1c7cb28faa..a0b6078a579 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -19,33 +19,33 @@ var colorDfltRgba = rgba(colorDflt); var opacityDflt = 1; function calculateColor(colorIn, opacityIn) { - var colorOut = colorIn; - colorOut[3] *= opacityIn; - return colorOut; +var colorOut = colorIn; +colorOut[3] *= opacityIn; +return colorOut; } function validateColor(colorIn) { - if (isNumeric(colorIn)) return colorDfltRgba; +if(isNumeric(colorIn)) return colorDfltRgba; - var colorOut = rgba(colorIn); +var colorOut = rgba(colorIn); - return colorOut.length ? colorOut : colorDfltRgba; +return colorOut.length ? colorOut : colorDfltRgba; } function validateOpacity(opacityIn) { - return isNumeric(opacityIn) ? opacityIn : opacityDflt; +return isNumeric(opacityIn) ? opacityIn : opacityDflt; } function formatColor(containerIn, opacityIn, len) { - var colorIn = containerIn.color, - isArrayColorIn = Array.isArray(colorIn), - isArrayOpacityIn = Array.isArray(opacityIn), - colorOut = []; +var colorIn = containerIn.color, + isArrayColorIn = Array.isArray(colorIn), + isArrayOpacityIn = Array.isArray(opacityIn), + colorOut = []; - var sclFunc, getColor, getOpacity, colori, opacityi; +var sclFunc, getColor, getOpacity, colori, opacityi; - if(containerIn.colorscale !== undefined) { - sclFunc = Colorscale.makeColorScaleFunc( +if(containerIn.colorscale !== undefined) { + sclFunc = Colorscale.makeColorScaleFunc( Colorscale.extractScale( containerIn.colorscale, containerIn.cmin, diff --git a/src/lib/str2rgbarray.js b/src/lib/str2rgbarray.js index 6f30820fe5d..750bdea7ab8 100644 --- a/src/lib/str2rgbarray.js +++ b/src/lib/str2rgbarray.js @@ -12,7 +12,7 @@ var rgba = require('color-rgba'); function str2RgbaArray(color) { - var colorOut = rgba(color); + var colorOut = rgba(color); return colorOut.length ? colorOut : [0, 0, 0, 1]; } From cdad90ffd183b0b4d035dd7584e67f9f646f8b2c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 14 Mar 2017 00:03:28 -0400 Subject: [PATCH 10/10] Fix linting --- src/lib/gl_format_color.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib/gl_format_color.js b/src/lib/gl_format_color.js index a0b6078a579..83052c63360 100644 --- a/src/lib/gl_format_color.js +++ b/src/lib/gl_format_color.js @@ -19,33 +19,33 @@ var colorDfltRgba = rgba(colorDflt); var opacityDflt = 1; function calculateColor(colorIn, opacityIn) { -var colorOut = colorIn; -colorOut[3] *= opacityIn; -return colorOut; + var colorOut = colorIn; + colorOut[3] *= opacityIn; + return colorOut; } function validateColor(colorIn) { -if(isNumeric(colorIn)) return colorDfltRgba; + if(isNumeric(colorIn)) return colorDfltRgba; -var colorOut = rgba(colorIn); + var colorOut = rgba(colorIn); -return colorOut.length ? colorOut : colorDfltRgba; + return colorOut.length ? colorOut : colorDfltRgba; } function validateOpacity(opacityIn) { -return isNumeric(opacityIn) ? opacityIn : opacityDflt; + return isNumeric(opacityIn) ? opacityIn : opacityDflt; } function formatColor(containerIn, opacityIn, len) { -var colorIn = containerIn.color, - isArrayColorIn = Array.isArray(colorIn), - isArrayOpacityIn = Array.isArray(opacityIn), - colorOut = []; + var colorIn = containerIn.color, + isArrayColorIn = Array.isArray(colorIn), + isArrayOpacityIn = Array.isArray(opacityIn), + colorOut = []; -var sclFunc, getColor, getOpacity, colori, opacityi; + var sclFunc, getColor, getOpacity, colori, opacityi; -if(containerIn.colorscale !== undefined) { - sclFunc = Colorscale.makeColorScaleFunc( + if(containerIn.colorscale !== undefined) { + sclFunc = Colorscale.makeColorScaleFunc( Colorscale.extractScale( containerIn.colorscale, containerIn.cmin,