Skip to content

Skip zeroline when negative sizes are present on positive base and vice versa #4714

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 6 commits into from
Apr 6, 2020
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
2 changes: 1 addition & 1 deletion src/traces/bar/cross_trace_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function setBaseAndTop(sa, sieve) {
pts.push(top);
if(bar.hasB) pts.push(base);

if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
if(!bar.hasB || !(bar.b > 0 && bar.b + bar.s > 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Per #4701 (comment) I'm really curious if there's anything wrong with just:
if (!bar.hasB || !bar.b)
or maybe even
if (!bar.b)
depending on what these values are.

If you negate all base and size values - so all top and bottom values are <0 - we should also not draw the axis to zero. And if there are already values on both sides of zero, the tozero: true flag is irrelevant.

Also: there's similar logic down in normalizeBars ~line 700 that probably needs updating as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now added logic & tests to handle negative case similar to the positive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per #4701 (comment) I'm really curious if there's anything wrong with just:
if (!bar.hasB || !bar.b)
or maybe even
if (!bar.b)
depending on what these values are.

That would change bar_attrs_overlay & bar_attrs_group baselines.

allBaseAboveZero = false;
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
164 changes: 164 additions & 0 deletions test/image/mocks/bar-like_traces_no-tozero.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"data": [
{
"xaxis": "x",
"yaxis": "y",
"type": "bar",
"orientation": "h",
"y": [
"A",
"B",
"C"
],
"x": [
1,
-1,
1
],
"text": [
"+1",
"-1",
"+1"
],
"textposition": "inside",
"insidetextanchor": "middle",
"base": 10
},
{
"xaxis": "x2",
"yaxis": "y2",
"type": "bar",
"x": [
"E",
"F",
"G"
],
"y": [
1,
-1,
1
],
"text": [
"+1",
"-1",
"+1"
],
"textposition": "inside",
"insidetextanchor": "middle",
"base": 10
},
{
"xaxis": "x3",
"yaxis": "y3",
"type": "waterfall",
"x": [
"E",
"F",
"G"
],
"y": [
1,
-2,
1
],
"text": [
"+1",
"-2",
"+1"
],
"textposition": "inside",
"insidetextanchor": "middle",
"base": 10
},
{
"xaxis": "x4",
"yaxis": "y4",
"type": "waterfall",
"orientation": "h",
"y": [
"A",
"B",
"C"
],
"x": [
1,
-2,
1
],
"text": [
"+1",
"-2",
"+1"
],
"textposition": "inside",
"insidetextanchor": "middle",
"base": 10
}
],
"layout": {
"width": 400,
"height": 400,
"template": {
"layout": {
"showlegend": false,
"title": {
"text": "non-zero autorange with<br>base and negative size"
},
"xaxis": {
"domain": [
0,
0.45
]
},
"yaxis": {
"domain": [
0,
0.45
]
},
"xaxis2": {
"anchor": "y2",
"domain": [
0.55,
1
]
},
"yaxis2": {
"anchor": "x2",
"domain": [
0.55,
1
]
},
"xaxis3": {
"anchor": "y3",
"domain": [
0,
0.45
]
},
"yaxis3": {
"anchor": "x3",
"domain": [
0.55,
1
]
},
"xaxis4": {
"anchor": "y4",
"domain": [
0.55,
1
]
},
"yaxis4": {
"anchor": "x4",
"domain": [
0,
0.45
]
}
}
}
}
}