From 4dffd77d6ea5aa8d29ee76fd23b559a9b7e7da25 Mon Sep 17 00:00:00 2001 From: ruslan hryhoriev Date: Tue, 24 Nov 2026 17:16:13 +0000 Subject: [PATCH 1/3] Accept 3-element zmin and zmax for rgb and hsl image traces The rgb and hsl colormodels have 3 components, but the schema declared zmin and zmax as exactly 4 elements. Plotly.validate and the validators generated from the schema rejected valid 3-element arrays. Setting freeLength accepts 3 and 4 elements. --- draftlogs/XXXX_fix.md | 1 + src/traces/image/attributes.ts | 2 ++ src/types/generated/schema.d.ts | 4 +-- test/jasmine/tests/validate_test.js | 55 +++++++++++++++++++++++++++++ test/plot-schema.json | 2 ++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 draftlogs/XXXX_fix.md diff --git a/draftlogs/XXXX_fix.md b/draftlogs/XXXX_fix.md new file mode 100644 index 00000000000..f21c43392d1 --- /dev/null +++ b/draftlogs/XXXX_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", From 039ce48d0f04db0ca60f81c6cf6da09159849053 Mon Sep 17 00:00:00 2001 From: ruslan hryhoriev Date: Thu, 26 Nov 2026 12:10:02 +0000 Subject: [PATCH 2/3] Add draftlog for PR 8203 --- draftlogs/{XXXX_fix.md => 8203_fix.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename draftlogs/{XXXX_fix.md => 8203_fix.md} (100%) diff --git a/draftlogs/XXXX_fix.md b/draftlogs/8203_fix.md similarity index 100% rename from draftlogs/XXXX_fix.md rename to draftlogs/8203_fix.md From 7e9572148b9d6cb88ebcedd6d9e2a23218ffdeda Mon Sep 17 00:00:00 2001 From: ruslan hryhoriev Date: Sun, 29 Nov 2026 16:25:41 +0000 Subject: [PATCH 3/3] Fill PR number in draftlog --- draftlogs/8203_fix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draftlogs/8203_fix.md b/draftlogs/8203_fix.md index f21c43392d1..c55938468c8 100644 --- a/draftlogs/8203_fix.md +++ b/draftlogs/8203_fix.md @@ -1 +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)] + - Fix `zmin` and `zmax` of `image` traces so that `Plotly.validate` accepts 3-element arrays for the `rgb` and `hsl` colormodels [[#8203](https://github.com/plotly/plotly.js/pull/8203)]