Skip to content

Make frame with nulls clear items & array containers #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 11, 2016
67 changes: 67 additions & 0 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,71 @@ describe('Test Plots', function() {
expect(gd._transitioning).toBeUndefined();
});
});

describe('extendObjectWithContainers', function() {

function assert(dest, src, expected) {
Plots.extendObjectWithContainers(dest, src, ['container']);
expect(dest).toEqual(expected);
}

it('extend each container items', function() {
var dest = {
container: [
{ text: '1', x: 1, y: 1 },
{ text: '2', x: 2, y: 2 }
]
};

var src = {
container: [
{ text: '1-new' },
{ text: '2-new' }
]
};

var expected = {
container: [
{ text: '1-new', x: 1, y: 1 },
{ text: '2-new', x: 2, y: 2 }
]
};

assert(dest, src, expected);
});

it('clears container items when applying null src items', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This also looks like what I'd expect. Am I correct in understanding that [undefined, undefined] would skip applying any changes?

var dest = {
container: [
{ text: '1', x: 1, y: 1 },
{ text: '2', x: 2, y: 2 }
]
};

var src = {
container: [null, null]
};

var expected = {
container: [null, null]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

N.B. I changed the behavior here as discussed in #1118 (comment) - see 36859f1

In brief, frames with array containers set to null extend the state with null. It is now up to the subsequent supplyDefaults calls to coerced those null items into {}, as in regular Plotly.plot calls.

};

assert(dest, src, expected);
});

it('clears container applying null src', function() {
var dest = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. Ditto on behavior of undefined?

container: [
{ text: '1', x: 1, y: 1 },
{ text: '2', x: 2, y: 2 }
]
};

var src = { container: null };

var expected = { container: null };

assert(dest, src, expected);
});
});
});