Skip to content

Commit 674f00f

Browse files
authored
Merge pull request #1420 from plotly/validate-colorscale-fix
Fix `Plotly.validate` for colorscale attributes
2 parents 34eb326 + 217403f commit 674f00f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/plot_api/validate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ function crawl(objIn, objOut, schema, list, base, path) {
164164
valOut = objOut[k];
165165

166166
var nestedSchema = getNestedSchema(schema, k),
167-
isInfoArray = (nestedSchema || {}).valType === 'info_array';
167+
isInfoArray = (nestedSchema || {}).valType === 'info_array',
168+
isColorscale = (nestedSchema || {}).valType === 'colorscale';
168169

169170
if(!isInSchema(schema, k)) {
170171
list.push(format('schema', base, p));
@@ -209,7 +210,7 @@ function crawl(objIn, objOut, schema, list, base, path) {
209210
else if(!isPlainObject(valIn) && isPlainObject(valOut)) {
210211
list.push(format('object', base, p, valIn));
211212
}
212-
else if(!isArray(valIn) && isArray(valOut) && !isInfoArray) {
213+
else if(!isArray(valIn) && isArray(valOut) && !isInfoArray && !isColorscale) {
213214
list.push(format('array', base, p, valIn));
214215
}
215216
else if(!(k in objOut)) {

test/jasmine/tests/validate_test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ describe('Plotly.validate', function() {
148148
);
149149
});
150150

151+
it('should work with colorscale attributes', function() {
152+
var out = Plotly.validate([{
153+
x: [1, 2, 3],
154+
marker: {
155+
color: [20, 10, 30],
156+
colorscale: 'Reds'
157+
}
158+
}, {
159+
x: [1, 2, 3],
160+
marker: {
161+
color: [20, 10, 30],
162+
colorscale: 'not-gonna-work'
163+
}
164+
}, {
165+
x: [1, 2, 3],
166+
marker: {
167+
color: [20, 10, 30],
168+
colorscale: [[0, 'red'], [1, 'blue']]
169+
}
170+
}]);
171+
172+
expect(out.length).toEqual(1);
173+
assertErrorContent(
174+
out[0], 'value', 'data', 1, ['marker', 'colorscale'], 'marker.colorscale',
175+
'In data trace 1, key marker.colorscale is set to an invalid value (not-gonna-work)'
176+
);
177+
});
178+
151179
it('should work with isLinkedToArray attributes', function() {
152180
var out = Plotly.validate([], {
153181
annotations: [{

0 commit comments

Comments
 (0)