Skip to content

Filter numbers during calc step #4063

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 3 commits into from
Jul 23, 2019
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Jul 19, 2019

Follow up of #4056 &
Fixes #4057.

Fix and apply Lib.mergeArrayCastPositive during calc step of various traces to ensure having positive inputs for size attributes.
@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Jul 19, 2019
@etpinard
Copy link
Contributor

@archmoj have you noticed any broken behaviour that can be traced back to not having positive sizes in the calc step?

@etpinard
Copy link
Contributor

I'm thinking if might be safer to move some of these checks to Drawing?

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2019

@archmoj have you noticed any broken behaviour that can be traced back to not having positive sizes in the calc step?

For example missing a circle in this scatter plot:
before
after

@archmoj
Copy link
Contributor Author

archmoj commented Jul 22, 2019

I'm thinking if might be safer to move some of these checks to Drawing?

I would say it is better if one checks the inputs as early as possible which is in this case the clac step.
But we may also add additional checks in Drawing to bypass values that make no sense.

@etpinard
Copy link
Contributor

For example missing a circle in this scatter plot:

Ok nice!

Now, what about the other calcdata field you're sanitizing:

  • funnelarea marker.line.width
  • scatter textfont.size
  • scatter marker.size
  • scatter marker.opacity

are they showing bugs currently on master?

I'm just trying to make sure we don't sanitize things twice.

src/lib/index.js Outdated
@@ -474,7 +474,7 @@ lib.mergeArray = function(traceAttr, cd, cdAttr, fn) {
lib.mergeArrayCastPositive = function(traceAttr, cd, cdAttr) {
return lib.mergeArray(traceAttr, cd, cdAttr, function(v) {
var w = +v;
return w > 0 ? w : 0;
return isNaN(w) ? NaN : w > 0 ? w : 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want isNumeric here. Have tried something like

'marker.line.width': [NaN, null, undefined, [], {}, 0]`

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works OK with those cases. Using isNumeric might be slow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried running benchmarks here? I doubt that isNumeric is that much slower than isNaN

Copy link
Contributor

Choose a reason for hiding this comment

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

Moreover, could we lock those cases down in a _module.calc test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests are added in 39b9840.

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2019

For example missing a circle in this scatter plot:

Ok nice!

Now, what about the other calcdata field you're sanitizing:

  • funnelarea marker.line.width
  • scatter textfont.size
  • scatter marker.size
  • scatter marker.opacity

are they showing bugs currently on master?

I'm just trying to make sure we don't sanitize things twice.

Also regarding funnelarea marker.line.width we have {
codepen before,
codepen after
}

}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
Copy link
Contributor

@etpinard etpinard Jul 23, 2019

Choose a reason for hiding this comment

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

Does having NaN in calcdata[i][j].mlw lead to console errors?

Copy link
Contributor

Choose a reason for hiding this comment

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

console errors e.g. when drawing a svg path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't notice any:
Scatter codepen
Bar codepen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But that's a very good question.
Now I am wondering if we should patch this test instead of the lib.mergeArrayCastPositive to accept 0 instead of NaN?
shouldCheckForNaN

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't notice any:

Ok, but looks like marker pts with mlw = NaN render as if they had mlw = 0, so I would prefer making NaN cast to 0 during calc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in f9db523 and fixed scattegeo test.

@etpinard
Copy link
Contributor

Nicely done @archmoj - thanks very much!!

@archmoj
Copy link
Contributor Author

archmoj commented Jul 23, 2019

@etpinard may I merge this PR?

@etpinard
Copy link
Contributor

Oops - I forgot the 💃

@etpinard
Copy link
Contributor

Yes, please merge this PR - thanks again!

@archmoj archmoj merged commit 96fe262 into master Jul 23, 2019
@archmoj archmoj deleted the reuse-merge-array-cast-positive branch July 23, 2019 21:43
@archmoj archmoj added this to the v1.49.0 milestone Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with marker.line.width arrays containing scientific number strings
2 participants