@@ -36,15 +36,17 @@ var position = {
36
36
37
37
var SI_PREFIX = / [ y z a f p n µ m k M G T P E Z Y ] / ;
38
38
39
+ function hasTransition ( transitionOpts ) {
40
+ // If transition config is provided, then it is only a partial replot and traces not
41
+ // updated are removed.
42
+ return transitionOpts && transitionOpts . duration > 0 ;
43
+ }
44
+
39
45
module . exports = function plot ( gd , cdModule , transitionOpts , makeOnCompleteCallback ) {
40
46
var fullLayout = gd . _fullLayout ;
41
47
var onComplete ;
42
48
43
- // If transition config is provided, then it is only a partial replot and traces not
44
- // updated are removed.
45
- var hasTransition = transitionOpts && transitionOpts . duration > 0 ;
46
-
47
- if ( hasTransition ) {
49
+ if ( hasTransition ( transitionOpts ) ) {
48
50
if ( makeOnCompleteCallback ) {
49
51
// If it was passed a callback to register completion, make a callback. If
50
52
// this is created, then it must be executed on completion, otherwise the
@@ -56,6 +58,7 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
56
58
Lib . makeTraceGroups ( fullLayout . _indicatorlayer , cdModule , 'trace' ) . each ( function ( cd ) {
57
59
var cd0 = cd [ 0 ] ;
58
60
var trace = cd0 . trace ;
61
+
59
62
var plotGroup = d3 . select ( this ) ;
60
63
61
64
// Elements in trace
@@ -109,15 +112,13 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
109
112
}
110
113
111
114
// Draw numbers
112
- var numbersOpts = {
115
+ drawNumbers ( gd , plotGroup , cd , {
113
116
numbersX : numbersX ,
114
117
numbersY : numbersY ,
115
118
numbersScaler : numbersScaler ,
116
- hasTransition : hasTransition ,
117
119
transitionOpts : transitionOpts ,
118
120
onComplete : onComplete
119
- } ;
120
- drawNumbers ( gd , plotGroup , cd , numbersOpts ) ;
121
+ } ) ;
121
122
122
123
// Reexpress our gauge background attributes for drawing
123
124
var gaugeBg , gaugeOutline ;
@@ -149,37 +150,38 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
149
150
var angularaxisLayer = plotGroup . selectAll ( 'g.angularaxis' ) . data ( isAngular ? cd : [ ] ) ;
150
151
angularaxisLayer . exit ( ) . remove ( ) ;
151
152
152
- var gaugeOpts = {
153
- size : size ,
154
- radius : radius ,
155
- innerRadius : innerRadius ,
156
- gaugeBg : gaugeBg ,
157
- gaugeOutline : gaugeOutline ,
158
- angularaxisLayer : angularaxisLayer ,
159
- angularGauge : angularGauge ,
160
- hasTransition : hasTransition ,
161
- transitionOpts : transitionOpts ,
162
- onComplete : onComplete
163
- } ;
164
- if ( isAngular ) drawAngularGauge ( gd , plotGroup , cd , gaugeOpts ) ;
153
+ if ( isAngular ) {
154
+ drawAngularGauge ( gd , plotGroup , cd , {
155
+ radius : radius ,
156
+ innerRadius : innerRadius ,
157
+
158
+ gauge : angularGauge ,
159
+ layer : angularaxisLayer ,
160
+ size : size ,
161
+ gaugeBg : gaugeBg ,
162
+ gaugeOutline : gaugeOutline ,
163
+ transitionOpts : transitionOpts ,
164
+ onComplete : onComplete
165
+ } ) ;
166
+ }
165
167
166
168
// Prepare bullet layers
167
169
var bulletGauge = plotGroup . selectAll ( 'g.bullet' ) . data ( isBullet ? cd : [ ] ) ;
168
170
bulletGauge . exit ( ) . remove ( ) ;
169
171
var bulletaxisLayer = plotGroup . selectAll ( 'g.bulletaxis' ) . data ( isBullet ? cd : [ ] ) ;
170
172
bulletaxisLayer . exit ( ) . remove ( ) ;
171
173
172
- gaugeOpts = {
173
- size : size ,
174
- gaugeBg : gaugeBg ,
175
- gaugeOutline : gaugeOutline ,
176
- bulletGauge : bulletGauge ,
177
- bulletaxisLayer : bulletaxisLayer ,
178
- hasTransition : hasTransition ,
179
- transitionOpts : transitionOpts ,
180
- onComplete : onComplete
181
- } ;
182
- if ( isBullet ) drawBulletGauge ( gd , plotGroup , cd , gaugeOpts ) ;
174
+ if ( isBullet ) {
175
+ drawBulletGauge ( gd , plotGroup , cd , {
176
+ gauge : bulletGauge ,
177
+ layer : bulletaxisLayer ,
178
+ size : size ,
179
+ gaugeBg : gaugeBg ,
180
+ gaugeOutline : gaugeOutline ,
181
+ transitionOpts : transitionOpts ,
182
+ onComplete : onComplete
183
+ } ) ;
184
+ }
183
185
184
186
// title
185
187
var title = plotGroup . selectAll ( 'text.title' ) . data ( cd ) ;
@@ -223,40 +225,38 @@ module.exports = function plot(gd, cdModule, transitionOpts, makeOnCompleteCallb
223
225
} ) ;
224
226
} ;
225
227
226
- function drawBulletGauge ( gd , plotGroup , cd , gaugeOpts ) {
228
+ function drawBulletGauge ( gd , plotGroup , cd , opts ) {
227
229
var trace = cd [ 0 ] . trace ;
228
230
229
- var bullet = gaugeOpts . bulletGauge ;
230
- var bulletaxis = gaugeOpts . bulletaxisLayer ;
231
- var gaugeBg = gaugeOpts . gaugeBg ;
232
- var gaugeOutline = gaugeOpts . gaugeOutline ;
233
- var size = gaugeOpts . size ;
231
+ var bullet = opts . gauge ;
232
+ var axisLayer = opts . layer ;
233
+ var gaugeBg = opts . gaugeBg ;
234
+ var gaugeOutline = opts . gaugeOutline ;
235
+ var size = opts . size ;
234
236
var domain = trace . domain ;
235
237
236
- var hasTransition = gaugeOpts . hasTransition ;
237
- var transitionOpts = gaugeOpts . transitionOpts ;
238
- var onComplete = gaugeOpts . onComplete ;
238
+ var transitionOpts = opts . transitionOpts ;
239
+ var onComplete = opts . onComplete ;
239
240
240
241
// preparing axis
241
242
var ax , vals , transFn , tickSign , shift ;
242
- var opts = trace . gauge . axis ;
243
243
244
244
// Enter bullet, axis
245
245
bullet . enter ( ) . append ( 'g' ) . classed ( 'bullet' , true ) ;
246
246
bullet . attr ( 'transform' , 'translate(' + size . l + ', ' + size . t + ')' ) ;
247
247
248
- bulletaxis . enter ( ) . append ( 'g' )
248
+ axisLayer . enter ( ) . append ( 'g' )
249
249
. classed ( 'bulletaxis' , true )
250
250
. classed ( 'crisp' , true ) ;
251
- bulletaxis . selectAll ( 'g.' + 'xbulletaxis' + 'tick,path,text' ) . remove ( ) ;
251
+ axisLayer . selectAll ( 'g.' + 'xbulletaxis' + 'tick,path,text' ) . remove ( ) ;
252
252
253
253
// Draw bullet
254
254
var bulletHeight = size . h ; // use all vertical domain
255
255
var innerBulletHeight = trace . gauge . bar . thickness * bulletHeight ;
256
256
var bulletLeft = domain . x [ 0 ] ;
257
257
var bulletRight = domain . x [ 0 ] + ( domain . x [ 1 ] - domain . x [ 0 ] ) * ( ( trace . _hasNumber || trace . _hasDelta ) ? ( 1 - cn . bulletNumberDomainSize ) : 1 ) ;
258
258
259
- ax = mockAxis ( gd , opts , trace . gauge . axis . range ) ;
259
+ ax = mockAxis ( gd , trace . gauge . axis , trace . gauge . axis . range ) ;
260
260
ax . _id = 'xbulletaxis' ;
261
261
ax . domain = [ bulletLeft , bulletRight ] ;
262
262
ax . setScale ( ) ;
@@ -269,14 +269,14 @@ function drawBulletGauge(gd, plotGroup, cd, gaugeOpts) {
269
269
if ( ax . visible ) {
270
270
Axes . drawTicks ( gd , ax , {
271
271
vals : ax . ticks === 'inside' ? Axes . clipEnds ( ax , vals ) : vals ,
272
- layer : bulletaxis ,
272
+ layer : axisLayer ,
273
273
path : Axes . makeTickPath ( ax , shift , tickSign ) ,
274
274
transFn : transFn
275
275
} ) ;
276
276
277
277
Axes . drawLabels ( gd , ax , {
278
278
vals : vals ,
279
- layer : bulletaxis ,
279
+ layer : axisLayer ,
280
280
transFn : transFn ,
281
281
labelFns : Axes . makeLabelFns ( ax , shift )
282
282
} ) ;
@@ -306,7 +306,7 @@ function drawBulletGauge(gd, plotGroup, cd, gaugeOpts) {
306
306
. attr ( 'height' , innerBulletHeight )
307
307
. attr ( 'y' , ( bulletHeight - innerBulletHeight ) / 2 )
308
308
. call ( styleShape ) ;
309
- if ( hasTransition ) {
309
+ if ( hasTransition ( transitionOpts ) ) {
310
310
fgBullet . select ( 'rect' )
311
311
. transition ( )
312
312
. duration ( transitionOpts . duration )
@@ -340,21 +340,20 @@ function drawBulletGauge(gd, plotGroup, cd, gaugeOpts) {
340
340
bulletOutline . exit ( ) . remove ( ) ;
341
341
}
342
342
343
- function drawAngularGauge ( gd , plotGroup , cd , gaugeOpts ) {
343
+ function drawAngularGauge ( gd , plotGroup , cd , opts ) {
344
344
var trace = cd [ 0 ] . trace ;
345
345
346
- var size = gaugeOpts . size ;
347
- var radius = gaugeOpts . radius ;
348
- var innerRadius = gaugeOpts . innerRadius ;
349
- var gaugeBg = gaugeOpts . gaugeBg ;
350
- var gaugeOutline = gaugeOpts . gaugeOutline ;
346
+ var size = opts . size ;
347
+ var radius = opts . radius ;
348
+ var innerRadius = opts . innerRadius ;
349
+ var gaugeBg = opts . gaugeBg ;
350
+ var gaugeOutline = opts . gaugeOutline ;
351
351
var gaugePosition = [ size . l + size . w / 2 , size . t + size . h / 2 + radius / 2 ] ;
352
- var angularGauge = gaugeOpts . angularGauge ;
353
- var angularaxisLayer = gaugeOpts . angularaxisLayer ;
352
+ var gauge = opts . gauge ;
353
+ var axisLayer = opts . layer ;
354
354
355
- var hasTransition = gaugeOpts . hasTransition ;
356
- var transitionOpts = gaugeOpts . transitionOpts ;
357
- var onComplete = gaugeOpts . onComplete ;
355
+ var transitionOpts = opts . transitionOpts ;
356
+ var onComplete = opts . onComplete ;
358
357
359
358
// circular gauge
360
359
var theta = Math . PI / 2 ;
@@ -385,18 +384,17 @@ function drawAngularGauge(gd, plotGroup, cd, gaugeOpts) {
385
384
386
385
// preparing axis
387
386
var ax , vals , transFn , tickSign ;
388
- var opts = trace . gauge . axis ;
389
387
390
388
// Enter gauge and axis
391
- angularGauge . enter ( ) . append ( 'g' ) . classed ( 'angular' , true ) ;
392
- angularGauge . attr ( 'transform' , strTranslate ( gaugePosition [ 0 ] , gaugePosition [ 1 ] ) ) ;
389
+ gauge . enter ( ) . append ( 'g' ) . classed ( 'angular' , true ) ;
390
+ gauge . attr ( 'transform' , strTranslate ( gaugePosition [ 0 ] , gaugePosition [ 1 ] ) ) ;
393
391
394
- angularaxisLayer . enter ( ) . append ( 'g' )
392
+ axisLayer . enter ( ) . append ( 'g' )
395
393
. classed ( 'angularaxis' , true )
396
394
. classed ( 'crisp' , true ) ;
397
- angularaxisLayer . selectAll ( 'g.' + 'xangularaxis' + 'tick,path,text' ) . remove ( ) ;
395
+ axisLayer . selectAll ( 'g.' + 'xangularaxis' + 'tick,path,text' ) . remove ( ) ;
398
396
399
- ax = mockAxis ( gd , opts ) ;
397
+ ax = mockAxis ( gd , trace . gauge . axis ) ;
400
398
ax . type = 'linear' ;
401
399
ax . range = trace . gauge . axis . range ;
402
400
ax . _id = 'xangularaxis' ; // or 'y', but I don't think this makes a difference here
@@ -451,31 +449,31 @@ function drawAngularGauge(gd, plotGroup, cd, gaugeOpts) {
451
449
var pad = ( ax . linewidth || 1 ) / 2 ;
452
450
Axes . drawTicks ( gd , ax , {
453
451
vals : vals ,
454
- layer : angularaxisLayer ,
452
+ layer : axisLayer ,
455
453
path : 'M' + ( tickSign * pad ) + ',0h' + ( tickSign * ax . ticklen ) ,
456
454
transFn : transFn2
457
455
} ) ;
458
456
Axes . drawLabels ( gd , ax , {
459
457
vals : vals ,
460
- layer : angularaxisLayer ,
458
+ layer : axisLayer ,
461
459
transFn : transFn ,
462
460
labelFns : labelFns
463
461
} ) ;
464
462
}
465
463
466
464
// Draw background + steps
467
465
var arcs = [ gaugeBg ] . concat ( trace . gauge . steps ) ;
468
- var bgArc = angularGauge . selectAll ( 'g.bg-arc' ) . data ( arcs ) ;
466
+ var bgArc = gauge . selectAll ( 'g.bg-arc' ) . data ( arcs ) ;
469
467
bgArc . enter ( ) . append ( 'g' ) . classed ( 'bg-arc' , true ) . append ( 'path' ) ;
470
468
bgArc . select ( 'path' ) . call ( drawArc ) . call ( styleShape ) ;
471
469
bgArc . exit ( ) . remove ( ) ;
472
470
473
471
// Draw foreground with transition
474
472
var valueArcPathGenerator = arcPathGenerator ( trace . gauge . bar . thickness ) ;
475
- var valueArc = angularGauge . selectAll ( 'g.value-arc' ) . data ( [ trace . gauge . bar ] ) ;
473
+ var valueArc = gauge . selectAll ( 'g.value-arc' ) . data ( [ trace . gauge . bar ] ) ;
476
474
valueArc . enter ( ) . append ( 'g' ) . classed ( 'value-arc' , true ) . append ( 'path' ) ;
477
475
var valueArcPath = valueArc . select ( 'path' ) ;
478
- if ( hasTransition ) {
476
+ if ( hasTransition ( transitionOpts ) ) {
479
477
valueArcPath
480
478
. transition ( )
481
479
. duration ( transitionOpts . duration )
@@ -505,26 +503,26 @@ function drawAngularGauge(gd, plotGroup, cd, gaugeOpts) {
505
503
thickness : trace . gauge . threshold . thickness
506
504
} ) ;
507
505
}
508
- var thresholdArc = angularGauge . selectAll ( 'g.threshold-arc' ) . data ( arcs ) ;
506
+ var thresholdArc = gauge . selectAll ( 'g.threshold-arc' ) . data ( arcs ) ;
509
507
thresholdArc . enter ( ) . append ( 'g' ) . classed ( 'threshold-arc' , true ) . append ( 'path' ) ;
510
508
thresholdArc . select ( 'path' ) . call ( drawArc ) . call ( styleShape ) ;
511
509
thresholdArc . exit ( ) . remove ( ) ;
512
510
513
511
// Draw border last
514
- var gaugeBorder = angularGauge . selectAll ( 'g.gauge-outline' ) . data ( [ gaugeOutline ] ) ;
512
+ var gaugeBorder = gauge . selectAll ( 'g.gauge-outline' ) . data ( [ gaugeOutline ] ) ;
515
513
gaugeBorder . enter ( ) . append ( 'g' ) . classed ( 'gauge-outline' , true ) . append ( 'path' ) ;
516
514
gaugeBorder . select ( 'path' ) . call ( drawArc ) . call ( styleShape ) ;
517
515
gaugeBorder . exit ( ) . remove ( ) ;
518
516
}
519
517
520
518
function drawNumbers ( gd , plotGroup , cd , opts ) {
521
519
var trace = cd [ 0 ] . trace ;
520
+
522
521
var numbersX = opts . numbersX ;
523
522
var numbersY = opts . numbersY ;
524
523
var numbersAlign = trace . align || 'center' ;
525
524
var numbersAnchor = anchor [ numbersAlign ] ;
526
525
527
- var hasTransition = opts . hasTransition ;
528
526
var transitionOpts = opts . transitionOpts ;
529
527
var onComplete = opts . onComplete ;
530
528
@@ -582,7 +580,8 @@ function drawNumbers(gd, plotGroup, cd, opts) {
582
580
function writeNumber ( ) {
583
581
number . text ( bignumberPrefix + fmt ( cd [ 0 ] . y ) + bignumberSuffix ) ;
584
582
}
585
- if ( hasTransition ) {
583
+
584
+ if ( hasTransition ( transitionOpts ) ) {
586
585
number
587
586
. transition ( )
588
587
. duration ( transitionOpts . duration )
@@ -635,7 +634,7 @@ function drawNumbers(gd, plotGroup, cd, opts) {
635
634
. call ( Color . fill , deltaFill ( cd [ 0 ] ) ) ;
636
635
}
637
636
638
- if ( hasTransition ) {
637
+ if ( hasTransition ( transitionOpts ) ) {
639
638
delta
640
639
. transition ( )
641
640
. duration ( transitionOpts . duration )
0 commit comments