12
12
var d3 = require ( 'd3' ) ;
13
13
14
14
var Plotly = require ( '../../plotly' ) ;
15
+ var Plots = require ( '../../plots/plots' ) ;
16
+ var Axes = require ( '../../plots/cartesian/axes' ) ;
17
+ var Fx = require ( '../../plots/cartesian/graph_interact' ) ;
18
+ var Lib = require ( '../../lib' ) ;
19
+ var Drawing = require ( '../drawing' ) ;
20
+ var Color = require ( '../color' ) ;
21
+
22
+ var handleAxisDefaults = require ( '../../plots/cartesian/axis_defaults' ) ;
23
+ var handleAxisPositionDefaults = require ( '../../plots/cartesian/position_defaults' ) ;
24
+ var axisLayoutAttrs = require ( '../../plots/cartesian/layout_attributes' ) ;
15
25
16
26
var attributes = require ( './attributes' ) ;
17
27
@@ -163,23 +173,19 @@ module.exports = function draw(gd, id) {
163
173
// Coerce w.r.t. Axes layoutAttributes:
164
174
// re-use axes.js logic without updating _fullData
165
175
function coerce ( attr , dflt ) {
166
- return Plotly . Lib . coerce ( cbAxisIn , cbAxisOut ,
167
- Plotly . Axes . layoutAttributes ,
168
- attr , dflt ) ;
176
+ return Lib . coerce ( cbAxisIn , cbAxisOut , axisLayoutAttrs , attr , dflt ) ;
169
177
}
170
178
171
179
// Prepare the Plotly axis object
172
- Plotly . Axes . handleAxisDefaults ( cbAxisIn , cbAxisOut ,
173
- coerce , axisOptions ) ;
174
- Plotly . Axes . handleAxisPositioningDefaults ( cbAxisIn , cbAxisOut ,
175
- coerce , axisOptions ) ;
180
+ handleAxisDefaults ( cbAxisIn , cbAxisOut , coerce , axisOptions ) ;
181
+ handleAxisPositionDefaults ( cbAxisIn , cbAxisOut , coerce , axisOptions ) ;
176
182
177
183
cbAxisOut . _id = 'y' + id ;
178
184
cbAxisOut . _td = gd ;
179
185
180
186
// position can't go in through supplyDefaults
181
187
// because that restricts it to [0,1]
182
- cbAxisOut . position = opts . x + xpadFrac + thickFrac ;
188
+ cbAxisOut . position = opts . x + xpadFrac + thickFrac ;
183
189
184
190
// save for other callers to access this axis
185
191
component . axis = cbAxisOut ;
@@ -196,14 +202,14 @@ module.exports = function draw(gd, id) {
196
202
cbAxisOut . tick0 = opts . levels . start ;
197
203
var dtick = opts . levels . size ;
198
204
// expand if too many contours, so we don't get too many ticks
199
- var autoNtick = Plotly . Lib . constrain (
205
+ var autoNtick = Lib . constrain (
200
206
( yBottomPx - yTopPx ) / 50 , 4 , 15 ) + 1 ,
201
207
dtFactor = ( zrange [ 1 ] - zrange [ 0 ] ) /
202
208
( ( opts . nticks || autoNtick ) * dtick ) ;
203
209
if ( dtFactor > 1 ) {
204
210
var dtexp = Math . pow ( 10 , Math . floor (
205
211
Math . log ( dtFactor ) / Math . LN10 ) ) ;
206
- dtick *= dtexp * Plotly . Lib . roundUp ( dtFactor / dtexp , [ 2 , 5 , 10 ] ) ;
212
+ dtick *= dtexp * Lib . roundUp ( dtFactor / dtexp , [ 2 , 5 , 10 ] ) ;
207
213
// if the contours are at round multiples, reset tick0
208
214
// so they're still at round multiples. Otherwise,
209
215
// keep the first label on the first contour level
@@ -269,7 +275,7 @@ module.exports = function draw(gd, id) {
269
275
parseInt ( titleText . style ( 'font-size' ) , 10 ) * 1.3 ;
270
276
}
271
277
if ( mathJaxNode ) {
272
- titleHeight = Plotly . Drawing . bBox ( mathJaxNode ) . height ;
278
+ titleHeight = Drawing . bBox ( mathJaxNode ) . height ;
273
279
if ( titleHeight > lineSize ) {
274
280
// not entirely sure how mathjax is doing
275
281
// vertical alignment, but this seems to work.
@@ -278,7 +284,7 @@ module.exports = function draw(gd, id) {
278
284
}
279
285
else if ( titleText . node ( ) &&
280
286
! titleText . classed ( 'js-placeholder' ) ) {
281
- titleHeight = Plotly . Drawing . bBox (
287
+ titleHeight = Drawing . bBox (
282
288
titleGroup . node ( ) ) . height ;
283
289
}
284
290
if ( titleHeight ) {
@@ -351,7 +357,7 @@ module.exports = function draw(gd, id) {
351
357
. attr ( 'd' , 'M' + xLeft + ',' +
352
358
( Math . round ( cbAxisOut . c2p ( d ) ) + ( opts . line . width / 2 ) % 1 ) +
353
359
'h' + thickPx )
354
- . call ( Plotly . Drawing . lineGroupStyle ,
360
+ . call ( Drawing . lineGroupStyle ,
355
361
opts . line . width , linecolormap ( d ) , opts . line . dash ) ;
356
362
} ) ;
357
363
@@ -363,7 +369,7 @@ module.exports = function draw(gd, id) {
363
369
( opts . outlinewidth || 0 ) / 2 - ( opts . ticks === 'outside' ? 1 : 0 ) ;
364
370
cbAxisOut . side = 'right' ;
365
371
366
- return Plotly . Axes . doTicks ( gd , cbAxisOut ) ;
372
+ return Axes . doTicks ( gd , cbAxisOut ) ;
367
373
}
368
374
369
375
function positionCB ( ) {
@@ -372,7 +378,7 @@ module.exports = function draw(gd, id) {
372
378
// TODO: why are we redrawing multiple times now with this?
373
379
// I guess autoMargin doesn't like being post-promise?
374
380
var innerWidth = thickPx + opts . outlinewidth / 2 +
375
- Plotly . Drawing . bBox ( cbAxisOut . _axislayer . node ( ) ) . width ;
381
+ Drawing . bBox ( cbAxisOut . _axislayer . node ( ) ) . width ;
376
382
titleEl = titleCont . select ( 'text' ) ;
377
383
if ( titleEl . node ( ) && ! titleEl . classed ( 'js-placeholder' ) ) {
378
384
var mathJaxNode = titleCont
@@ -381,15 +387,15 @@ module.exports = function draw(gd, id) {
381
387
titleWidth ;
382
388
if ( mathJaxNode &&
383
389
[ 'top' , 'bottom' ] . indexOf ( opts . titleside ) !== - 1 ) {
384
- titleWidth = Plotly . Drawing . bBox ( mathJaxNode ) . width ;
390
+ titleWidth = Drawing . bBox ( mathJaxNode ) . width ;
385
391
}
386
392
else {
387
393
// note: the formula below works for all titlesides,
388
394
// (except for top/bottom mathjax, above)
389
395
// but the weird fullLayout._size.l is because the titleunshift
390
396
// transform gets removed by Drawing.bBox
391
397
titleWidth =
392
- Plotly . Drawing . bBox ( titleCont . node ( ) ) . right -
398
+ Drawing . bBox ( titleCont . node ( ) ) . right -
393
399
xLeft - fullLayout . _size . l ;
394
400
}
395
401
innerWidth = Math . max ( innerWidth , titleWidth ) ;
@@ -406,8 +412,8 @@ module.exports = function draw(gd, id) {
406
412
width : Math . max ( outerwidth , 2 ) ,
407
413
height : Math . max ( outerheight + 2 * yExtraPx , 2 )
408
414
} )
409
- . call ( Plotly . Color . fill , opts . bgcolor )
410
- . call ( Plotly . Color . stroke , opts . bordercolor )
415
+ . call ( Color . fill , opts . bgcolor )
416
+ . call ( Color . stroke , opts . bordercolor )
411
417
. style ( { 'stroke-width' : opts . borderwidth } ) ;
412
418
413
419
container . selectAll ( '.cboutline' ) . attr ( {
@@ -417,7 +423,7 @@ module.exports = function draw(gd, id) {
417
423
width : Math . max ( thickPx , 2 ) ,
418
424
height : Math . max ( outerheight - 2 * opts . ypad - titleHeight , 2 )
419
425
} )
420
- . call ( Plotly . Color . stroke , opts . outlinecolor )
426
+ . call ( Color . stroke , opts . outlinecolor )
421
427
. style ( {
422
428
fill : 'None' ,
423
429
'stroke-width' : opts . outlinewidth
@@ -430,7 +436,7 @@ module.exports = function draw(gd, id) {
430
436
'translate(' + ( fullLayout . _size . l - xoffset ) + ',' + fullLayout . _size . t + ')' ) ;
431
437
432
438
//auto margin adjustment
433
- Plotly . Plots . autoMargin ( gd , id , {
439
+ Plots . autoMargin ( gd , id , {
434
440
x : opts . x ,
435
441
y : opts . y ,
436
442
l : outerwidth * ( { right :1 , center :0.5 } [ opts . xanchor ] || 0 ) ,
@@ -440,10 +446,10 @@ module.exports = function draw(gd, id) {
440
446
} ) ;
441
447
}
442
448
443
- var cbDone = Plotly . Lib . syncOrAsync ( [
444
- Plotly . Plots . previousPromises ,
449
+ var cbDone = Lib . syncOrAsync ( [
450
+ Plots . previousPromises ,
445
451
drawAxis ,
446
- Plotly . Plots . previousPromises ,
452
+ Plots . previousPromises ,
447
453
positionCB
448
454
] , gd ) ;
449
455
@@ -455,29 +461,29 @@ module.exports = function draw(gd, id) {
455
461
xf ,
456
462
yf ;
457
463
458
- Plotly . Fx . dragElement ( {
464
+ Fx . dragElement ( {
459
465
element : container . node ( ) ,
460
466
prepFn : function ( ) {
461
467
t0 = container . attr ( 'transform' ) ;
462
- Plotly . Fx . setCursor ( container ) ;
468
+ Fx . setCursor ( container ) ;
463
469
} ,
464
470
moveFn : function ( dx , dy ) {
465
471
var gs = gd . _fullLayout . _size ;
466
472
467
473
container . attr ( 'transform' ,
468
474
t0 + ' ' + 'translate(' + dx + ',' + dy + ')' ) ;
469
475
470
- xf = Plotly . Fx . dragAlign ( xLeftFrac + ( dx / gs . w ) , thickFrac ,
476
+ xf = Fx . dragAlign ( xLeftFrac + ( dx / gs . w ) , thickFrac ,
471
477
0 , 1 , opts . xanchor ) ;
472
- yf = Plotly . Fx . dragAlign ( yBottomFrac - ( dy / gs . h ) , lenFrac ,
478
+ yf = Fx . dragAlign ( yBottomFrac - ( dy / gs . h ) , lenFrac ,
473
479
0 , 1 , opts . yanchor ) ;
474
480
475
- var csr = Plotly . Fx . dragCursors ( xf , yf ,
481
+ var csr = Fx . dragCursors ( xf , yf ,
476
482
opts . xanchor , opts . yanchor ) ;
477
- Plotly . Fx . setCursor ( container , csr ) ;
483
+ Fx . setCursor ( container , csr ) ;
478
484
} ,
479
485
doneFn : function ( dragged ) {
480
- Plotly . Fx . setCursor ( container ) ;
486
+ Fx . setCursor ( container ) ;
481
487
482
488
if ( dragged && xf !== undefined && yf !== undefined ) {
483
489
var idNum = id . substr ( 2 ) ,
@@ -507,8 +513,8 @@ module.exports = function draw(gd, id) {
507
513
508
514
// setter - for multi-part properties,
509
515
// set only the parts that are provided
510
- opts [ name ] = Plotly . Lib . isPlainObject ( opts [ name ] ) ?
511
- Plotly . Lib . extendFlat ( opts [ name ] , v ) :
516
+ opts [ name ] = Lib . isPlainObject ( opts [ name ] ) ?
517
+ Lib . extendFlat ( opts [ name ] , v ) :
512
518
v ;
513
519
514
520
return component ;
0 commit comments