diff --git a/draftlogs/8125_fix.md b/draftlogs/8125_fix.md new file mode 100644 index 00000000000..ed4aa06379b --- /dev/null +++ b/draftlogs/8125_fix.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)] 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() {