8000 Fix setting tickwidth, tickcolor, ticklen, linecolor and possibly more attributes via template by archmoj · Pull Request #4904 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Fix setting tickwidth, tickcolor, ticklen, linecolor and possibly more attributes via template #4904

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 14 commits into from
Jun 17, 2020
Merged
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
Next Next commit
rename propOut to valOut
  • Loading branch information
archmoj committed Jun 7, 2020
commit 5c3be81ee1073d199b8399ff02ce8dd7ddf0a3fa
8 changes: 4 additions & 4 deletions src/lib/coerce.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,19 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
* returns false if there is no user input.
*/
exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
var propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);
var valOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);

var attr = attributes[attribute];
Copy link
Collaborator

Choose a reason for hiding this comment

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

    var attr = nestedProperty(attributes, attribute).get();

From coerce (line 364 above) - then the attr || {} below would be unnecessary - attr will always exist.

But I'm a little concerned whether the logic below (theDefault !== undefined && theDefault !== propOut) is robust - what if your template explicitly provides the same value as the default? If valIn does that, we return propOut, but given the logic here if the template does that we'll return false.

Could we instead make a base function like _coerce that returns both the value and where it came from (default, template, or container), then have exports.coerce just ignore that second part and return the value, whereas exports.coerce2 returns false if the value came from a default, otherwise the value?

Actually isn't there another already existing problem with coerce2? Looks like if you provide an invalid valIn, the prop will be set to the default value but it'll look like you set it explicitly. The base function approach would fix that problem too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexcjohnson thanks for the review.
Please find the commits below.

var theDefault = (dflt !== undefined) ? dflt : (attr || {}).dflt;
if(
theDefault !== undefined &&
theDefault !== propOut
theDefault !== valOut
) {
return propOut;
return valOut;
}

var valIn = nestedProperty(containerIn, attribute).get();
return (valIn !== undefined && valIn !== null) ? propOut : false;
return (valIn !== undefined && valIn !== null) ? valOut : false;
};

/*
Expand Down
0