@@ -19,7 +19,6 @@ var svgTextUtils = require('../../lib/svg_text_utils');
19
19
var Color = require ( '../../components/color' ) ;
20
20
var Drawing = require ( '../../components/drawing' ) ;
21
21
var Registry = require ( '../../registry' ) ;
22
- var makeTraceGroups = require ( '../../plots/cartesian/make_trace_groups' ) ;
23
22
24
23
var attributes = require ( './attributes' ) ,
25
24
attributeText = attributes . text ,
@@ -32,128 +31,128 @@ var attributes = require('./attributes'),
32
31
var TEXTPAD = 3 ;
33
32
34
33
module . exports = function plot ( gd , plotinfo , cdbar , barLayer ) {
35
- var bartraces = makeTraceGroups ( gd , plotinfo , cdbar , barLayer , 'trace bars' , plotOne ) ;
36
-
37
- // error bars are on the top
38
- Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( bartraces , plotinfo ) ;
39
- } ;
40
-
41
- function plotOne ( gd , plotinfo , cd , plotGroup ) {
42
34
var xa = plotinfo . xaxis ;
43
35
var ya = plotinfo . yaxis ;
44
36
var fullLayout = gd . _fullLayout ;
45
- var cd0 = cd [ 0 ] ;
46
- var t = cd0 . t ;
47
- var trace = cd0 . trace ;
48
37
49
- if ( ! plotinfo . isRangePlot ) cd0 . node3 = plotGroup ;
38
+ var bartraces = Lib . makeTraceGroups ( barLayer , cdbar , 'trace bars' ) . each ( function ( cd ) {
39
+ var plotGroup = d3 . select ( this ) ;
40
+ var cd0 = cd [ 0 ] ;
41
+ var t = cd0 . t ;
42
+ var trace = cd0 . trace ;
50
43
51
- var poffset = t . poffset ;
52
- var poffsetIsArray = Array . isArray ( poffset ) ;
44
+ if ( ! plotinfo . isRangePlot ) cd0 . node3 = plotGroup ;
53
45
54
- var pointGroup = Lib . ensureSingle ( plotGroup , 'g' , 'points' ) ;
46
+ var poffset = t . poffset ;
47
+ var poffsetIsArray = Array . isArray ( poffset ) ;
55
48
56
- var bars = pointGroup . selectAll ( 'g.point' ) . data ( Lib . identity ) ;
49
+ var pointGroup = Lib . ensureSingle ( plotGroup , 'g' , 'points' ) ;
57
50
58
- bars . enter ( ) . append ( 'g' )
59
- . classed ( 'point' , true ) ;
51
+ var bars = pointGroup . selectAll ( 'g.point' ) . data ( Lib . identity ) ;
60
52
61
- bars . exit ( ) . remove ( ) ;
53
+ bars . enter ( ) . append ( 'g' )
54
+ . classed ( 'point' , true ) ;
62
55
63
- bars . each ( function ( di , i ) {
64
- var bar = d3 . select ( this ) ;
56
+ bars . exit ( ) . remove ( ) ;
65
57
66
- // now display the bar
67
- // clipped xf/yf (2nd arg true): non-positive
68
- // log values go off-screen by plotwidth
69
- // so you see them continue if you drag the plot
70
- var p0 = di . p + ( ( poffsetIsArray ) ? poffset [ i ] : poffset ) ,
71
- p1 = p0 + di . w ,
72
- s0 = di . b ,
73
- s1 = s0 + di . s ;
58
+ bars . each ( function ( di , i ) {
59
+ var bar = d3 . select ( this ) ;
74
60
75
- var x0 , x1 , y0 , y1 ;
76
- if ( trace . orientation === 'h' ) {
77
- y0 = ya . c2p ( p0 , true ) ;
78
- y1 = ya . c2p ( p1 , true ) ;
79
- x0 = xa . c2p ( s0 , true ) ;
80
- x1 = xa . c2p ( s1 , true ) ;
61
+ // now display the bar
62
+ // clipped xf/yf (2nd arg true): non-positive
63
+ // log values go off-screen by plotwidth
64
+ // so you see them continue if you drag the plot
65
+ var p0 = di . p + ( ( poffsetIsArray ) ? poffset [ i ] : poffset ) ,
66
+ p1 = p0 + di . w ,
67
+ s0 = di . b ,
68
+ s1 = s0 + di . s ;
81
69
82
- // for selections
83
- di . ct = [ x1 , ( y0 + y1 ) / 2 ] ;
84
- }
85
- else {
86
- x0 = xa . c2p ( p0 , true ) ;
87
- x1 = xa . c2p ( p1 , true ) ;
88
- y0 = ya . c2p ( s0 , true ) ;
89
- y1 = ya . c2p ( s1 , true ) ;
70
+ var x0 , x1 , y0 , y1 ;
71
+ if ( trace . orientation === 'h' ) {
72
+ y0 = ya . c2p ( p0 , true ) ;
73
+ y1 = ya . c2p ( p1 , true ) ;
74
+ x0 = xa . c2p ( s0 , true ) ;
75
+ x1 = xa . c2p ( s1 , true ) ;
90
76
91
- // for selections
92
- di . ct = [ ( x0 + x1 ) / 2 , y1 ] ;
93
- }
77
+ // for selections
78
+ di . ct = [ x1 , ( y0 + y1 ) / 2 ] ;
79
+ }
80
+ else {
81
+ x0 = xa . c2p ( p0 , true ) ;
82
+ x1 = xa . c2p ( p1 , true ) ;
83
+ y0 = ya . c2p ( s0 , true ) ;
84
+ y1 = ya . c2p ( s1 , true ) ;
94
85
95
- if ( ! isNumeric ( x0 ) || ! isNumeric ( x1 ) ||
96
- ! isNumeric ( y0 ) || ! isNumeric ( y1 ) ||
97
- x0 === x1 || y0 === y1 ) {
98
- bar . remove ( ) ;
99
- return ;
100
- }
86
+ // for selections
87
+ di . ct = [ ( x0 + x1 ) / 2 , y1 ] ;
88
+ }
89
+
90
+ if ( ! isNumeric ( x0 ) || ! isNumeric ( x1 ) ||
91
+ ! isNumeric ( y0 ) || ! isNumeric ( y1 ) ||
92
+ x0 === x1 || y0 === y1 ) {
93
+ bar . remove ( ) ;
94
+ return ;
95
+ }
101
96
102
- var lw = ( di . mlw + 1 || trace . marker . line . width + 1 ||
103
- ( di . trace ? di . trace . marker . line . width : 0 ) + 1 ) - 1 ,
104
- offset = d3 . round ( ( lw / 2 ) % 1 , 2 ) ;
97
+ var lw = ( di . mlw + 1 || trace . marker . line . width + 1 ||
98
+ ( di . trace ? di . trace . marker . line . width : 0 ) + 1 ) - 1 ,
99
+ offset = d3 . round ( ( lw / 2 ) % 1 , 2 ) ;
105
100
106
- function roundWithLine ( v ) {
107
- // if there are explicit gaps, don't round,
108
- // it can make the gaps look crappy
109
- return ( fullLayout . bargap === 0 && fullLayout . bargroupgap === 0 ) ?
110
- d3 . round ( Math . round ( v ) - offset , 2 ) : v ;
111
- }
101
+ function roundWithLine ( v ) {
102
+ // if there are explicit gaps, don't round,
103
+ // it can make the gaps look crappy
104
+ return ( fullLayout . bargap === 0 && fullLayout . bargroupgap === 0 ) ?
105
+ d3 . round ( Math . round ( v ) - offset , 2 ) : v ;
106
+ }
112
107
113
- function expandToVisible ( v , vc ) {
114
- // if it's not in danger of disappearing entirely,
115
- // round more precisely
116
- return Math . abs ( v - vc ) >= 2 ? roundWithLine ( v ) :
117
- // but if it's very thin, expand it so it's
118
- // necessarily visible, even if it might overlap
119
- // its neighbor
120
- ( v > vc ? Math . ceil ( v ) : Math . floor ( v ) ) ;
121
- }
108
+ function expandToVisible ( v , vc ) {
109
+ // if it's not in danger of disappearing entirely,
110
+ // round more precisely
111
+ return Math . abs ( v - vc ) >= 2 ? roundWithLine ( v ) :
112
+ // but if it's very thin, expand it so it's
113
+ // necessarily visible, even if it might overlap
114
+ // its neighbor
115
+ ( v > vc ? Math . ceil ( v ) : Math . floor ( v ) ) ;
116
+ }
122
117
123
- if ( ! gd . _context . staticPlot ) {
124
- // if bars are not fully opaque or they have a line
125
- // around them, round to integer pixels, mainly for
126
- // safari so we prevent overlaps from its expansive
127
- // pixelation. if the bars ARE fully opaque and have
128
- // no line, expand to a full pixel to make sure we
129
- // can see them
130
- var op = Color . opacity ( di . mc || trace . marker . color ) ,
131
- fixpx = ( op < 1 || lw > 0.01 ) ?
132
- roundWithLine : expandToVisible ;
133
- x0 = fixpx ( x0 , x1 ) ;
134
- x1 = fixpx ( x1 , x0 ) ;
135
- y0 = fixpx ( y0 , y1 ) ;
136
- y1 = fixpx ( y1 , y0 ) ;
137
- }
118
+ if ( ! gd . _context . staticPlot ) {
119
+ // if bars are not fully opaque or they have a line
120
+ // around them, round to integer pixels, mainly for
121
+ // safari so we prevent overlaps from its expansive
122
+ // pixelation. if the bars ARE fully opaque and have
123
+ // no line, expand to a full pixel to make sure we
124
+ // can see them
125
+ var op = Color . opacity ( di . mc || trace . marker . color ) ,
126
+ fixpx = ( op < 1 || lw > 0.01 ) ?
127
+ roundWithLine : expandToVisible ;
128
+ x0 = fixpx ( x0 , x1 ) ;
129
+ x1 = fixpx ( x1 , x0 ) ;
130
+ y0 = fixpx ( y0 , y1 ) ;
131
+ y1 = fixpx ( y1 , y0 ) ;
132
+ }
138
133
139
- Lib . ensureSingle ( bar , 'path' )
140
- . style ( 'vector-effect' , 'non-scaling-stroke' )
141
- . attr ( 'd' ,
142
- 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
143
- . call ( Drawing . setClipUrl , plotinfo . layerClipId ) ;
134
+ Lib . ensureSingle ( bar , 'path' )
135
+ . style ( 'vector-effect' , 'non-scaling-stroke' )
136
+ . attr ( 'd' ,
137
+ 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z' )
138
+ . call ( Drawing . setClipUrl , plotinfo . layerClipId ) ;
144
139
145
- appendBarText ( gd , bar , cd , i , x0 , x1 , y0 , y1 ) ;
140
+ appendBarText ( gd , bar , cd , i , x0 , x1 , y0 , y1 ) ;
146
141
147
- if ( plotinfo . layerClipId ) {
148
- Drawing . hideOutsideRangePoint ( di , bar . select ( 'text' ) , xa , ya , trace . xcalendar , trace . ycalendar ) ;
149
- }
142
+ if ( plotinfo . layerClipId ) {
143
+ Drawing . hideOutsideRangePoint ( di , bar . select ( 'text' ) , xa , ya , trace . xcalendar , trace . ycalendar ) ;
144
+ }
145
+ } ) ;
146
+
147
+ // lastly, clip points groups of `cliponaxis !== false` traces
148
+ // on `plotinfo._hasClipOnAxisFalse === true` subplots
149
+ var hasClipOnAxisFalse = cd0 . trace . cliponaxis === false ;
150
+ Drawing . setClipUrl ( plotGroup , hasClipOnAxisFalse ? null : plotinfo . layerClipId ) ;
150
151
} ) ;
151
152
152
- // lastly, clip points groups of `cliponaxis !== false` traces
153
- // on `plotinfo._hasClipOnAxisFalse === true` subplots
154
- var hasClipOnAxisFalse = cd0 . trace . cliponaxis === false ;
155
- Drawing . setClipUrl ( plotGroup , hasClipOnAxisFalse ? null : plotinfo . layerClipId ) ;
156
- }
153
+ // error bars are on the top
154
+ Registry . getComponentMethod ( 'errorbars' , 'plot' ) ( bartraces , plotinfo ) ;
155
+ } ;
157
156
158
157
function appendBarText ( gd , bar , calcTrace , i , x0 , x1 , y0 , y1 ) {
159
158
var textPosition ;
0 commit comments