Skip to content

Commit 60f71a1

Browse files
committed
fix 4047 display empty bars only when having line.width
1 parent 674f0b0 commit 60f71a1

File tree

3 files changed

+357
-6
lines changed

3 files changed

+357
-6
lines changed

src/traces/bar/plot.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
6969
var isWaterfall = (trace.type === 'waterfall');
7070
var isFunnel = (trace.type === 'funnel');
7171
var isBar = (trace.type === 'bar');
72-
var shouldDisplayZeros = isBar || isFunnel;
72+
var shouldDisplayZeros = (isBar || isFunnel);
7373

7474
var adjustPixel = 0;
7575
if(isWaterfall && trace.connector.visible && trace.connector.mode === 'between') {
@@ -102,12 +102,23 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts) {
102102
var y0 = xy[1][0];
103103
var y1 = xy[1][1];
104104

105-
var isBlank = di.isBlank = !(
106-
isNumeric(x0) && isNumeric(x1) &&
107-
isNumeric(y0) && isNumeric(y1) &&
108-
(x0 !== x1 || (shouldDisplayZeros && isHorizontal)) &&
109-
(y0 !== y1 || (shouldDisplayZeros && !isHorizontal))
105+
var isBlank = (
106+
x0 === x1 ||
107+
y0 === y1 ||
108+
!isNumeric(x0) ||
109+
!isNumeric(x1) ||
110+
!isNumeric(y0) ||
111+
!isNumeric(y1)
110112
);
113+
// display zeros if line.width > 0
114+
if(isBlank && shouldDisplayZeros) {
115+
if(isHorizontal ? x1 - x0 === 0 : y1 - y0 === 0) {
116+
if(di.mlw || trace.marker.line.width > 0) {
117+
isBlank = false;
118+
}
119+
}
120+
}
121+
di.isBlank = isBlank;
111122

112123
// in waterfall mode `between` we need to adjust bar end points to match the connector width
113124
if(adjustPixel) {
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
{
2+
"data": [
3+
{
4+
"type": "bar",
5+
"marker": {
6+
"line": {
7+
"width": 0
8+
}
9+
},
10+
"x": [
11+
"A",
12+
"b",
13+
"c",
14+
"d",
15+
"E"
16+
],
17+
"y": [
18+
0,
19+
0,
20+
null,
21+
null,
22+
1
23+
],
24+
"text": [
25+
0,
26+
0,
27+
null,
28+
null,
29+
1
30+
],
31+
"textposition": "auto",
32+
"insidetextanchor": "middle",
33+
"cliponaxis": false
34+
},
35+
{
36+
"type": "bar",
37+
"marker": {
38+
"line": {
39+
"width": [10, 0, 10, 0, 10]
40+
}
41+
},
42+
"x": [
43+
"A",
44+
"b",
45+
"c",
46+
"d",
47+
"E"
48+
],
49+
"y": [
50+
0,
51+
0,
52+
null,
53+
null,
54+
1
55+
],
56+
"text": [
57+
0,
58+
0,
59+
null,
60+
null,
61+
1
62+
],
63+
"textposition": "auto",
64+
"insidetextanchor": "middle",
65+
"cliponaxis": false
66+
},
67+
{
68+
"type": "bar",
69+
"marker": {
70+
"line": {
71+
"width": 0
72+
}
73+
},
74+
"x": [
75+
"A",
76+
"b",
77+
"c",
78+
"d",
79+
"E"
80+
],
81+
"y": [
82+
0,
83+
0,
84+
null,
85+
null,
86+
1
87+
],
88+
"text": [
89+
0,
90+
0,
91+
null,
92+
null,
93+
1
94+
],
95+
"textposition": "auto",
96+
"insidetextanchor": "middle",
97+
"cliponaxis": false,
98+
"xaxis": "x2",
99+
"yaxis": "y2"
100+
},
101+
{
102+
"type": "bar",
103+
"marker": {
104+
"line": {
105+
"width": [10, 0, 10, 0, 10]
106+
}
107+
},
108+
"x": [
109+
"A",
110+
"b",
111+
"c",
112+
"d",
113+
"E"
114+
],
115+
"y": [
116+
0,
117+
0,
118+
null,
119+
null,
120+
1
121+
],
122+
"text": [
123+
0,
124+
0,
125+
null,
126+
null,
127+
1
128+
],
129+
"textposition": "auto",
130+
"insidetextanchor": "middle",
131+
"cliponaxis": false,
132+
"xaxis": "x2",
133+
"yaxis": "y2"
134+
},
135+
{
136+
"type": "bar",
137+
"marker": {
138+
"line": {
139+
"width": 0
140+
}
141+
},
142+
"orientation": "h",
143+
"y": [
144+
"A",
145+
"b",
146+
"c",
147+
"d",
148+
"E"
149+
],
150+
"x": [
151+
0,
152+
0,
153+
null,
154+
null,
155+
1
156+
],
157+
"text": [
158+
0,
159+
0,
160+
null,
161+
null,
162+
1
163+
],
164+
"textposition": "auto",
165+
"insidetextanchor": "middle",
166+
"cliponaxis": false,
167+
"xaxis": "x3",
168+
"yaxis": "y3"
169+
},
170+
{
171+
"type": "bar",
172+
"marker": {
173+
"line": {
174+
"width": [10, 0, 10, 0, 10]
175+
}
176+
},
177+
"orientation": "h",
178+
"y": [
179+
"A",
180+
"b",
181+
"c",
182+
"d",
183+
"E"
184+
],
185+
"x": [
186+
0,
187+
0,
188+
null,
189+
null,
190+
1
191+
],
192+
"text": [
193+
0,
194+
0,
195+
null,
196+
null,
197+
1
198+
],
199+
"textposition": "auto",
200+
"insidetextanchor": "middle",
201+
"cliponaxis": false,
202+
"xaxis": "x3",
203+
"yaxis": "y3"
204+
},
205+
{
206+
"type": "bar",
207+
"marker": {
208+
"line": {
209+
"width": 0
210+
}
211+
},
212+
"orientation": "h",
213+
"y": [
214+
"A",
215+
"b",
216+
"c",
217+
"d",
218+
"E"
219+
],
220+
"x": [
221+
0,
222+
0,
223+
null,
224+
null,
225+
1
226+
],
227+
"text": [
228+
0,
229+
0,
230+
null,
231+
null,
232+
1
233+
],
234+
"textposition": "auto",
235+
"insidetextanchor": "middle",
236+
"cliponaxis": false,
237+
"xaxis": "x4",
238+
"yaxis": "y4"
239+
},
240+
{
241+
"type": "bar",
242+
"marker": {
243+
"line": {
244+
"width": [10, 0, 10, 0, 10]
245+
}
246+
},
247+
"orientation": "h",
248+
"y": [
249+
"A",
250+
"b",
251+
"c",
252+
"d",
253+
"E"
254+
],
255+
"x": [
256+
0,
257+
0,
258+
null,
259+
null,
260+
1
261+
],
262+
"text": [
263+
0,
264+
0,
265+
null,
266+
null,
267+
1
268+
],
269+
"textposition": "auto",
270+
"insidetextanchor": "middle",
271+
"cliponaxis": false,
272+
"xaxis": "x4",
273+
"yaxis": "y4"
274+
}
275+
],
276+
"layout": {
277+
"showlegend": true,
278+
"width": 800,
279+
"height": 800,
280+
"dragmode": "pan",
281+
"xaxis": {
282+
"domain": [
283+
0,
284+
0.48
285+
]
286+
},
287+
"xaxis2": {
288+
"autorange": "reversed",
289+
"anchor": "y2",
290+
"domain": [
291+
0.52,
292+
1
293+
]
294+
},
295+
"xaxis3": {
296+
"anchor": "y3",
297+
"domain": [
298+
0,
299+
0.48
300+
]
301+
},
302+
"xaxis4": {
303+
"autorange": "reversed",
304+
"anchor": "y4",
305+
"domain": [
306+
0.52,
307+
1
308+
]
309+
},
310+
"yaxis": {
311+
"domain": [
312+
0,
313+
0.48
314+
]
315+
},
316+
"yaxis2": {
317+
"autorange": "reversed",
318+
"anchor": "x2",
319+
"domain": [
320+
0.52,
321+
1
322+
]
323+
},
324+
"yaxis3": {
325+
"anchor": "x3",
326+
"domain": [
327+
0.52,
328+
1
329+
]
330+
},
331+
"yaxis4": {
332+
"autorange": "reversed",
333+
"anchor": "x4",
334+
"domain": [
335+
0,
336+
0.48
337+
]
338+
}
339+
}
340+
}

0 commit comments

Comments
 (0)