diff --git a/draftlogs/8203_fix.md b/draftlogs/8203_fix.md new file mode 100644 index 00000000000..f21c43392d1 --- /dev/null +++ b/draftlogs/8203_fix.md @@ -0,0 +1 @@ + - Fix `zmin` and `zmax` of `image` traces so that `Plotly.validate` accepts 3-element arrays for the `rgb` and `hsl` colormodels [[#XXXX](https://github.com/plotly/plotly.js/pull/XXXX)] diff --git a/src/traces/image/attributes.ts b/src/traces/image/attributes.ts index 80779d449e1..777908253f4 100644 --- a/src/traces/image/attributes.ts +++ b/src/traces/image/attributes.ts @@ -58,6 +58,7 @@ const attributes = { { valType: 'number', editType: 'calc' }, { valType: 'number', editType: 'calc' } ], + freeLength: true, editType: 'calc', description: [ 'Array defining the lower bound for each color component.', @@ -73,6 +74,7 @@ const attributes = { { valType: 'number', editType: 'calc' }, { valType: 'number', editType: 'calc' } ], + freeLength: true, editType: 'calc', description: [ 'Array defining the higher bound for each color component.', diff --git a/src/types/generated/schema.d.ts b/src/types/generated/schema.d.ts index 853b8c815f9..78f5f62b2e4 100644 --- a/src/types/generated/schema.d.ts +++ b/src/types/generated/schema.d.ts @@ -5211,9 +5211,9 @@ export interface ImageData { /** A 2-dimensional array in which each element is an array of 3 or 4 numbers representing a color. */ z?: Datum[] | Datum[][] | TypedArray; /** Array defining the higher bound for each color component. Note that the default value will depend on the colormodel. For the `rgb` colormodel, it is [255, 255, 255]. For the `rgba` colormodel, it is [255, 255, 255, 1]. For the `rgba256` colormodel, it is [255, 255, 255, 255]. For the `hsl` colormodel, it is [360, 100, 100]. For the `hsla` colormodel, it is [360, 100, 100, 1]. */ - zmax?: [number, number, number, number]; + zmax?: number[]; /** Array defining the lower bound for each color component. Note that the default value will depend on the colormodel. For the `rgb` colormodel, it is [0, 0, 0]. For the `rgba` colormodel, it is [0, 0, 0, 0]. For the `rgba256` colormodel, it is [0, 0, 0, 0]. For the `hsl` colormodel, it is [0, 0, 0]. For the `hsla` colormodel, it is [0, 0, 0, 0]. */ - zmin?: [number, number, number, number]; + zmin?: number[]; /** * Sets the layer on which this trace is displayed, relative to other SVG traces on the same subplot. SVG traces with higher `zorder` appear in front of those with lower `zorder`. * @default 0 diff --git a/test/jasmine/tests/validate_test.js b/test/jasmine/tests/validate_test.js index b8577e07efe..bd983f65e34 100644 --- a/test/jasmine/tests/validate_test.js +++ b/test/jasmine/tests/validate_test.js @@ -820,4 +820,59 @@ describe('Plotly.validate', function () { ]); expect(out).toBeUndefined(); }); + + it('should accept zmin and zmax with as many elements as the image colormodel', function () { + var tests = [ + ['rgb', [10, 10, 10], [100, 100, 100]], + ['hsl', [0, 0, 0], [360, 100, 100]], + ['rgba', [0, 0, 0, 0], [255, 255, 255, 1]], + ['rgba256', [0, 0, 0, 0], [255, 255, 255, 255]], + ['hsla', [0, 0, 0, 0], [360, 100, 100, 1]] + ]; + + tests.forEach(function (test) { + var out = Plotly.validate([ + { + type: 'image', + z: [[[1, 1, 1, 1]]], + colormodel: test[0], + zmin: test[1], + zmax: test[2] + } + ]); + expect(out).toBeUndefined('colormodel ' + test[0]); + }); + }); + + it('should reject invalid image zmin and zmax', function () { + var out = Plotly.validate([ + { + type: 'image', + z: [[[1, 1, 1]]], + colormodel: 'rgb', + zmin: [10, 'a', 10], + zmax: [100, 100, 100, 1, 1] + } + ]); + + expect(out.length).toBe(2); + assertErrorContent( + out[0], + 'value', + 'data', + 0, + ['zmin', 1], + 'zmin[1]', + 'In data trace 0, key zmin[1] is set to an invalid value (a)' + ); + assertErrorContent( + out[1], + 'unused', + 'data', + 0, + ['zmax', 4], + 'zmax[4]', + 'In data trace 0, key zmax[4] did not get coerced' + ); + }); }); diff --git a/test/plot-schema.json b/test/plot-schema.json index 7ab1ae48d50..cdffb6b2a3a 100644 --- a/test/plot-schema.json +++ b/test/plot-schema.json @@ -41854,6 +41854,7 @@ "zmax": { "description": "Array defining the higher bound for each color component. Note that the default value will depend on the colormodel. For the `rgb` colormodel, it is [255, 255, 255]. For the `rgba` colormodel, it is [255, 255, 255, 1]. For the `rgba256` colormodel, it is [255, 255, 255, 255]. For the `hsl` colormodel, it is [360, 100, 100]. For the `hsla` colormodel, it is [360, 100, 100, 1].", "editType": "calc", + "freeLength": true, "items": [ { "editType": "calc", @@ -41877,6 +41878,7 @@ "zmin": { "description": "Array defining the lower bound for each color component. Note that the default value will depend on the colormodel. For the `rgb` colormodel, it is [0, 0, 0]. For the `rgba` colormodel, it is [0, 0, 0, 0]. For the `rgba256` colormodel, it is [0, 0, 0, 0]. For the `hsl` colormodel, it is [0, 0, 0]. For the `hsla` colormodel, it is [0, 0, 0, 0].", "editType": "calc", + "freeLength": true, "items": [ { "editType": "calc",