Skip to content

- fix issue scattergl and fill to zero and undefined value #2965

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 11 additions & 4 deletions src/traces/scattergl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,17 @@ function plot(gd, subplot, cdata) {
var pos = [], srcPos = (lineOptions && lineOptions.positions) || stash.positions;

if(trace.fill === 'tozeroy') {
pos = [srcPos[0], 0];
pos = pos.concat(srcPos);
pos.push(srcPos[srcPos.length - 2]);
pos.push(0);
var firstdef = 1;
while(isNaN(srcPos[firstdef])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh hmm - this checks for invalid y, what about invalid x?

firstdef += 2;
}
var lastdef = srcPos.length - 1;
while(isNaN(srcPos[lastdef])) {
lastdef += -2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

-= 2?

}
pos = [ srcPos[firstdef - 1], 0 ];
pos = pos.concat(srcPos.slice(firstdef - 1, lastdef + 1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

🐎 so we don't need to slice unnecessarily, can we keep track of whether there actually were invalid points on either end?

pos = pos.concat([ srcPos[lastdef - 1], 0 ]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I notice the existing code didn't take advantage of this, but push is variadic:
pos.push(srcPos[lastdef - 1], 0);

}
else if(trace.fill === 'tozerox') {
pos = [0, srcPos[1]];
Expand Down
Binary file added test/image/baselines/fill_trace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions test/image/mocks/fill_trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"data": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind renaming this mock gl2d_fill_trace.json? We like to prefix gl-based mocks by either gl2d_ or gl3d_.

Would should probably write down in the CONTRIBUTING file at some point.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point for this PR - but rather than describing this in CONTRIBUTING.md how about we make the image test system support subfolders and give them a little more organization? It's getting impossible to find what you want in mocks and baselines...

{
"x": [
1,
2,
3,
4,
5
],
"y": [ null
,
100,
100,null
,null
],
"type": "scattergl",
"fill": "tozeroy",
"mode": "none",
"showlegend": false,
"fillcolor": "#90ff70",
"line": { "color": "#90ff70" }

},
{
"x": [
1,
2,
3,
4,
5
],
"y": [null
,null
,null
,
100,
100
],
"type": "scattergl",
"fill": "tozeroy",
"mode": "none",
"showlegend": false,
"fillcolor": "#f02f20",
"line": { "color": "#f02f20" }
}
],
"layout": {
"margin": {"l": 100, "r": 100, "t": 100, "b": 100},
"yaxis": { "title": "Y axis 2 ", "type": "linear", "rangemode": "tozero", "nticks": 3 }
}
}