From 786309b3fb7c3a02ba055fdcefa541e7d220f3e7 Mon Sep 17 00:00:00 2001 From: Ya-Fan Chen <20377719+Lexachoc@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:49:01 +0200 Subject: [PATCH 1/6] Fix interval constraint value normalization in contour traces --- src/traces/contour/constraint_defaults.js | 6 ++-- test/jasmine/tests/contour_test.js | 39 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/traces/contour/constraint_defaults.js b/src/traces/contour/constraint_defaults.js index 2b0178d940f..280bef22dd6 100644 --- a/src/traces/contour/constraint_defaults.js +++ b/src/traces/contour/constraint_defaults.js @@ -57,10 +57,10 @@ function handleConstraintValueDefaults(coerce, contours) { contours.value = [zvalue, zvalue + 1]; } } else if(contours.value.length > 2) { - contours.value = contours.value.slice(2); - } else if(contours.length === 0) { + contours.value = contours.value.slice(0, 2); + } else if(contours.value.length === 0) { contours.value = [0, 1]; - } else if(contours.length < 2) { + } else if(contours.value.length < 2) { zvalue = parseFloat(contours.value[0]); contours.value = [zvalue, zvalue + 1]; } else { diff --git a/test/jasmine/tests/contour_test.js b/test/jasmine/tests/contour_test.js index ae098a30702..5a842fce097 100644 --- a/test/jasmine/tests/contour_test.js +++ b/test/jasmine/tests/contour_test.js @@ -115,6 +115,45 @@ describe('contour defaults', function() { expect(traceOut.xcalendar).toBe('coptic'); expect(traceOut.ycalendar).toBe('ethiopian'); }); + + it('should coerce constraint interval values to two numbers', function() { + var specs = [ + { + value: [], + expected: [0, 1] + }, + { + value: [5], + expected: [5, 6] + }, + { + value: [10, 20], + expected: [10, 20] + }, + { + value: [10, 20, 30], + expected: [10, 20] + } + ]; + + specs.forEach(function(spec) { + traceIn = { + type: 'contour', + z: [[0, 1], [2, 3]], + contours: { + type: 'constraint', + operation: '[]', + value: spec.value + } + }; + + traceOut = {}; + + supplyDefaults(traceIn, traceOut, defaultColor, layout); + + expect(traceOut.contours.value).toEqual(spec.expected); + }); + }); }); describe('contour makeColorMap', function() { From 13379ae63a1388309c48c6c2c793f1136b82ef50 Mon Sep 17 00:00:00 2001 From: Ya-Fan Chen <20377719+Lexachoc@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:57:16 +0200 Subject: [PATCH 2/6] add draftlog --- draftlogs/8125.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/8125.md diff --git a/draftlogs/8125.md b/draftlogs/8125.md new file mode 100644 index 00000000000..19f43ac6ccf --- /dev/null +++ b/draftlogs/8125.md @@ -0,0 +1 @@ + - Fix normalization of `contours.value` for interval constraints in `contour` and `contourcarpet` [[#8125](https://github.com/plotly/plotly.js/pull/8125)] \ No newline at end of file From e26ff9c0d0797526e40e5daa085f12d04d5cdf7c Mon Sep 17 00:00:00 2001 From: Ya-Fan Chen <20377719+Lexachoc@users.noreply.github.com> Date: Thu, 15 Oct 2026 17:59:20 +0200 Subject: [PATCH 3/6] Rename draftlogs/8125.md to draftlogs/8125_fix.md --- draftlogs/{8125.md => 8125_fix.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename draftlogs/{8125.md => 8125_fix.md} (82%) diff --git a/draftlogs/8125.md b/draftlogs/8125_fix.md similarity index 82% rename from draftlogs/8125.md rename to draftlogs/8125_fix.md index 19f43ac6ccf..ed4aa06379b 100644 --- a/draftlogs/8125.md +++ b/draftlogs/8125_fix.md @@ -1 +1 @@ - - Fix normalization of `contours.value` for interval constraints in `contour` and `contourcarpet` [[#8125](https://github.com/plotly/plotly.js/pull/8125)] \ No newline at end of file + - Fix normalization of `contours.value` for interval constraints in `contour` and `contourcarpet` [[#8125](https://github.com/plotly/plotly.js/pull/8125)] From 69fb48d669b3b9a8cfba6d656af4f24dc5ba67b3 Mon Sep 17 00:00:00 2001 From: Ya-Fan Chen <20377719+Lexachoc@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:07:48 +0000 Subject: [PATCH 4/6] refactor: improve handling of contour value defaults --- src/traces/contour/constraint_defaults.js | 27 ++++++++++++++--------- test/jasmine/tests/contour_test.js | 8 +++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/traces/contour/constraint_defaults.js b/src/traces/contour/constraint_defaults.js index 280bef22dd6..a55590e9aa7 100644 --- a/src/traces/contour/constraint_defaults.js +++ b/src/traces/contour/constraint_defaults.js @@ -56,18 +56,23 @@ function handleConstraintValueDefaults(coerce, contours) { zvalue = parseFloat(contours.value); contours.value = [zvalue, zvalue + 1]; } - } else if(contours.value.length > 2) { - contours.value = contours.value.slice(0, 2); - } else if(contours.value.length === 0) { - contours.value = [0, 1]; - } else if(contours.value.length < 2) { - zvalue = parseFloat(contours.value[0]); - contours.value = [zvalue, zvalue + 1]; + } else { - contours.value = [ - parseFloat(contours.value[0]), - parseFloat(contours.value[1]) - ]; + switch(contours.value.length) { + case 0: + contours.value = [0, 1]; + break; + case 1: + zvalue = parseFloat(contours.value[0]); + contours.value = [zvalue, zvalue + 1]; + break; + default: + // Keep only the first two values + contours.value = [ + parseFloat(contours.value[0]), + parseFloat(contours.value[1]) + ]; + } } } else { // Requires a single scalar: diff --git a/test/jasmine/tests/contour_test.js b/test/jasmine/tests/contour_test.js index 5a842fce097..41884c2b7ed 100644 --- a/test/jasmine/tests/contour_test.js +++ b/test/jasmine/tests/contour_test.js @@ -127,12 +127,12 @@ describe('contour defaults', function() { expected: [5, 6] }, { - value: [10, 20], - expected: [10, 20] + value: ['10.5', '20.25', '30.75'], + expected: [10.5, 20.25] }, { - value: [10, 20, 30], - expected: [10, 20] + value: [1.25, 2.75], + expected: [1.25, 2.75] } ]; From 74d2732fc205b991621d07e1fb444f8279852534 Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Thu, 19 Nov 2026 11:08:59 -0700 Subject: [PATCH 5/6] Add Float64Array test case --- test/jasmine/tests/contour_test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/jasmine/tests/contour_test.js b/test/jasmine/tests/contour_test.js index 41884c2b7ed..4b45ba2b01d 100644 --- a/test/jasmine/tests/contour_test.js +++ b/test/jasmine/tests/contour_test.js @@ -133,6 +133,10 @@ describe('contour defaults', function() { { value: [1.25, 2.75], expected: [1.25, 2.75] + }, + { + value: new Float64Array([1.5, 2.5, 3.5]), + expected: [1.5, 2.5] } ]; From 8f39a949ede1548855ef30c5b9c8a97d2d1685d6 Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Thu, 19 Nov 2026 11:10:34 -0700 Subject: [PATCH 6/6] Update draftlog --- draftlogs/8125_fix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draftlogs/8125_fix.md b/draftlogs/8125_fix.md index ed4aa06379b..96233a48310 100644 --- a/draftlogs/8125_fix.md +++ b/draftlogs/8125_fix.md @@ -1 +1 @@ - - Fix normalization of `contours.value` for interval constraints in `contour` and `contourcarpet` [[#8125](https://github.com/plotly/plotly.js/pull/8125)] + - Fix normalization of `contours.value` for interval constraints in `contour` and `contourcarpet` [[#8125](https://github.com/plotly/plotly.js/pull/8125)], with thanks to @Lexachoc for the contribution!