Skip to content

Fast color parsing #1443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/lib/gl_format_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@

'use strict';

var tinycolor = require('tinycolor2');
var isNumeric = require('fast-isnumeric');
var rgba = require('color-rgba');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add color-rgba to the package.json and push again?

I'll be interesting to see if the tests pass on CI ...


var Colorscale = require('../components/colorscale');
var colorDflt = require('../components/color/attributes').defaultLine;

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) {
Expand Down Expand Up @@ -73,7 +71,7 @@ function formatColor(containerIn, opacityIn, len) {
colorOut[i] = calculateColor(colori, opacityi);
}
}
else colorOut = calculateColor(colorIn, opacityIn);
else colorOut = calculateColor(rgba(colorIn), opacityIn);

return colorOut;
}
Expand Down
6 changes: 2 additions & 4 deletions src/lib/str2rgbarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

'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;