Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/8203_fix.md
Original file line number Diff line number Diff line change
@@ -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)]
2 changes: 2 additions & 0 deletions src/traces/image/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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.',
Expand Down
4 changes: 2 additions & 2 deletions src/types/generated/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions test/jasmine/tests/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});
2 changes: 2 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down