@@ -49,15 +49,23 @@ function getXY(di, xa, ya, isHorizontal) {
49
49
return isHorizontal ? [ s , p ] : [ p , s ] ;
50
50
}
51
51
52
- module . exports = function plot ( gd , plotinfo , cdModule , traceLayer ) {
52
+ module . exports = function plot ( gd , plotinfo , cdModule , traceLayer , opts ) {
53
53
var xa = plotinfo . xaxis ;
54
54
var ya = plotinfo . yaxis ;
55
55
var fullLayout = gd . _fullLayout ;
56
56
57
+ if ( ! opts ) {
58
+ opts = {
59
+ mode : fullLayout . barmode ,
60
+ norm : fullLayout . barmode ,
61
+ gap : fullLayout . bargap ,
62
+ groupgap : fullLayout . bargroupgap
63
+ } ;
64
+ }
65
+
57
66
var bartraces = Lib . makeTraceGroups ( traceLayer , cdModule , 'trace bars' ) . each ( function ( cd ) {
58
67
var plotGroup = d3 . select ( this ) ;
59
- var cd0 = cd [ 0 ] ;
60
- var trace = cd0 . trace ;
68
+ var trace = cd [ 0 ] . trace ;
61
69
62
70
var adjustPixel = 0 ;
63
71
if ( trace . type === 'waterfall' && trace . connector . visible && trace . connector . mode === 'between' ) {
@@ -66,7 +74,7 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
66
74
67
75
var isHorizontal = ( trace . orientation === 'h' ) ;
68
76
69
- if ( ! plotinfo . isRangePlot ) cd0 . node3 = plotGroup ;
77
+ if ( ! plotinfo . isRangePlot ) cd [ 0 ] . node3 = plotGroup ;
70
78
71
79
var pointGroup = Lib . ensureSingle ( plotGroup , 'g' , 'points' ) ;
72
80
@@ -111,9 +119,6 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
111
119
112
120
var lw ;
113
121
var mc ;
114
- var prefix =
115
- ( trace . type === 'waterfall' ) ? 'waterfall' :
116
- ( trace . type === 'funnel' ) ? 'funnel' : 'bar' ;
117
122
118
123
if ( trace . type === 'waterfall' ) {
119
124
if ( ! isBlank ) {
@@ -128,13 +133,11 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
128
133
}
129
134
130
135
var offset = d3 . round ( ( lw / 2 ) % 1 , 2 ) ;
131
- var bargap = fullLayout [ prefix + 'gap' ] ;
132
- var bargroupgap = fullLayout [ prefix + 'groupgap' ] ;
133
136
134
137
function roundWithLine ( v ) {
135
138
// if there are explicit gaps, don't round,
136
139
// it can make the gaps look crappy
137
- return ( bargap === 0 && bargroupgap === 0 ) ?
140
+ return ( opts . gap === 0 && opts . groupgap === 0 ) ?
138
141
d3 . round ( Math . round ( v ) - offset , 2 ) : v ;
139
142
}
140
143
@@ -169,7 +172,7 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
169
172
. attr ( 'd' , isBlank ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
170
173
. call ( Drawing . setClipUrl , plotinfo . layerClipId , gd ) ;
171
174
172
- appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , prefix ) ;
175
+ appendBarText ( gd , plotinfo , bar , cd , i , x0 , x1 , y0 , y1 , opts ) ;
173
176
174
177
if ( plotinfo . layerClipId ) {
175
178
Drawing . hideOutsideRangePoint ( di , bar . select ( 'text' ) , xa , ya , trace . xcalendar , trace . ycalendar ) ;
@@ -178,15 +181,15 @@ module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
178
181
179
182
// lastly, clip points groups of `cliponaxis !== false` traces
180
183
// on `plotinfo._hasClipOnAxisFalse === true` subplots
181
- var hasClipOnAxisFalse = cd0 . trace . cliponaxis === false ;
184
+ var hasClipOnAxisFalse = trace . cliponaxis === false ;
182
185
Drawing . setClipUrl ( plotGroup , hasClipOnAxisFalse ? null : plotinfo . layerClipId , gd ) ;
183
186
} ) ;
184
187
185
188
// error bars are on the top
186
189
Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( gd , bartraces , plotinfo ) ;
187
190
} ;
188
191
189
- function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , prefix ) {
192
+ function appendBarText ( gd , plotinfo , bar , calcTrace , i , x0 , x1 , y0 , y1 , opts ) {
190
193
var xa = plotinfo . xaxis ;
191
194
var ya = plotinfo . yaxis ;
192
195
@@ -218,14 +221,18 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, prefix)
218
221
textPosition = getTextPosition ( trace , i ) ;
219
222
220
223
// compute text position
221
- var barmode = fullLayout [ prefix + 'mode' ] ;
222
- var inStackOrRelativeMode = barmode === 'stack' || barmode === 'relative' ;
224
+ var inStackOrRelativeMode =
225
+ opts . mode === 'stack' ||
226
+ opts . mode === 'relative' ;
223
227
224
228
var calcBar = calcTrace [ i ] ;
225
229
var isOutmostBar = ! inStackOrRelativeMode || calcBar . _outmost ;
226
230
227
- if ( ! text || textPosition === 'none' ||
228
- ( calcBar . isBlank && ( textPosition === 'auto' || textPosition === 'inside' ) ) ) {
231
+ if ( ! text ||
232
+ textPosition === 'none' ||
233
+ ( calcBar . isBlank && (
234
+ textPosition === 'auto' ||
235
+ textPosition === 'inside' ) ) ) {
229
236
bar . select ( 'text' ) . remove ( ) ;
230
237
return ;
231
238
}
@@ -286,8 +293,11 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, prefix)
286
293
( barWidth >= textWidth * ( barHeight / textHeight ) ) :
287
294
( barHeight >= textHeight * ( barWidth / textWidth ) ) ;
288
295
289
- if ( textHasSize &&
290
- ( fitsInside || fitsInsideIfRotated || fitsInsideIfShrunk ) ) {
296
+ if ( textHasSize && (
297
+ fitsInside ||
298
+ fitsInsideIfRotated ||
299
+ fitsInsideIfShrunk )
300
+ ) {
291
301
textPosition = 'inside' ;
292
302
} else {
293
303
textPosition = 'outside' ;
@@ -317,11 +327,17 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, prefix)
317
327
// compute text transform
318
328
var transform , constrained ;
319
329
if ( textPosition === 'outside' ) {
320
- constrained = trace . constraintext === 'both' || trace . constraintext === 'outside' ;
330
+ constrained =
331
+ trace . constraintext === 'both' ||
332
+ trace . constraintext === 'outside' ;
333
+
321
334
transform = getTransformToMoveOutsideBar ( x0 , x1 , y0 , y1 , textBB ,
322
335
orientation , constrained ) ;
323
336
} else {
324
- constrained = trace . constraintext === 'both' || trace . constraintext === 'inside' ;
337
+ constrained =
338
+ trace . constraintext === 'both' ||
339
+ trace . constraintext === 'inside' ;
340
+
325
341
transform = getTransformToMoveInsideBar ( x0 , x1 , y0 , y1 , textBB ,
326
342
orientation , constrained , trace . insidetextanchor , trace . insidetextrotate === 'none' ) ;
327
343
}
0 commit comments