Skip to content

Commit 1edd000

Browse files
committed
adding test for coerce colorlist, cleanup
1 parent a69bbf9 commit 1edd000

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/lib/coerce.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ exports.valObjectMeta = {
152152
function isColor(color) {
153153
return tinycolor(color).isValid();
154154
}
155-
if(!Array.isArray(v)) propOut.set(dflt);
155+
if(!Array.isArray(v) || !v.length) propOut.set(dflt);
156156
else if(v.every(isColor)) propOut.set(v);
157157
else propOut.set(dflt);
158158
}

test/image/mocks/layout-colorway.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
{
99
"labels": ["a","b","c","c","c","a","d","e","f","f","g","h"],
1010
"type": "pie",
11-
"domain": {"x": [0, 0.4]},
12-
"xaxis": "x2",
13-
"yaxis": "y2"
11+
"domain": {"x": [0, 0.4]}
1412
}
1513
],
1614
"layout": {
@@ -24,9 +22,6 @@
2422
],
2523
"xaxis": {
2624
"domain": [0.4, 1]
27-
},
28-
"yaxis": {
29-
"anchor": "y2"
3025
}
3126
}
3227
}

test/jasmine/tests/lib_test.js

+9
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,15 @@ describe('Test lib.js:', function() {
10731073
});
10741074
});
10751075

1076+
it('should work for valType \'colorlist\' where', function() {
1077+
var shouldPass = [['red'],['#ffffff'],['rgba(0,0,0,1)'], ['red', 'green', 'blue']],
1078+
shouldFail = [1, null, undefined, {}, [], 'red', ['red', null]];
1079+
1080+
assert(shouldPass, shouldFail, {
1081+
valType: 'colorlist'
1082+
});
1083+
});
1084+
10761085
it('should work for valType \'colorscale\' where', function() {
10771086
var good = [ [0, 'red'], [1, 'blue'] ],
10781087
bad = [ [0.1, 'red'], [1, 'blue'] ],

0 commit comments

Comments
 (0)