Skip to content

Commit cc5ce23

Browse files
committed
display bars with height zero not waterfalls not funnels
1 parent d6da48e commit cc5ce23

File tree

5 files changed

+194
-8
lines changed

5 files changed

+194
-8
lines changed

src/traces/bar/plot.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer, opts) {
6767
var bartraces = Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {
6868
var plotGroup = d3.select(this);
6969
var trace = cd[0].trace;
70+
var isWaterfall = (trace.type === 'waterfall');
71+
var isFunnel = (trace.type === 'funnel');
72+
var isBar = !(isWaterfall || isFunnel);
7073

7174
var adjustPixel = 0;
72-
if(trace.type === 'waterfall' && trace.connector.visible && trace.connector.mode === 'between') {
75+
if(isWaterfall && trace.connector.visible && trace.connector.mode === 'between') {
7376
adjustPixel = trace.connector.line.width / 2;
7477
}
7578

@@ -101,10 +104,11 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer, opts) {
101104
var y0 = xy[1][0];
102105
var y1 = xy[1][1];
103106

104-
var isBlank = di.isBlank = (
105-
!isNumeric(x0) || !isNumeric(x1) ||
106-
!isNumeric(y0) || !isNumeric(y1) ||
107-
x0 === x1 || y0 === y1
107+
var isBlank = di.isBlank = !(
108+
isNumeric(x0) && isNumeric(x1) &&
109+
isNumeric(y0) && isNumeric(y1) &&
110+
(x0 !== x1 || (isBar && isHorizontal)) &&
111+
(y0 !== y1 || (isBar && !isHorizontal))
108112
);
109113

110114
// in waterfall mode `between` we need to adjust bar end points to match the connector width
@@ -231,7 +235,7 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
231235

232236
if(!text ||
233237
textPosition === 'none' ||
234-
(calcBar.isBlank && (
238+
((calcBar.isBlank || x0 === x1 || y0 === y1) && (
235239
textPosition === 'auto' ||
236240
textPosition === 'inside'))) {
237241
bar.select('text').remove();
@@ -513,6 +517,8 @@ function getTextPosition(trace, index) {
513517
function calcTextinfo(calcTrace, index, xa, ya) {
514518
var trace = calcTrace[0].trace;
515519
var isHorizontal = (trace.orientation === 'h');
520+
var isWaterfall = (trace.type === 'waterfall');
521+
var isFunnel = (trace.type === 'funnel');
516522

517523
function formatLabel(u) {
518524
var pAxis = isHorizontal ? ya : xa;
@@ -542,7 +548,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
542548
if(tx === 0 || tx) text.push(tx);
543549
}
544550

545-
if(trace.type === 'waterfall') {
551+
if(isWaterfall) {
546552
var delta = +cdi.rawS || cdi.s;
547553
var final = cdi.v;
548554
var initial = final - delta;
@@ -552,7 +558,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
552558
if(hasFlag('final')) text.push(formatNumber(final));
553559
}
554560

555-
if(trace.type === 'funnel') {
561+
if(isFunnel) {
556562
if(hasFlag('value')) text.push(formatNumber(cdi.s));
557563

558564
var nPercent = 0;
Loading
35.7 KB
Loading
56 Bytes
Loading
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"data": [
3+
{
4+
"type": "bar",
5+
"marker": {
6+
"line": {
7+
"width": 10
8+
}
9+
},
10+
"x": [
11+
"A",
12+
"B",
13+
"C"
14+
],
15+
"y": [
16+
0,
17+
null,
18+
1
19+
],
20+
"text": [
21+
0,
22+
null,
23+
1
24+
],
25+
"textposition": "auto",
26+
"insidetextanchor": "middle",
27+
"cliponaxis": false
28+
},
29+
{
30+
"type": "bar",
31+
"marker": {
32+
"line": {
33+
"width": 10
34+
}
35+
},
36+
"x": [
37+
"A",
38+
"B",
39+
"C"
40+
],
41+
"y": [
42+
0,
43+
null,
44+
1
45+
],
46+
"text": [
47+
0,
48+
null,
49+
1
50+
],
51+
"textposition": "auto",
52+
"insidetextanchor": "middle",
53+
"cliponaxis": false,
54+
"xaxis": "x2",
55+
"yaxis": "y2"
56+
},
57+
{
58+
"type": "bar",
59+
"marker": {
60+
"line": {
61+
"width": 10
62+
}
63+
},
64+
"orientation": "h",
65+
"x": [
66+
0,
67+
null,
68+
1
69+
],
70+
"y": [
71+
"A",
72+
"B",
73+
"C"
74+
],
75+
"text": [
76+
0,
77+
null,
78+
1
79+
],
80+
"textposition": "auto",
81+
"insidetextanchor": "middle",
82+
"cliponaxis": false,
83+
"xaxis": "x3",
84+
"yaxis": "y3"
85+
},
86+
{
87+
"type": "bar",
88+
"marker": {
89+
"line": {
90+
"width": 10
91+
}
92+
},
93+
"orientation": "h",
94+
"x": [
95+
0,
96+
null,
97+
1
98+
],
99+
"y": [
100+
"A",
101+
"B",
102+
"C"
103+
],
104+
"text": [
105+
0,
106+
null,
107+
1
108+
],
109+
"textposition": "auto",
110+
"insidetextanchor": "middle",
111+
"cliponaxis": false,
112+
"xaxis": "x4",
113+
"yaxis": "y4"
114+
}
115+
],
116+
"layout": {
117+
"showlegend": true,
118+
"width": 800,
119+
"height": 800,
120+
"dragmode": "pan",
121+
"xaxis": {
122+
"domain": [
123+
0,
124+
0.48
125+
]
126+
},
127+
"xaxis2": {
128+
"autorange": "reversed",
129+
"anchor": "y2",
130+
"domain": [
131+
0.52,
132+
1
133+
]
134+
},
135+
"xaxis3": {
136+
"anchor": "y3",
137+
"domain": [
138+
0,
139+
0.48
140+
]
141+
},
142+
"xaxis4": {
143+
"autorange": "reversed",
144+
"anchor": "y4",
145+
"domain": [
146+
0.52,
147+
1
148+
]
149+
},
150+
"yaxis": {
151+
"domain": [
152+
0,
153+
0.48
154+
]
155+
},
156+
"yaxis2": {
157+
"autorange": "reversed",
158+
"anchor": "x2",
159+
"domain": [
160+
0.52,
161+
1
162+
]
163+
},
164+
"yaxis3": {
165+
"anchor": "x3",
166+
"domain": [
167+
0.52,
168+
1
169+
]
170+
},
171+
"yaxis4": {
172+
"autorange": "reversed",
173+
"anchor": "x4",
174+
"domain": [
175+
0,
176+
0.48
177+
]
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)