12
12
var Plotly = require ( '../../plotly' ) ;
13
13
var d3 = require ( 'd3' ) ;
14
14
15
+ var Lib = require ( '../../lib' ) ;
16
+
17
+ var Plots = require ( '../../plots/plots' ) ;
18
+ var Fx = require ( '../../plots/cartesian/graph_interact' ) ;
19
+
20
+ var Color = require ( '../color' ) ;
21
+ var Drawing = require ( '../drawing' ) ;
22
+
15
23
var subTypes = require ( '../../traces/scatter/subtypes' ) ;
16
24
var styleOne = require ( '../../traces/pie/style_one' ) ;
17
25
@@ -33,10 +41,10 @@ legend.supplyLayoutDefaults = function(layoutIn, layoutOut, fullData) {
33
41
if ( legendGetsTrace ( trace ) ) {
34
42
visibleTraces ++ ;
35
43
// always show the legend by default if there's a pie
36
- if ( Plotly . Plots . traceIs ( trace , 'pie' ) ) visibleTraces ++ ;
44
+ if ( Plots . traceIs ( trace , 'pie' ) ) visibleTraces ++ ;
37
45
}
38
46
39
- if ( ( Plotly . Plots . traceIs ( trace , 'bar' ) && layoutOut . barmode === 'stack' ) ||
47
+ if ( ( Plots . traceIs ( trace , 'bar' ) && layoutOut . barmode === 'stack' ) ||
40
48
[ 'tonextx' , 'tonexty' ] . indexOf ( trace . fill ) !== - 1 ) {
41
49
defaultOrder = isGrouped ( { traceorder : defaultOrder } ) ?
42
50
'grouped+reversed' : 'reversed' ;
@@ -49,28 +57,29 @@ legend.supplyLayoutDefaults = function(layoutIn, layoutOut, fullData) {
49
57
}
50
58
51
59
function coerce ( attr , dflt ) {
52
- return Plotly . Lib . coerce ( containerIn , containerOut ,
60
+ return Lib . coerce ( containerIn , containerOut ,
53
61
legend . layoutAttributes , attr , dflt ) ;
54
62
}
55
63
56
- var showLegend = Plotly . Lib . coerce ( layoutIn , layoutOut ,
57
- Plotly . Plots . layoutAttributes , 'showlegend' , visibleTraces > 1 ) ;
64
+ var showLegend = Lib . coerce ( layoutIn , layoutOut ,
65
+ Plots . layoutAttributes , 'showlegend' , visibleTraces > 1 ) ;
58
66
59
67
if ( showLegend === false ) return ;
60
68
61
69
coerce ( 'bgcolor' , layoutOut . paper_bgcolor ) ;
62
70
coerce ( 'bordercolor' ) ;
63
71
coerce ( 'borderwidth' ) ;
64
- Plotly . Lib . coerceFont ( coerce , 'font' , layoutOut . font ) ;
72
+ Lib . coerceFont ( coerce , 'font' , layoutOut . font ) ;
65
73
74
+ coerce ( 'type' ) ;
66
75
coerce ( 'traceorder' , defaultOrder ) ;
67
76
if ( isGrouped ( layoutOut . legend ) ) coerce ( 'tracegroupgap' ) ;
68
77
69
78
coerce ( 'x' ) ;
70
79
coerce ( 'xanchor' ) ;
71
80
coerce ( 'y' ) ;
72
81
coerce ( 'yanchor' ) ;
73
- Plotly . Lib . noneOrAll ( containerIn , containerOut , [ 'x' , 'y' ] ) ;
82
+ Lib . noneOrAll ( containerIn , containerOut , [ 'x' , 'y' ] ) ;
74
83
} ;
75
84
76
85
// -----------------------------------------------------
@@ -88,14 +97,14 @@ legend.lines = function(d){
88
97
fill . enter ( ) . append ( 'path' ) . classed ( 'js-fill' , true ) ;
89
98
fill . exit ( ) . remove ( ) ;
90
99
fill . attr ( 'd' , 'M5,0h30v6h-30z' )
91
- . call ( Plotly . Drawing . fillGroupStyle ) ;
100
+ . call ( Drawing . fillGroupStyle ) ;
92
101
93
102
var line = d3 . select ( this ) . select ( '.legendlines' ) . selectAll ( 'path' )
94
103
. data ( showLine ? [ d ] : [ ] ) ;
95
104
line . enter ( ) . append ( 'path' ) . classed ( 'js-line' , true )
96
105
. attr ( 'd' , 'M5,0h30' ) ;
97
106
line . exit ( ) . remove ( ) ;
98
- line . call ( Plotly . Drawing . lineGroupStyle ) ;
107
+ line . call ( Drawing . lineGroupStyle ) ;
99
108
} ;
100
109
101
110
legend . points = function ( d ) {
@@ -111,7 +120,7 @@ legend.points = function(d){
111
120
// use d0.trace to infer arrayOk attributes
112
121
113
122
function boundVal ( attrIn , arrayToValFn , bounds ) {
114
- var valIn = Plotly . Lib . nestedProperty ( trace , attrIn ) . get ( ) ,
123
+ var valIn = Lib . nestedProperty ( trace , attrIn ) . get ( ) ,
115
124
valToBound = ( Array . isArray ( valIn ) && arrayToValFn ) ?
116
125
arrayToValFn ( valIn ) : valIn ;
117
126
@@ -131,10 +140,10 @@ legend.points = function(d){
131
140
132
141
if ( showMarkers ) {
133
142
dEdit . mc = boundVal ( 'marker.color' , pickFirst ) ;
134
- dEdit . mo = boundVal ( 'marker.opacity' , Plotly . Lib . mean , [ 0.2 , 1 ] ) ;
135
- dEdit . ms = boundVal ( 'marker.size' , Plotly . Lib . mean , [ 2 , 16 ] ) ;
143
+ dEdit . mo = boundVal ( 'marker.opacity' , Lib . mean , [ 0.2 , 1 ] ) ;
144
+ dEdit . ms = boundVal ( 'marker.size' , Lib . mean , [ 2 , 16 ] ) ;
136
145
dEdit . mlc = boundVal ( 'marker.line.color' , pickFirst ) ;
137
- dEdit . mlw = boundVal ( 'marker.line.width' , Plotly . Lib . mean , [ 0 , 5 ] ) ;
146
+ dEdit . mlw = boundVal ( 'marker.line.width' , Lib . mean , [ 0 , 5 ] ) ;
138
147
tEdit . marker = {
139
148
sizeref : 1 ,
140
149
sizemin : 1 ,
@@ -156,8 +165,8 @@ legend.points = function(d){
156
165
dEdit . tf = boundVal ( 'textfont.family' , pickFirst ) ;
157
166
}
158
167
159
- dMod = [ Plotly . Lib . minExtend ( d0 , dEdit ) ] ;
160
- tMod = Plotly . Lib . minExtend ( trace , tEdit ) ;
168
+ dMod = [ Lib . minExtend ( d0 , dEdit ) ] ;
169
+ tMod = Lib . minExtend ( trace , tEdit ) ;
161
170
}
162
171
163
172
var ptgroup = d3 . select ( this ) . select ( 'g.legendpoints' ) ;
@@ -167,7 +176,7 @@ legend.points = function(d){
167
176
pts . enter ( ) . append ( 'path' ) . classed ( 'scatterpts' , true )
168
177
. attr ( 'transform' , 'translate(20,0)' ) ;
169
178
pts . exit ( ) . remove ( ) ;
170
- pts . call ( Plotly . Drawing . pointStyle , tMod ) ;
179
+ pts . call ( Drawing . pointStyle , tMod ) ;
171
180
172
181
// 'mrc' is set in pointStyle and used in textPointStyle:
173
182
// constrain it here
@@ -179,7 +188,7 @@ legend.points = function(d){
179
188
. append ( 'g' ) . classed ( 'pointtext' , true )
180
189
. append ( 'text' ) . attr ( 'transform' , 'translate(20,0)' ) ;
181
190
txt . exit ( ) . remove ( ) ;
182
- txt . selectAll ( 'text' ) . call ( Plotly . Drawing . textPointStyle , tMod ) ;
191
+ txt . selectAll ( 'text' ) . call ( Drawing . textPointStyle , tMod ) ;
183
192
184
193
} ;
185
194
@@ -189,7 +198,7 @@ legend.bars = function(d){
189
198
markerLine = marker . line || { } ,
190
199
barpath = d3 . select ( this ) . select ( 'g.legendpoints' )
191
200
. selectAll ( 'path.legendbar' )
192
- . data ( Plotly . Plots . traceIs ( trace , 'bar' ) ? [ d ] : [ ] ) ;
201
+ . data ( Plots . traceIs ( trace , 'bar' ) ? [ d ] : [ ] ) ;
193
202
barpath . enter ( ) . append ( 'path' ) . classed ( 'legendbar' , true )
194
203
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
195
204
. attr ( 'transform' , 'translate(20,0)' ) ;
@@ -198,9 +207,9 @@ legend.bars = function(d){
198
207
var w = ( d . mlw + 1 || markerLine . width + 1 ) - 1 ,
199
208
p = d3 . select ( this ) ;
200
209
p . style ( 'stroke-width' , w + 'px' )
201
- . call ( Plotly . Color . fill , d . mc || marker . color ) ;
210
+ . call ( Color . fill , d . mc || marker . color ) ;
202
211
if ( w ) {
203
- p . call ( Plotly . Color . stroke , d . mlc || markerLine . color ) ;
212
+ p . call ( Color . stroke , d . mlc || markerLine . color ) ;
204
213
}
205
214
} ) ;
206
215
} ;
@@ -209,7 +218,7 @@ legend.boxes = function(d){
209
218
var trace = d [ 0 ] . trace ,
210
219
pts = d3 . select ( this ) . select ( 'g.legendpoints' )
211
220
. selectAll ( 'path.legendbox' )
212
- . data ( Plotly . Plots . traceIs ( trace , 'box' ) && trace . visible ? [ d ] : [ ] ) ;
221
+ . data ( Plots . traceIs ( trace , 'box' ) && trace . visible ? [ d ] : [ ] ) ;
213
222
pts . enter ( ) . append ( 'path' ) . classed ( 'legendbox' , true )
214
223
// if we want the median bar, prepend M6,0H-6
215
224
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
@@ -219,9 +228,9 @@ legend.boxes = function(d){
219
228
var w = ( d . lw + 1 || trace . line . width + 1 ) - 1 ,
220
229
p = d3 . select ( this ) ;
221
230
p . style ( 'stroke-width' , w + 'px' )
222
- . call ( Plotly . Color . fill , d . fc || trace . fillcolor ) ;
231
+ . call ( Color . fill , d . fc || trace . fillcolor ) ;
223
232
if ( w ) {
224
- p . call ( Plotly . Color . stroke , d . lc || trace . line . color ) ;
233
+ p . call ( Color . stroke , d . lc || trace . line . color ) ;
225
234
}
226
235
} ) ;
227
236
} ;
@@ -230,7 +239,7 @@ legend.pie = function(d) {
230
239
var trace = d [ 0 ] . trace ,
231
240
pts = d3 . select ( this ) . select ( 'g.legendpoints' )
232
241
. selectAll ( 'path.legendpie' )
233
- . data ( Plotly . Plots . traceIs ( trace , 'pie' ) && trace . visible ? [ d ] : [ ] ) ;
242
+ . data ( Plots . traceIs ( trace , 'pie' ) && trace . visible ? [ d ] : [ ] ) ;
234
243
pts . enter ( ) . append ( 'path' ) . classed ( 'legendpie' , true )
235
244
. attr ( 'd' , 'M6,6H-6V-6H6Z' )
236
245
. attr ( 'transform' , 'translate(20,0)' ) ;
@@ -277,7 +286,7 @@ legend.style = function(s) {
277
286
legend . texts = function ( context , td , d , i , traces ) {
278
287
var fullLayout = td . _fullLayout ,
279
288
trace = d [ 0 ] . trace ,
280
- isPie = Plotly . Plots . traceIs ( trace , 'pie' ) ,
289
+ isPie = Plots . traceIs ( trace , 'pie' ) ,
281
290
traceIndex = trace . index ,
282
291
name = isPie ? d [ 0 ] . label : trace . name ;
283
292
@@ -289,7 +298,7 @@ legend.texts = function(context, td, d, i, traces){
289
298
y : 0
290
299
} )
291
300
. style ( 'text-anchor' , 'start' )
292
- . call ( Plotly . Drawing . font , fullLayout . legend . font )
301
+ . call ( Drawing . font , fullLayout . legend . font )
293
302
. text ( name )
294
303
. attr ( { 'data-unformatted' : name } ) ;
295
304
@@ -319,7 +328,7 @@ legend.texts = function(context, td, d, i, traces){
319
328
// -----------------------------------------------------
320
329
321
330
function legendGetsTrace ( trace ) {
322
- return trace . visible && Plotly . Plots . traceIs ( trace , 'showLegend' ) ;
331
+ return trace . visible && Plots . traceIs ( trace , 'showLegend' ) ;
323
332
}
324
333
325
334
function isGrouped ( legendLayout ) {
@@ -365,7 +374,7 @@ legend.getLegendData = function(calcdata, opts) {
365
374
366
375
if ( ! legendGetsTrace ( trace ) || ! trace . showlegend ) continue ;
367
376
368
- if ( Plotly . Plots . traceIs ( trace , 'pie' ) ) {
377
+ if ( Plots . traceIs ( trace , 'pie' ) ) {
369
378
if ( ! slicesShown [ lgroup ] ) slicesShown [ lgroup ] = { } ;
370
379
for ( j = 0 ; j < cd . length ; j ++ ) {
371
380
labelj = cd [ j ] . label ;
@@ -426,7 +435,7 @@ legend.draw = function(td) {
426
435
427
436
if ( ! fullLayout . showlegend || ! legendData . length ) {
428
437
fullLayout . _infolayer . selectAll ( '.legend' ) . remove ( ) ;
429
- Plotly . Plots . autoMargin ( td , 'legend' ) ;
438
+ Plots . autoMargin ( td , 'legend' ) ;
430
439
return ;
431
440
}
432
441
@@ -443,8 +452,8 @@ legend.draw = function(td) {
443
452
bgRect . enter ( 0 ) . append ( 'rect' )
444
453
. attr ( 'class' , 'bg' ) ;
445
454
bgRect
446
- . call ( Plotly . Color . stroke , opts . bordercolor )
447
- . call ( Plotly . Color . fill , opts . bgcolor )
455
+ . call ( Color . stroke , opts . bordercolor )
456
+ . call ( Color . fill , opts . bgcolor )
448
457
. style ( 'stroke-width' , opts . borderwidth + 'px' ) ;
449
458
450
459
var groups = legendsvg . selectAll ( 'g.groups' )
@@ -460,15 +469,15 @@ legend.draw = function(td) {
460
469
}
461
470
462
471
var traces = groups . selectAll ( 'g.traces' )
463
- . data ( Plotly . Lib . identity ) ;
472
+ . data ( Lib . identity ) ;
464
473
465
474
traces . enter ( ) . append ( 'g' ) . attr ( 'class' , 'traces' ) ;
466
475
traces . exit ( ) . remove ( ) ;
467
476
468
477
traces . call ( legend . style )
469
478
. style ( 'opacity' , function ( d ) {
470
479
var trace = d [ 0 ] . trace ;
471
- if ( Plotly . Plots . traceIs ( trace , 'pie' ) ) {
480
+ if ( Plots . traceIs ( trace , 'pie' ) ) {
472
481
return hiddenSlices . indexOf ( d [ 0 ] . label ) !== - 1 ? 0.5 : 1 ;
473
482
} else {
474
483
return trace . visible === 'legendonly' ? 0.5 : 1 ;
@@ -483,7 +492,7 @@ legend.draw = function(td) {
483
492
. classed ( 'legendtoggle' , true )
484
493
. style ( 'cursor' , 'pointer' )
485
494
. attr ( 'pointer-events' , 'all' )
486
- . call ( Plotly . Color . fill , 'rgba(0,0,0,0)' ) ;
495
+ . call ( Color . fill , 'rgba(0,0,0,0)' ) ;
487
496
traceToggle . on ( 'click' , function ( ) {
488
497
if ( td . _dragged ) return ;
489
498
@@ -494,7 +503,7 @@ legend.draw = function(td) {
494
503
tracei ,
495
504
newVisible ;
496
505
497
- if ( Plotly . Plots . traceIs ( trace , 'pie' ) ) {
506
+ if ( Plots . traceIs ( trace , 'pie' ) ) {
498
507
var thisLabel = d [ 0 ] . label ,
499
508
newHiddenSlices = hiddenSlices . slice ( ) ,
500
509
thisLabelIndex = newHiddenSlices . indexOf ( thisLabel ) ;
@@ -531,31 +540,31 @@ legend.draw = function(td) {
531
540
lw ,
532
541
lh ;
533
542
534
- Plotly . Fx . dragElement ( {
543
+ Fx . dragElement ( {
535
544
element : legendsvg . node ( ) ,
536
545
prepFn : function ( ) {
537
546
x0 = Number ( legendsvg . attr ( 'x' ) ) ;
538
547
y0 = Number ( legendsvg . attr ( 'y' ) ) ;
539
548
lw = Number ( legendsvg . attr ( 'width' ) ) ;
540
549
lh = Number ( legendsvg . attr ( 'height' ) ) ;
541
- Plotly . Fx . setCursor ( legendsvg ) ;
550
+ Fx . setCursor ( legendsvg ) ;
542
551
} ,
543
552
moveFn : function ( dx , dy ) {
544
553
var gs = td . _fullLayout . _size ;
545
554
546
- legendsvg . call ( Plotly . Drawing . setPosition , x0 + dx , y0 + dy ) ;
555
+ legendsvg . call ( Drawing . setPosition , x0 + dx , y0 + dy ) ;
547
556
548
- xf = Plotly . Fx . dragAlign ( x0 + dx , lw , gs . l , gs . l + gs . w ,
557
+ xf = Fx . dragAlign ( x0 + dx , lw , gs . l , gs . l + gs . w ,
549
558
opts . xanchor ) ;
550
- yf = Plotly . Fx . dragAlign ( y0 + dy + lh , - lh , gs . t + gs . h , gs . t ,
559
+ yf = Fx . dragAlign ( y0 + dy + lh , - lh , gs . t + gs . h , gs . t ,
551
560
opts . yanchor ) ;
552
561
553
- var csr = Plotly . Fx . dragCursors ( xf , yf ,
562
+ var csr = Fx . dragCursors ( xf , yf ,
554
563
opts . xanchor , opts . yanchor ) ;
555
- Plotly . Fx . setCursor ( legendsvg , csr ) ;
564
+ Fx . setCursor ( legendsvg , csr ) ;
556
565
} ,
557
566
doneFn : function ( dragged ) {
558
- Plotly . Fx . setCursor ( legendsvg ) ;
567
+ Fx . setCursor ( legendsvg ) ;
559
568
if ( dragged && xf !== undefined && yf !== undefined ) {
560
569
Plotly . relayout ( td , { 'legend.x' : xf , 'legend.y' : yf } ) ;
561
570
}
@@ -583,7 +592,7 @@ legend.repositionLegend = function(td, traces){
583
592
tspans = g . selectAll ( '.legendtext>tspan' ) ,
584
593
tHeight = opts . font . size * 1.3 ,
585
594
tLines = tspans [ 0 ] . length || 1 ,
586
- tWidth = text . node ( ) && Plotly . Drawing . bBox ( text . node ( ) ) . width ,
595
+ tWidth = text . node ( ) && Drawing . bBox ( text . node ( ) ) . width ,
587
596
mathjaxGroup = g . select ( 'g[class*=math-group]' ) ,
588
597
textY ,
589
598
tHeightFull ;
@@ -594,7 +603,7 @@ legend.repositionLegend = function(td, traces){
594
603
}
595
604
596
605
if ( mathjaxGroup . node ( ) ) {
597
- var mathjaxBB = Plotly . Drawing . bBox ( mathjaxGroup . node ( ) ) ;
606
+ var mathjaxBB = Drawing . bBox ( mathjaxGroup . node ( ) ) ;
598
607
tHeight = mathjaxBB . height ;
599
608
tWidth = mathjaxBB . width ;
600
609
mathjaxGroup . attr ( 'transform' , 'translate(0,' + ( tHeight / 4 ) + ')' ) ;
@@ -664,13 +673,13 @@ legend.repositionLegend = function(td, traces){
664
673
ly = Math . round ( ly ) ;
665
674
666
675
fullLayout . _infolayer . selectAll ( 'svg.legend' )
667
- . call ( Plotly . Drawing . setRect , lx , ly , legendwidth , legendheight ) ;
676
+ . call ( Drawing . setRect , lx , ly , legendwidth , legendheight ) ;
668
677
fullLayout . _infolayer . selectAll ( 'svg.legend .bg' )
669
- . call ( Plotly . Drawing . setRect , borderwidth / 2 , borderwidth / 2 ,
678
+ . call ( Drawing . setRect , borderwidth / 2 , borderwidth / 2 ,
670
679
legendwidth - borderwidth , legendheight - borderwidth ) ;
671
680
672
681
// lastly check if the margin auto-expand has changed
673
- Plotly . Plots . autoMargin ( td , 'legend' , {
682
+ Plots . autoMargin ( td , 'legend' , {
674
683
x : opts . x ,
675
684
y : opts . y ,
676
685
l : legendwidth * ( { right :1 , center :0.5 } [ xanchor ] || 0 ) ,
0 commit comments