Skip to content
Merged
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/8125_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 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!
27 changes: 16 additions & 11 deletions src/traces/contour/constraint_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(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])
];
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:
Expand Down
43 changes: 43 additions & 0 deletions test/jasmine/tests/contour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,49 @@ describe('contour defaults', function() {
expect(traceOut.xcalendar).toBe('coptic');
expect(traceOut.ycalendar).toBe('ethiopian');
});

it('should coerce constraint interval values to two numbers', function() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a case that checks a float array?

var specs = [
{
value: [],
expected: [0, 1]
},
{
value: [5],
expected: [5, 6]
},
{
value: ['10.5', '20.25', '30.75'],
expected: [10.5, 20.25]
},
{
value: [1.25, 2.75],
expected: [1.25, 2.75]
},
{
value: new Float64Array([1.5, 2.5, 3.5]),
expected: [1.5, 2.5]
}
];

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() {
Expand Down
Loading