Skip to content

Bar with non-numeric (x,y) items bug fix #1519

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 5 commits into from
Mar 30, 2017
Merged

Conversation

etpinard
Copy link
Contributor

Currently

var data = [{
  x: [5, NaN, 15, 20, NaN, 21],
  y: [20, NaN, 23, 25, NaN, 26],
  type: 'bar'
}];

Plotly.newPlot('myDiv', data);

generates

image

which is wrong.

With this PR, we get

image

- so that item with non-numeric (x,y) are excluded from
  the calcdata.
@etpinard etpinard added status: reviewable bug something broken labels Mar 27, 2017
@etpinard etpinard changed the title Bar with non-numeric (x.y) items bug fix Bar with non-numeric (x,y) items bug fix Mar 27, 2017
cd.push({ p: p, s: s });
} else {
cd.push({ p: p });
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. Do we need to merge in the base loop below 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.

Maybe? The behavior now is similar to how scatter fills in its arrayOk attributes. I can double check though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like scatter keeps a 1:1 mapping between calcdata points and the input arrays, filling in non-numerics with {x: false, y: false} - that's a good point about other arrayOK attributes, maybe it would be easier to keep that 1:1 mapping for bars too? Should be faster too, as we're not doing repeated .push, can set the size of cd at the start.

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 prefer removing non-numeric items in the calc step, so that we don't have to do that during the plot step (e.g. on zoom).

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, but then how do you want to solve this for bar color arrays etc? save the original index in each cd element? cd.push({p: p, s: s, i: i}) or something? That would need to be propagated all the way through to Lib.mergeArray which seems like a bit of a disaster.

Non-numerics should be regarded as an edge case, so the overhead of managing their objects shouldn't be seen as a concern, but you're right to worry about the overhead of checking each valid point. That said, this works for scatter which can have way more points than bars, so I think as long as we make this test super simple it shouldn't be a problem.

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 ok, you convinced me.

With commit 0144f06 bar calcdata has now a 1-1 correspondence with the bar (x,y) coordinates. Note that non-numeric bar items are cleaned up in bar/plot.js and makeCalcdata (called above the serieslen loop in bar/calc.js) sets non-numeric values to BADNUM.


This a pretty big change that might lead to regressions, so this PR will make be part of the next minor release v1.26.0 only.

- as per AJ's recommendation
- and skip over them in setPositions
- use BADNUM constant to skip over non-numeric items
  (recall: non-numeric values are set to BADNUM in makeCalcdata)
- see #1369
  for why that was needed.
@etpinard etpinard added this to the v1.26.0 milestone Mar 28, 2017
var cd = gd.calcdata;
assertPointField(cd, 'x', [[0, 1, 2, 3]]);
assertPointField(cd, 'y', [[1, NaN, NaN, 15]]);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we have a test with a bad x but good y for the same point?

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. Added in 6f0a95d

@alexcjohnson
Copy link
Collaborator

Nice - big improvement. At some point we may want to make sure we have tests that throw some garbage or partially garbage points into ALL our trace types - perhaps just add some junk to various image test mocks that shouldn't impact the images - but it's great that we've locked this down for bars now. 💃

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.

2 participants