Skip to content

Commit 30f3ddc

Browse files
authored
Merge pull request plotly#4714 from plotly/bar-with-base-tozero
Skip zeroline when negative sizes are present on positive base and vice versa
2 parents d50cb75 + 158a59c commit 30f3ddc

11 files changed

+759
-8
lines changed

src/traces/bar/cross_trace_calc.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function setBaseAndTop(sa, sieve) {
501501
var calcTrace = calcTraces[i];
502502
var fullTrace = calcTrace[0].trace;
503503
var pts = [];
504-
var allBaseAboveZero = true;
504+
var tozero = false;
505505

506506
for(var j = 0; j < calcTrace.length; j++) {
507507
var bar = calcTrace[j];
@@ -512,13 +512,13 @@ function setBaseAndTop(sa, sieve) {
512512
pts.push(top);
513513
if(bar.hasB) pts.push(base);
514514

515-
if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
516-
allBaseAboveZero = false;
515+
if(!bar.hasB || !bar.b) {
516+
tozero = true;
517517
}
518518
}
519519

520520
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
521-
tozero: !allBaseAboveZero,
521+
tozero: tozero,
522522
padded: true
523523
});
524524
}
@@ -667,7 +667,7 @@ function normalizeBars(sa, sieve, opts) {
667667
var calcTrace = calcTraces[i];
668668
var fullTrace = calcTrace[0].trace;
669669
var pts = [];
670-
var allBaseAboveZero = true;
670+
var tozero = false;
671671
var padded = false;
672672

673673
for(var j = 0; j < calcTrace.length; j++) {
@@ -690,14 +690,14 @@ function normalizeBars(sa, sieve, opts) {
690690
padded = padded || needsPadding(base);
691691
}
692692

693-
if(!bar.hasB || !(bar.b > 0 && bar.s > 0)) {
694-
allBaseAboveZero = false;
693+
if(!bar.hasB || !bar.b) {
694+
tozero = true;
695695
}
696696
}
697697
}
698698

699699
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
700-
tozero: !allBaseAboveZero,
700+
tozero: tozero,
701701
padded: padded
702702
});
703703
}
Loading
Loading
Loading
16.9 KB
Loading
-55 Bytes
Loading
-98 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"data": [
3+
{
4+
"xaxis": "x",
5+
"yaxis": "y",
6+
"type": "bar",
7+
"orientation": "h",
8+
"y": [
9+
"A",
10+
"B",
11+
"C"
12+
],
13+
"x": [
14+
1,
15+
-1,
16+
1
17+
],
18+
"text": [
19+
"+1",
20+
"-1",
21+
"+1"
22+
],
23+
"textposition": "inside",
24+
"insidetextanchor": "middle",
25+
"base": 10
26+
},
27+
{
28+
"xaxis": "x2",
29+
"yaxis": "y2",
30+
"type": "bar",
31+
"x": [
32+
"E",
33+
"F",
34+
"G"
35+
],
36+
"y": [
37+
1,
38+
-1,
39+
1
40+
],
41+
"text": [
42+
"+1",
43+
"-1",
44+
"+1"
45+
],
46+
"textposition": "inside",
47+
"insidetextanchor": "middle",
48+
"base": 10
49+
},
50+
{
51+
"xaxis": "x3",
52+
"yaxis": "y3",
53+
"type": "waterfall",
54+
"x": [
55+
"E",
56+
"F",
57+
"G"
58+
],
59+
"y": [
60+
1,
61+
-2,
62+
1
63+
],
64+
"text": [
65+
"+1",
66+
"-2",
67+
"+1"
68+
],
69+
"textposition": "inside",
70+
"insidetextanchor": "middle",
71+
"base": 10
72+
},
73+
{
74+
"xaxis": "x4",
75+
"yaxis": "y4",
76+
"type": "waterfall",
77+
"orientation": "h",
78+
"y": [
79+
"A",
80+
"B",
81+
"C"
82+
],
83+
"x": [
84+
1,
85+
-2,
86+
1
87+
],
88+
"text": [
89+
"+1",
90+
"-2",
91+
"+1"
92+
],
93+
"textposition": "inside",
94+
"insidetextanchor": "middle",
95+
"base": 10
96+
}
97+
],
98+
"layout": {
99+
"width": 400,
100+
"height": 400,
101+
"template": {
102+
"layout": {
103+
"showlegend": false,
104+
"title": {
105+
"text": "non-zero autorange with<br>base and negative size"
106+
},
107+
"xaxis": {
108+
"domain": [
109+
0,
110+
0.45
111+
]
112+
},
113+
"yaxis": {
114+
"domain": [
115+
0,
116+
0.45
117+
]
118+
},
119+
"xaxis2": {
120+
"anchor": "y2",
121+
"domain": [
122+
0.55,
123+
1
124+
]
125+
},
126+
"yaxis2": {
127+
"anchor": "x2",
128+
"domain": [
129+
0.55,
130+
1
131+
]
132+
},
133+
"xaxis3": {
134+
"anchor": "y3",
135+
"domain": [
136+
0,
137+
0.45
138+
]
139+
},
140+
"yaxis3": {
141+
"anchor": "x3",
142+
"domain": [
143+
0.55,
144+
1
145+
]
146+
},
147+
"xaxis4": {
148+
"anchor": "y4",
149+
"domain": [
150+
0.55,
151+
1
152+
]
153+
},
154+
"yaxis4": {
155+
"anchor": "x4",
156+
"domain": [
157+
0,
158+
0.45
159+
]
160+
}
161+
}
162+
}
163+
}
164+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"data": [
3+
{
4+
"xaxis": "x",
5+
"yaxis": "y",
6+
"type": "bar",
7+
"orientation": "h",
8+
"y": [
9+
"A",
10+
"B",
11+
"C"
12+
],
13+
"x": [
14+
1,
15+
-1,
16+
1
17+
],
18+
"text": [
19+
"+1",
20+
"-1",
21+
"+1"
22+
],
23+
"textposition": "inside",
24+
"insidetextanchor": "middle",
25+
"base": [-10, -10, -10]
26+
},
27+
{
28+
"xaxis": "x2",
29+
"yaxis": "y2",
30+
"type": "bar",
31+
"x": [
32+
"E",
33+
"F",
34+
"G"
35+
],
36+
"y": [
37+
1,
38+
-1,
39+
1
40+
],
41+
"text": [
42+
"+1",
43+
"-1",
44+
"+1"
45+
],
46+
"textposition": "inside",
47+
"insidetextanchor": "middle",
48+
"base": [-10, -10, -10]
49+
},
50+
{
51+
"xaxis": "x3",
52+
"yaxis": "y3",
53+
"type": "waterfall",
54+
"x": [
55+
"E",
56+
"F",
57+
"G"
58+
],
59+
"y": [
60+
1,
61+
-2,
62+
1
63+
],
64+
"text": [
65+
"+1",
66+
"-2",
67+
"+1"
68+
],
69+
"textposition": "inside",
70+
"insidetextanchor": "middle",
71+
"base": -10
72+
},
73+
{
74+
"xaxis": "x4",
75+
"yaxis": "y4",
76+
"type": "waterfall",
77+
"orientation": "h",
78+
"y": [
79+
"A",
80+
"B",
81+
"C"
82+
],
83+
"x": [
84+
1,
85+
-2,
86+
1
87+
],
88+
"text": [
89+
"+1",
90+
"-2",
91+
"+1"
92+
],
93+
"textposition": "inside",
94+
"insidetextanchor": "middle",
95+
"base": -10
96+
}
97+
],
98+
"layout": {
99+
"width": 400,
100+
"height": 400,
101+
"template": {
102+
"layout": {
103+
"showlegend": false,
104+
"title": {
105+
"text": "non-zero autorange with<br>base and negative size"
106+
},
107+
"xaxis": {
108+
"domain": [
109+
0,
110+
0.45
111+
]
112+
},
113+
"yaxis": {
114+
"domain": [
115+
0,
116+
0.45
117+
]
118+
},
119+
"xaxis2": {
120+
"anchor": "y2",
121+
"domain": [
122+
0.55,
123+
1
124+
]
125+
},
126+
"yaxis2": {
127+
"anchor": "x2",
128+
"domain": [
129+
0.55,
130+
1
131+
]
132+
},
133+
"xaxis3": {
134+
"anchor": "y3",
135+
"domain": [
136+
0,
137+
0.45
138+
]
139+
},
140+
"yaxis3": {
141+
"anchor": "x3",
142+
"domain": [
143+
0.55,
144+
1
145+
]
146+
},
147+
"xaxis4": {
148+
"anchor": "y4",
149+
"domain": [
150+
0.55,
151+
1
152+
]
153+
},
154+
"yaxis4": {
155+
"anchor": "x4",
156+
"domain": [
157+
0,
158+
0.45
159+
]
160+
}
161+
}
162+
}
163+
}
164+
}

0 commit comments

Comments
 (0)