Skip to content

Fix interval constraint value normalization in contour traces - #8125

Open
Lexachoc wants to merge 3 commits into
plotly:mainfrom
Lexachoc:fix-constraint-contour
Open

Lexachoc wants to merge 3 commits into
plotly:mainfrom
Lexachoc:fix-constraint-contour

Conversation

@Lexachoc

Copy link
Copy Markdown
Contributor

Closes #8124

Fix incorrect normalization of contours.value for interval constraints.

This causes cases such as:

[]           -> [NaN, NaN]
[5]          -> [5, NaN]
[2,4,8,10]   -> [8,10]

This PR normalizes them as:

[]           -> [0,1]
[5]          -> [5,6]
[2,4,8,10]   -> [2,4]

The issue is in constraint_defaults.js, where the array length is checked against contours.length instead of contours.value.length, and arrays longer than two values are handled with slice(2) instead of slice(0, 2).

The relevant logic is this part:

} else if(contours.value.length > 2) {
contours.value = contours.value.slice(2);
} else if(contours.length === 0) {
contours.value = [0, 1];
} else if(contours.length < 2) {
zvalue = parseFloat(contours.value[0]);
contours.value = [zvalue, zvalue + 1];
} else {
contours.value = [
parseFloat(contours.value[0]),
parseFloat(contours.value[1])
];
}

This affects both contour and contourcarpet, since they share the same constraint defaults.

@camdecoster camdecoster self-assigned this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Incorrect interval constraint normalization for contours.value in contour traces

2 participants