9
9
10
10
'use strict' ;
11
11
12
- var Plotly = require ( '../../plotly' ) ;
13
12
var isNumeric = require ( 'fast-isnumeric' ) ;
14
13
14
+ var Plotly = require ( '../../plotly' ) ;
15
+ var Lib = require ( '../../lib' ) ;
16
+ var Axes = require ( '../../plots/cartesian/axes' ) ;
17
+ var Color = require ( '../color' ) ;
18
+ var Drawing = require ( '../drawing' ) ;
19
+
20
+
15
21
var shapes = module . exports = { } ;
16
22
17
23
shapes . layoutAttributes = require ( './attributes' ) ;
@@ -29,9 +35,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
29
35
var shapeOut = { } ;
30
36
31
37
function coerce ( attr , dflt ) {
32
- return Plotly . Lib . coerce ( shapeIn , shapeOut ,
33
- shapes . layoutAttributes ,
34
- attr , dflt ) ;
38
+ return Lib . coerce ( shapeIn , shapeOut , shapes . layoutAttributes , attr , dflt ) ;
35
39
}
36
40
37
41
coerce ( 'opacity' ) ;
@@ -49,13 +53,13 @@ function handleShapeDefaults(shapeIn, fullLayout) {
49
53
tdMock = { _fullLayout : fullLayout } ;
50
54
51
55
// xref, yref
52
- var axRef = Plotly . Axes . coerceRef ( shapeIn , shapeOut , tdMock , axLetter ) ;
56
+ var axRef = Axes . coerceRef ( shapeIn , shapeOut , tdMock , axLetter ) ;
53
57
54
58
if ( shapeType !== 'path' ) {
55
59
var dflt0 = 0.25 ,
56
60
dflt1 = 0.75 ;
57
61
if ( axRef !== 'paper' ) {
58
- var ax = Plotly . Axes . getFromId ( tdMock , axRef ) ,
62
+ var ax = Axes . getFromId ( tdMock , axRef ) ,
59
63
convertFn = linearToData ( ax ) ;
60
64
dflt0 = convertFn ( ax . range [ 0 ] + dflt0 * ( ax . range [ 1 ] - ax . range [ 0 ] ) ) ;
61
65
dflt1 = convertFn ( ax . range [ 0 ] + dflt1 * ( ax . range [ 1 ] - ax . range [ 0 ] ) ) ;
@@ -69,7 +73,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
69
73
if ( shapeType === 'path' ) {
70
74
coerce ( 'path' ) ;
71
75
} else {
72
- Plotly . Lib . noneOrAll ( shapeIn , shapeOut , [ 'x0' , 'x1' , 'y0' , 'y1' ] ) ;
76
+ Lib . noneOrAll ( shapeIn , shapeOut , [ 'x0' , 'x1' , 'y0' , 'y1' ] ) ;
73
77
}
74
78
75
79
return shapeOut ;
@@ -140,7 +144,7 @@ shapes.draw = function(gd, index, opt, value) {
140
144
deleteShape ( gd , index ) ;
141
145
return ;
142
146
}
143
- else if ( value === 'add' || Plotly . Lib . isPlainObject ( value ) ) {
147
+ else if ( value === 'add' || Lib . isPlainObject ( value ) ) {
144
148
insertShape ( gd , index , value ) ;
145
149
}
146
150
}
@@ -187,8 +191,8 @@ function deleteShape(gd, index) {
187
191
function insertShape ( gd , index , newShape ) {
188
192
gd . _fullLayout . shapes . splice ( index , 0 , { } ) ;
189
193
190
- var rule = Plotly . Lib . isPlainObject ( newShape ) ?
191
- Plotly . Lib . extendFlat ( { } , newShape ) :
194
+ var rule = Lib . isPlainObject ( newShape ) ?
195
+ Lib . extendFlat ( { } , newShape ) :
192
196
{ text : 'New text' } ;
193
197
194
198
if ( gd . layout . shapes ) {
@@ -225,12 +229,12 @@ function updateShape(gd, index, opt, value) {
225
229
// alter the input shape as requested
226
230
var optionsEdit = { } ;
227
231
if ( typeof opt === 'string' && opt ) optionsEdit [ opt ] = value ;
228
- else if ( Plotly . Lib . isPlainObject ( opt ) ) optionsEdit = opt ;
232
+ else if ( Lib . isPlainObject ( opt ) ) optionsEdit = opt ;
229
233
230
234
var optionKeys = Object . keys ( optionsEdit ) ;
231
235
for ( i = 0 ; i < optionsEdit . length ; i ++ ) {
232
236
var k = optionKeys [ i ] ;
233
- Plotly . Lib . nestedProperty ( optionsIn , k ) . set ( optionsEdit [ k ] ) ;
237
+ Lib . nestedProperty ( optionsIn , k ) . set ( optionsEdit [ k ] ) ;
234
238
}
235
239
236
240
var posAttrs = [ 'x0' , 'x1' , 'y0' , 'y1' ] ;
@@ -247,10 +251,10 @@ function updateShape(gd, index, opt, value) {
247
251
}
248
252
249
253
var axLetter = posAttr . charAt ( 0 ) ,
250
- axOld = Plotly . Axes . getFromId ( gd ,
251
- Plotly . Axes . coerceRef ( oldRef , { } , gd , axLetter ) ) ,
252
- axNew = Plotly . Axes . getFromId ( gd ,
253
- Plotly . Axes . coerceRef ( optionsIn , { } , gd , axLetter ) ) ,
254
+ axOld = Axes . getFromId ( gd ,
255
+ Axes . coerceRef ( oldRef , { } , gd , axLetter ) ) ,
256
+ axNew = Axes . getFromId ( gd ,
257
+ Axes . coerceRef ( optionsIn , { } , gd , axLetter ) ) ,
254
258
position = optionsIn [ posAttr ] ,
255
259
linearizedPosition ;
256
260
@@ -295,13 +299,12 @@ function updateShape(gd, index, opt, value) {
295
299
var path = gd . _fullLayout . _shapelayer . append ( 'path' )
296
300
. attr ( attrs )
297
301
. style ( 'opacity' , options . opacity )
298
- . call ( Plotly . Color . stroke , lineColor )
299
- . call ( Plotly . Color . fill , options . fillcolor )
300
- . call ( Plotly . Drawing . dashLine , options . line . dash , options . line . width ) ;
302
+ . call ( Color . stroke , lineColor )
303
+ . call ( Color . fill , options . fillcolor )
304
+ . call ( Drawing . dashLine , options . line . dash , options . line . width ) ;
301
305
302
306
if ( clipAxes ) {
303
- path . call ( Plotly . Drawing . setClipUrl ,
304
- 'clip' + gd . _fullLayout . _uid + clipAxes ) ;
307
+ path . call ( Drawing . setClipUrl , 'clip' + gd . _fullLayout . _uid + clipAxes ) ;
305
308
}
306
309
}
307
310
@@ -311,8 +314,8 @@ function decodeDate(convertToPx) {
311
314
312
315
function shapePath ( gd , options ) {
313
316
var type = options . type ,
314
- xa = Plotly . Axes . getFromId ( gd , options . xref ) ,
315
- ya = Plotly . Axes . getFromId ( gd , options . yref ) ,
317
+ xa = Axes . getFromId ( gd , options . xref ) ,
318
+ ya = Axes . getFromId ( gd , options . yref ) ,
316
319
gs = gd . _fullLayout . _size ,
317
320
x2l ,
318
321
x2p ,
@@ -450,14 +453,14 @@ shapes.calcAutorange = function(gd) {
450
453
shape = shapeList [ i ] ;
451
454
ppad = shape . line . width / 2 ;
452
455
if ( shape . xref !== 'paper' ) {
453
- ax = Plotly . Axes . getFromId ( gd , shape . xref ) ;
456
+ ax = Axes . getFromId ( gd , shape . xref ) ;
454
457
bounds = shapeBounds ( ax , shape . x0 , shape . x1 , shape . path , paramIsX ) ;
455
- if ( bounds ) Plotly . Axes . expand ( ax , bounds , { ppad : ppad } ) ;
458
+ if ( bounds ) Axes . expand ( ax , bounds , { ppad : ppad } ) ;
456
459
}
457
460
if ( shape . yref !== 'paper' ) {
458
- ax = Plotly . Axes . getFromId ( gd , shape . yref ) ;
461
+ ax = Axes . getFromId ( gd , shape . yref ) ;
459
462
bounds = shapeBounds ( ax , shape . y0 , shape . y1 , shape . path , paramIsY ) ;
460
- if ( bounds ) Plotly . Axes . expand ( ax , bounds , { ppad : ppad } ) ;
463
+ if ( bounds ) Axes . expand ( ax , bounds , { ppad : ppad } ) ;
461
464
}
462
465
}
463
466
} ;
0 commit comments