9
9
10
10
'use strict' ;
11
11
12
- var tinycolor = require ( 'tinycolor2' ) ;
13
12
var isNumeric = require ( 'fast-isnumeric' ) ;
13
+ var rgba = require ( 'color-rgba' ) ;
14
14
15
15
var Colorscale = require ( '../components/colorscale' ) ;
16
16
var colorDflt = require ( '../components/color/attributes' ) . defaultLine ;
17
17
18
- var str2RgbaArray = require ( './str2rgbarray' ) ;
19
-
18
+ var colorDfltRgba = rgba ( colorDflt ) ;
20
19
var opacityDflt = 1 ;
21
20
22
21
function calculateColor ( colorIn , opacityIn ) {
23
- var colorOut = str2RgbaArray ( colorIn ) ;
22
+ var colorOut = colorIn ;
24
23
colorOut [ 3 ] *= opacityIn ;
25
24
return colorOut ;
26
25
}
27
26
28
27
function validateColor ( colorIn ) {
29
- return tinycolor ( colorIn ) . isValid ( ) ? colorIn : colorDflt ;
28
+ if ( isNumeric ( colorIn ) ) return colorDfltRgba ;
29
+
30
+ var colorOut = rgba ( colorIn ) ;
31
+
32
+ return colorOut . length ? colorOut : colorDfltRgba ;
30
33
}
31
34
32
35
function validateOpacity ( opacityIn ) {
@@ -50,11 +53,13 @@ function formatColor(containerIn, opacityIn, len) {
50
53
)
51
54
) ;
52
55
}
53
- else sclFunc = validateColor ;
56
+ else {
57
+ sclFunc = validateColor ;
58
+ }
54
59
55
60
if ( isArrayColorIn ) {
56
61
getColor = function ( c , i ) {
57
- return c [ i ] === undefined ? colorDflt : sclFunc ( c [ i ] ) ;
62
+ return c [ i ] === undefined ? colorDfltRgba : rgba ( sclFunc ( c [ i ] ) ) ;
58
63
} ;
59
64
}
60
65
else getColor = validateColor ;
@@ -73,7 +78,7 @@ function formatColor(containerIn, opacityIn, len) {
73
78
colorOut [ i ] = calculateColor ( colori , opacityi ) ;
74
79
}
75
80
}
76
- else colorOut = calculateColor ( colorIn , opacityIn ) ;
81
+ else colorOut = calculateColor ( rgba ( colorIn ) , opacityIn ) ;
77
82
78
83
return colorOut ;
79
84
}
0 commit comments