8000 Allow null and NaN in text templates by alexcjohnson · Pull Request #7360 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Allow null and NaN in text templates #7360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue 8000 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 5 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
nestedProperty: support retainNull for array get all
  • Loading branch information
alexcjohnson committed Feb 17, 2025
commit a348c245a69405dbe70866d1be98596e7a95940d
2 changes: 1 addition & 1 deletion src/lib/nested_property.js
Copy link
Contributor

Choose a reason for hiding this comment

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

@alexcjohnson I'm curious why line 90 doesn't need to be

out[j] = npGet(curCont[j], parts.slice(i + 1))(retainNull);

i.e. passing the retainNull value to the recursive function call.

Not important or a blocker, just idle curiousity!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great catch @emilykl! I'm not sure we actually use array index -1 for "get properties inside each array element" anywhere (I suppose users could access this via Plotly.restyle or Plotly.relayout but that way they don't have access to nestedProperty directly), and I certainly didn't need it for my use case, but since it's there we should support it -> a348c24

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function npGet(cont, parts) {
allSame = true;
out = [];
for(j = 0; j < curCont.length; j++) {
out[j] = npGet(curCont[j], parts.slice(i + 1))();
out[j] = npGet(curCont[j], parts.slice(i + 1))(retainNull);
if(out[j] !== out[0]) allSame = false;
}
return allSame ? out[0] : out;
Expand Down
7 changes: 4 additions & 3 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,12 @@ describe('Test lib.js:', function() {
});

it('should access properties of objects in an array with index -1', function() {
var obj = {arr: [{a: 1}, {a: 2}, {b: 3}]};
var obj = {arr: [{a: 1}, {a: null}, {b: 3}]};
var prop = np(obj, 'arr[-1].a');

expect(prop.get()).toEqual([1, 2, undefined]);
expect(obj).toEqual({arr: [{a: 1}, {a: 2}, {b: 3}]});
expect(prop.get()).toEqual([1, undefined, undefined]);
expect(prop.get(true)).toEqual([1, null, undefined]);
expect(obj).toEqual({arr: [{a: 1}, {a: null}, {b: 3}]});

prop.set(5);
expect(prop.get()).toBe(5);
Expand Down
0