Skip to content

Accept 3-element zmin and zmax for rgb and hsl image traces - #8203

Open
RuslanGrigoryev wants to merge 4 commits into
plotly:mainfrom
RuslanGrigoryev:fix-8182-image-zmin-zmax-3-elements
Open

RuslanGrigoryev wants to merge 4 commits into
plotly:mainfrom
RuslanGrigoryev:fix-8182-image-zmin-zmax-3-elements

Conversation

@RuslanGrigoryev

Copy link
Copy Markdown

Fixes #8182

Set freeLength: true on zmin and zmax of the image trace. The rgb and hsl colormodels have 3 components, so Plotly.validate and the plotly.py validators now accept 3-element arrays.

Why the change is correct

The schema declared zmin and zmax as info_array with 4 fixed items. Lib.validate rejects an array when its length differs from items.length and freeLength is not set. src/traces/image/constants.ts defines 3-element ranges for rgb and hsl. A validator cannot read the colormodel of the trace, so it must accept 3 or 4 elements.

Trace defaults already handle short arrays. image/defaults.js fills missing elements from the colormodel defaults, so rendering does not change.

Trade-offs

  • freeLength also accepts arrays with 0 to 2 elements, as it does for other info_array attributes
  • Plotly.validate reports a value with more than 4 elements as unused, and a non-number as value. The new test covers the two cases.
  • I kept the existing items array, so the generated type changes from a 4-tuple to number[]. A single-object items would change the schema more.
  • The Lib.validate call on a value with more than 4 elements throws, because items[4] is undefined. The same shape exists for parcoords constraintrange. Plotly.validate does not reach that call. I did not change it.

Tests

  • Jasmine suite: validate (test/jasmine/tests/validate_test.js), two new tests
  • Local runs: npm run lint, npm run typecheck, npm run test-syntax, npm run schema-typegen-diff-check
  • I did not run the karma suite. It needs a browser.
  • No pixels change. No mock or baseline changes.

Generated files

npm run schema regenerated test/plot-schema.json and src/types/generated/schema.d.ts.

Maintainer note

KoolADE85 approved a plotly.js fix in plotly/plotly.py#5869. The issue asks which form of items the maintainers prefer. Please confirm before merge.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant