Skip to content

Commit bca7923

Browse files
committed
Add faster color parsing
1 parent 8a310b3 commit bca7923

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/lib/gl_format_color.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
'use strict';
1111

12-
var tinycolor = require('tinycolor2');
1312
var isNumeric = require('fast-isnumeric');
13+
var rgba = require('color-rgba');
1414

1515
var Colorscale = require('../components/colorscale');
1616
var colorDflt = require('../components/color/attributes').defaultLine;
@@ -20,13 +20,13 @@ var str2RgbaArray = require('./str2rgbarray');
2020
var opacityDflt = 1;
2121

2222
function calculateColor(colorIn, opacityIn) {
23-
var colorOut = str2RgbaArray(colorIn);
23+
var colorOut = colorIn;
2424
colorOut[3] *= opacityIn;
2525
return colorOut;
2626
}
2727

2828
function validateColor(colorIn) {
29-
return tinycolor(colorIn).isValid() ? colorIn : colorDflt;
29+
return rgba(colorIn) || rgba(colorDflt);
3030
}
3131

3232
function validateOpacity(opacityIn) {
@@ -73,7 +73,7 @@ function formatColor(containerIn, opacityIn, len) {
7373
colorOut[i] = calculateColor(colori, opacityi);
7474
}
7575
}
76-
else colorOut = calculateColor(colorIn, opacityIn);
76+
else colorOut = calculateColor(rgba(colorIn), opacityIn);
7777

7878
return colorOut;
7979
}

src/lib/str2rgbarray.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010
'use strict';
1111

12-
var tinycolor = require('tinycolor2');
13-
var arrtools = require('arraytools');
12+
var rgba = require('color-rgba');
1413

1514
function str2RgbaArray(color) {
16-
color = tinycolor(color);
17-
return arrtools.str2RgbaArray(color.toRgbString());
15+
return rgba(color) || [0, 0, 0, 1];
1816
}
1917

2018
module.exports = str2RgbaArray;
19+

0 commit comments

Comments
 (0)