@@ -47,6 +47,7 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
47
47
var cd0 = cd [ 0 ] ;
48
48
var trace = cd0 . trace ;
49
49
50
+ // Domain size
50
51
var domain = trace . domain ;
51
52
var size = Lib . extendFlat ( { } , fullLayout . _size , {
52
53
w : fullLayout . _size . w * ( domain . x [ 1 ] - domain . x [ 0 ] ) ,
@@ -56,7 +57,6 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
56
57
t : Math . max ( fullLayout . _size . t , fullLayout . height * domain . y [ 0 ] ) ,
57
58
b : Math . max ( fullLayout . _size . b , fullLayout . height * ( 1 - domain . y [ 0 ] ) )
58
59
} ) ;
59
- var centerX = size . l + size . w / 2 ;
60
60
61
61
// bignumber
62
62
var isBigNumber = trace . mode . indexOf ( 'bignumber' ) !== - 1 ;
@@ -66,18 +66,18 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
66
66
var hasTicker = trace . mode . indexOf ( 'delta' ) !== - 1 ;
67
67
var tickerPercentFmt = d3 . format ( '2%' ) ;
68
68
69
- // trendline
70
- var hasSparkline = trace . mode === 'sparkline' ;
71
- if ( hasSparkline ) isBigNumber = true ;
72
-
73
69
// gauge related
74
70
var isGauge = trace . mode . indexOf ( 'gauge' ) !== - 1 ;
75
- var isCircular = isGauge && trace . gauge . shape === 'circular' ;
76
- var isBullet = isGauge && trace . gauge . shape === 'bullet' ;
77
71
72
+ // circular gauge
73
+ var isCircular = isGauge && trace . gauge . shape === 'circular' ;
78
74
var theta = Math . PI / 2 ;
79
75
var radius = Math . min ( size . w / 2 , size . h * 0.75 ) ;
80
76
var innerRadius = cn . innerRadius * radius ;
77
+
78
+ // bullet gauge
79
+ var isBullet = isGauge && trace . gauge . shape === 'bullet' ;
80
+
81
81
var isWide = ! ( size . h > radius ) ;
82
82
83
83
function valueToAngle ( v ) {
@@ -87,60 +87,60 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
87
87
return angle ;
88
88
}
89
89
90
+ // TODO: Move the following to defaults
91
+ // Position elements
90
92
var bignumberVerticalMargin , mainFontSize ;
91
- var tickerVerticalMargin , tickerFontSize , gaugeFontSize ;
92
- if ( isBigNumber && ! isGauge ) {
93
- // Center the text
94
- mainFontSize = Math . min ( size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
95
- bignumberVerticalMargin = size . t + size . h / 2 ;
96
- tickerFontSize = 0.5 * mainFontSize ;
97
- }
98
- if ( hasTicker && ! isGauge && ! isBigNumber ) {
99
- bignumberVerticalMargin = 0 ;
100
- tickerVerticalMargin = size . t + size . h / 2 ;
101
- mainFontSize = Math . min ( size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
102
- tickerFontSize = mainFontSize ;
103
- }
104
- if ( isCircular ) {
105
- bignumberVerticalMargin = size . t + size . h ;
106
- if ( ! isWide ) bignumberVerticalMargin -= ( size . h - radius ) / 2 ;
107
- // TODO: check formatted size of the number
108
- mainFontSize = Math . min ( 2 * innerRadius / ( trace . max . toString ( ) . length ) ) ;
109
- tickerFontSize = 0.35 * mainFontSize ;
110
- }
111
- if ( isBullet ) {
112
- // Center the text
113
- mainFontSize = Math . min ( size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
114
- bignumberVerticalMargin = size . t + size . h / 2 ;
115
- tickerFontSize = 0.5 * mainFontSize ;
93
+ var tickerVerticalMargin , tickerFontSize , tickerBaseline ;
94
+ var gaugeFontSize ;
95
+ var labelFontSize ;
96
+ var centerX = size . l + size . w / 2 ;
97
+
98
+ if ( ! isGauge ) {
99
+ // when no gauge, we are only constrained by figure size
100
+ if ( isBigNumber ) {
101
+ // Center the text vertically
102
+ mainFontSize = Math . min ( size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
103
+ tickerFontSize = 0.5 * mainFontSize ;
104
+ bignumberVerticalMargin = size . t + size . h / 2 ;
105
+ tickerVerticalMargin = size . t + size . h - tickerFontSize / 2 ;
106
+ } else {
107
+ mainFontSize = Math . min ( size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
108
+ tickerFontSize = mainFontSize ;
109
+ bignumberVerticalMargin = 0 ;
110
+ tickerVerticalMargin = size . t + size . h / 2 ;
111
+ }
112
+ labelFontSize = 0.35 * mainFontSize ;
113
+ } else {
114
+ if ( isCircular ) {
115
+ bignumberVerticalMargin = size . t + size . h ;
116
+ if ( ! isWide ) bignumberVerticalMargin -= ( size . h - radius ) / 2 ;
117
+ // TODO: check formatted size of the number
118
+ mainFontSize = Math . min ( 2 * innerRadius / ( trace . max . toString ( ) . length ) ) ;
119
+ tickerFontSize = 0.35 * mainFontSize ;
120
+ }
121
+ if ( isBullet ) {
122
+ // Center the text
123
+ mainFontSize = Math . min ( size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
124
+ bignumberVerticalMargin = size . t + size . h / 2 ;
125
+ tickerFontSize = 0.5 * mainFontSize ;
126
+ }
127
+ gaugeFontSize = Math . max ( 0.25 * mainFontSize , ( radius - innerRadius ) / 4 ) ;
128
+ labelFontSize = gaugeFontSize ;
129
+
130
+ if ( ! isBigNumber ) {
131
+ tickerFontSize = 0.75 * mainFontSize ;
132
+ tickerVerticalMargin = bignumberVerticalMargin ;
133
+ tickerBaseline = 'bottom' ;
134
+ } else {
135
+ tickerVerticalMargin = bignumberVerticalMargin + tickerFontSize ;
136
+ }
116
137
}
117
- gaugeFontSize = Math . max ( 0.25 * mainFontSize , ( radius - innerRadius ) / 4 ) ;
118
- if ( ! tickerVerticalMargin ) tickerVerticalMargin = ! isGauge ? size . t + size . h - tickerFontSize / 2 : bignumberVerticalMargin + tickerFontSize ;
119
138
120
139
plotGroup . each ( function ( ) {
121
- var data ;
122
- // Draw trendline
123
- data = cd . filter ( function ( ) { return hasSparkline ; } ) ;
124
- var x = d3 . scale . linear ( ) . domain ( [ trace . min , cd0 . historical . length - 1 ] ) . range ( [ 0 , size . w ] ) ;
125
- var y = d3 . scale . linear ( ) . domain ( [ trace . min , trace . max ] ) . range ( [ size . h , 0 ] ) ;
126
- var line = d3 . svg . line ( )
127
- . x ( function ( d , i ) { return x ( i ) ; } )
128
- . y ( function ( d ) { return y ( d ) ; } ) ;
129
- var sparkline = d3 . select ( this ) . selectAll ( 'path.sparkline' ) . data ( data ) ;
130
- sparkline . enter ( ) . append ( 'svg:path' ) . classed ( 'sparkline' , true ) ;
131
- sparkline
132
- . attr ( 'd' , line ( cd0 . historical ) )
133
- . style ( 'fill' , 'none' )
134
- . style ( 'stroke' , 'rgba(255, 255, 255, 0.5)' )
135
- . style ( 'stroke-width' , 2 )
136
- . attr ( 'transform' , 'translate(' + size . l + ', ' + size . t + ')' ) ;
137
- sparkline . exit ( ) . remove ( ) ;
138
-
139
140
// bignumber
140
- data = cd . filter ( function ( ) { return isBigNumber ; } ) ;
141
+ var data = cd . filter ( function ( ) { return isBigNumber ; } ) ;
141
142
var number = d3 . select ( this ) . selectAll ( 'text.number' ) . data ( data ) ;
142
143
number . enter ( ) . append ( 'text' ) . classed ( 'number' , true ) ;
143
-
144
144
number . attr ( {
145
145
x : centerX ,
146
146
y : bignumberVerticalMargin ,
@@ -177,7 +177,7 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
177
177
x : centerX ,
178
178
y : tickerVerticalMargin ,
179
179
'text-anchor' : 'middle' ,
180
- 'alignment-baseline' : 'middle'
180
+ 'alignment-baseline' : tickerBaseline || 'middle'
181
181
} )
182
182
. call ( Drawing . font , trace . font )
183
183
. style ( 'font-size' , tickerFontSize )
@@ -195,12 +195,12 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
195
195
name . enter ( ) . append ( 'text' ) . classed ( 'name' , true ) ;
196
196
name . attr ( {
197
197
x : centerX ,
198
- y : size . t + gaugeFontSize / 2 ,
198
+ y : size . t + labelFontSize / 2 ,
199
199
'text-anchor' : 'middle' ,
200
200
'alignment-baseline' : 'middle'
201
201
} )
202
202
. call ( Drawing . font , trace . font )
203
- . style ( 'font-size' , gaugeFontSize )
203
+ . style ( 'font-size' , labelFontSize )
204
204
. text ( trace . name ) ;
205
205
name . exit ( ) . remove ( ) ;
206
206
0 commit comments