@@ -13,9 +13,9 @@ var d3 = require('d3');
13
13
var Lib = require ( '../../lib' ) ;
14
14
var Drawing = require ( '../../components/drawing' ) ;
15
15
var cn = require ( './constants' ) ;
16
+ var svgTextUtils = require ( '../../lib/svg_text_utils' ) ;
16
17
// var Plots = require('../../plots/plots');
17
18
// var Axes = require('../../plots/cartesian/axes');
18
- // var svgTextUtils = require('../../lib/svg_text_utils');
19
19
//
20
20
// // arc cotangent
21
21
// function arcctg(x) { return Math.PI / 2 - Math.atan(x); }
@@ -52,12 +52,15 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
52
52
var size = Lib . extendFlat ( { } , fullLayout . _size , {
53
53
w : fullLayout . _size . w * ( domain . x [ 1 ] - domain . x [ 0 ] ) ,
54
54
h : fullLayout . _size . h * ( domain . y [ 1 ] - domain . y [ 0 ] ) ,
55
- l : Math . max ( fullLayout . _size . l , fullLayout . width * domain . x [ 0 ] ) ,
56
- r : Math . max ( fullLayout . _size . r , fullLayout . width * ( 1 - domain . x [ 1 ] ) ) ,
57
- t : Math . max ( fullLayout . _size . t , fullLayout . height * domain . y [ 0 ] ) ,
58
- b : Math . max ( fullLayout . _size . b , fullLayout . height * ( 1 - domain . y [ 0 ] ) )
55
+ l : fullLayout . _size . l + fullLayout . _size . w * domain . x [ 0 ] ,
56
+ r : fullLayout . _size . r + fullLayout . _size . w * ( 1 - domain . x [ 1 ] ) ,
57
+ t : fullLayout . _size . t + fullLayout . _size . h * domain . y [ 0 ] ,
58
+ b : fullLayout . _size . b + fullLayout . _size . h * ( 1 - domain . y [ 1 ] )
59
59
} ) ;
60
60
61
+ // title
62
+ var hasTitle = true ;
63
+
61
64
// bignumber
62
65
var hasBigNumber = trace . mode . indexOf ( 'bignumber' ) !== - 1 ;
63
66
var fmt = d3 . format ( trace . valueformat ) ;
@@ -98,6 +101,7 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
98
101
// Position elements
99
102
var bignumberVerticalMargin , mainFontSize , bignumberX ;
100
103
var deltaVerticalMargin , deltaFontSize , deltaBaseline ;
104
+ var bulletHeight = Math . min ( cn . bulletHeight , size . h / 2 ) ;
101
105
var gaugeFontSize ;
102
106
var labelFontSize ;
103
107
var centerX = size . l + size . w / 2 ;
@@ -133,12 +137,12 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
133
137
if ( isBullet ) {
134
138
// Center the text
135
139
var p = 0.75 ;
136
- mainFontSize = Math . min ( 0.25 * size . w / ( trace . max . toString ( ) . length ) , size . h / 2 ) ;
140
+ mainFontSize = Math . min ( 0.2 * size . w / ( trace . max . toString ( ) . length ) , bulletHeight ) ;
137
141
bignumberVerticalMargin = size . t + size . h / 2 ;
138
142
bignumberX = size . l + ( p + ( 1 - p ) / 2 ) * size . w ;
139
143
deltaFontSize = 0.5 * mainFontSize ;
140
144
deltaVerticalMargin = bignumberVerticalMargin + 1.5 * deltaFontSize ;
141
- labelFontSize = 0.75 * mainFontSize ;
145
+ labelFontSize = 0.4 * mainFontSize ;
142
146
}
143
147
144
148
if ( ! hasBigNumber ) {
@@ -148,6 +152,21 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
148
152
}
149
153
150
154
plotGroup . each ( function ( ) {
155
+ // Trace name
156
+ var name = d3 . select ( this ) . selectAll ( 'text.name' ) . data ( cd ) ;
157
+ name . enter ( ) . append ( 'text' ) . classed ( 'name' , true ) ;
158
+ name . attr ( {
159
+ x : isBullet ? size . l + 0.23 * size . w : centerX ,
160
+ y : isBullet ? bignumberVerticalMargin : size . t + labelFontSize / 2 ,
161
+ 'text-anchor' : isBullet ? 'end' : 'middle' ,
162
+ 'alignment-baseline' : 'central'
163
+ } )
164
+ . text ( trace . name )
165
+ . call ( Drawing . font , trace . font )
166
+ . style ( 'font-size' , labelFontSize )
167
+ . call ( svgTextUtils . convertToTspans , gd ) ;
168
+ name . exit ( ) . remove ( ) ;
169
+
151
170
// bignumber
152
171
var data = cd . filter ( function ( ) { return hasBigNumber ; } ) ;
153
172
var number = d3 . select ( this ) . selectAll ( 'text.number' ) . data ( data ) ;
@@ -196,20 +215,6 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
196
215
. text ( deltaText ) ;
197
216
delta . exit ( ) . remove ( ) ;
198
217
199
- // Trace name
200
- var name = d3 . select ( this ) . selectAll ( 'text.name' ) . data ( cd ) ;
201
- name . enter ( ) . append ( 'text' ) . classed ( 'name' , true ) ;
202
- name . attr ( {
203
- x : centerX ,
204
- y : size . t + labelFontSize / 2 ,
205
- 'text-anchor' : 'middle' ,
206
- 'alignment-baseline' : 'central'
207
- } )
208
- . call ( Drawing . font , trace . font )
209
- . style ( 'font-size' , labelFontSize )
210
- . text ( trace . name ) ;
211
- name . exit ( ) . remove ( ) ;
212
-
213
218
// Draw circular gauge
214
219
data = cd . filter ( function ( ) { return isAngular ; } ) ;
215
220
var gauge = d3 . select ( this ) . selectAll ( 'g.gauge' ) . data ( data ) ;
@@ -246,8 +251,8 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
246
251
. startAngle ( - theta ) ;
247
252
248
253
var valueArcPath = d3 . svg . arc ( )
249
- . innerRadius ( ( innerRadius + radius ) / 2 - cn . valueHeight / 2 * ( radius - innerRadius ) )
250
- . outerRadius ( ( innerRadius + radius ) / 2 + cn . valueHeight / 2 * ( radius - innerRadius ) )
254
+ . innerRadius ( ( innerRadius + radius ) / 2 - trace . gauge . value . size / 2 * ( radius - innerRadius ) )
255
+ . outerRadius ( ( innerRadius + radius ) / 2 + trace . gauge . value . size / 2 * ( radius - innerRadius ) )
251
256
. startAngle ( - theta ) ;
252
257
253
258
// TODO: DRY up the following code to draw the different arcs
@@ -395,14 +400,16 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
395
400
// Axes.drawOne(gd, ya);
396
401
// }
397
402
data = cd . filter ( function ( ) { return isBullet ; } ) ;
398
- var bulletHeight = cn . bulletHeight ;
399
- var innerBulletHeight = cn . valueHeight * bulletHeight ;
403
+ var innerBulletHeight = trace . gauge . value . size * bulletHeight ;
400
404
var bulletVerticalMargin = bignumberVerticalMargin - bulletHeight / 2 ;
401
405
var bullet = d3 . select ( this ) . selectAll ( 'g.bullet' ) . data ( data ) ;
402
406
bullet . enter ( ) . append ( 'g' ) . classed ( 'bullet' , true ) ;
403
- bullet . attr ( 'transform' , 'translate(' + size . l + ',' + bulletVerticalMargin + ')' ) ;
407
+ bullet . attr ( 'transform' , 'translate(' + ( size . l + ( hasTitle ? 0.25 : 0 ) * size . w ) + ',' + bulletVerticalMargin + ')' ) ;
404
408
405
- var scale = d3 . scale . linear ( ) . domain ( [ trace . min , trace . max ] ) . range ( [ 0 , ( ( hasBigNumber || hasDelta ) ? 0.75 : 1.0 ) * size . w ] ) ;
409
+ var bulletWidth = 1 ;
410
+ if ( hasBigNumber || hasDelta ) bulletWidth -= 0.25 ;
411
+ if ( hasTitle ) bulletWidth -= 0.25 ;
412
+ var scale = d3 . scale . linear ( ) . domain ( [ trace . min , trace . max ] ) . range ( [ 0 , bulletWidth * size . w ] ) ;
406
413
407
414
// TODO: prevent rect width from being negative
408
415
var bgBullet = bullet . selectAll ( 'g.bgBullet' ) . data ( cd ) ;
@@ -453,8 +460,8 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
453
460
threshold . select ( 'line' )
454
461
. attr ( 'x1' , scale ( trace . gauge . threshold . value ) )
455
462
. attr ( 'x2' , scale ( trace . gauge . threshold . value ) )
456
- . attr ( 'y1' , ( 1 - trace . gauge . threshold . height ) / 2 * bulletHeight )
457
- . attr ( 'y2' , ( 1 - ( 1 - trace . gauge . threshold . height ) / 2 ) * bulletHeight )
463
+ . attr ( 'y1' , ( 1 - trace . gauge . threshold . size ) / 2 * bulletHeight )
464
+ . attr ( 'y2' , ( 1 - ( 1 - trace . gauge . threshold . size ) / 2 ) * bulletHeight )
458
465
. style ( 'stroke' , trace . gauge . threshold . color )
459
466
. style ( 'stroke-width' , trace . gauge . threshold . width ) ;
460
467
threshold . exit ( ) . remove ( ) ;
@@ -469,19 +476,18 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
469
476
group . append ( 'path' ) ;
470
477
ticks . select ( 'path' )
471
478
. attr ( 'd' , 'M0,0V' + 0.1 * bulletHeight )
472
- . style ( 'stroke' , 'white' ) ;
479
+ . style ( 'stroke' , trace . font . color ) ;
473
480
474
481
group . insert ( 'text' ) ;
475
482
ticks . select ( 'text' )
476
483
. text ( function ( d ) { return fmt ( d ) ; } )
477
484
. call ( Drawing . font , trace . font )
485
+ . style ( 'font-size' , labelFontSize )
478
486
. attr ( {
479
- y : 20 ,
487
+ y : 0.2 * bulletHeight ,
480
488
'text-anchor' : 'middle' ,
481
- 'alignment-baseline' : 'central'
482
- } )
483
- . style ( 'fill' , 'white' ) ;
484
-
489
+ 'alignment-baseline' : 'hanging'
490
+ } ) ;
485
491
ticks
486
492
. attr ( 'transform' , function ( d ) {
487
493
var pos = scale ( d ) ;
0 commit comments