99
1010'use strict' ;
1111
12- var Plotly = require ( '../../plotly' ) ;
1312var isNumeric = require ( 'fast-isnumeric' ) ;
1413
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+
1521var shapes = module . exports = { } ;
1622
1723shapes . layoutAttributes = require ( './attributes' ) ;
@@ -29,9 +35,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
2935 var shapeOut = { } ;
3036
3137 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 ) ;
3539 }
3640
3741 coerce ( 'opacity' ) ;
@@ -49,13 +53,13 @@ function handleShapeDefaults(shapeIn, fullLayout) {
4953 tdMock = { _fullLayout : fullLayout } ;
5054
5155 // xref, yref
52- var axRef = Plotly . Axes . coerceRef ( shapeIn , shapeOut , tdMock , axLetter ) ;
56+ var axRef = Axes . coerceRef ( shapeIn , shapeOut , tdMock , axLetter ) ;
5357
5458 if ( shapeType !== 'path' ) {
5559 var dflt0 = 0.25 ,
5660 dflt1 = 0.75 ;
5761 if ( axRef !== 'paper' ) {
58- var ax = Plotly . Axes . getFromId ( tdMock , axRef ) ,
62+ var ax = Axes . getFromId ( tdMock , axRef ) ,
5963 convertFn = linearToData ( ax ) ;
6064 dflt0 = convertFn ( ax . range [ 0 ] + dflt0 * ( ax . range [ 1 ] - ax . range [ 0 ] ) ) ;
6165 dflt1 = convertFn ( ax . range [ 0 ] + dflt1 * ( ax . range [ 1 ] - ax . range [ 0 ] ) ) ;
@@ -69,7 +73,7 @@ function handleShapeDefaults(shapeIn, fullLayout) {
6973 if ( shapeType === 'path' ) {
7074 coerce ( 'path' ) ;
7175 } else {
72- Plotly . Lib . noneOrAll ( shapeIn , shapeOut , [ 'x0' , 'x1' , 'y0' , 'y1' ] ) ;
76+ Lib . noneOrAll ( shapeIn , shapeOut , [ 'x0' , 'x1' , 'y0' , 'y1' ] ) ;
7377 }
7478
7579 return shapeOut ;
@@ -140,7 +144,7 @@ shapes.draw = function(gd, index, opt, value) {
140144 deleteShape ( gd , index ) ;
141145 return ;
142146 }
143- else if ( value === 'add' || Plotly . Lib . isPlainObject ( value ) ) {
147+ else if ( value === 'add' || Lib . isPlainObject ( value ) ) {
144148 insertShape ( gd , index , value ) ;
145149 }
146150 }
@@ -187,8 +191,8 @@ function deleteShape(gd, index) {
187191function insertShape ( gd , index , newShape ) {
188192 gd . _fullLayout . shapes . splice ( index , 0 , { } ) ;
189193
190- var rule = Plotly . Lib . isPlainObject ( newShape ) ?
191- Plotly . Lib . extendFlat ( { } , newShape ) :
194+ var rule = Lib . isPlainObject ( newShape ) ?
195+ Lib . extendFlat ( { } , newShape ) :
192196 { text : 'New text' } ;
193197
194198 if ( gd . layout . shapes ) {
@@ -225,12 +229,12 @@ function updateShape(gd, index, opt, value) {
225229 // alter the input shape as requested
226230 var optionsEdit = { } ;
227231 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 ;
229233
230234 var optionKeys = Object . keys ( optionsEdit ) ;
231235 for ( i = 0 ; i < optionsEdit . length ; i ++ ) {
232236 var k = optionKeys [ i ] ;
233- Plotly . Lib . nestedProperty ( optionsIn , k ) . set ( optionsEdit [ k ] ) ;
237+ Lib . nestedProperty ( optionsIn , k ) . set ( optionsEdit [ k ] ) ;
234238 }
235239
236240 var posAttrs = [ 'x0' , 'x1' , 'y0' , 'y1' ] ;
@@ -247,10 +251,10 @@ function updateShape(gd, index, opt, value) {
247251 }
248252
249253 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 ) ) ,
254258 position = optionsIn [ posAttr ] ,
255259 linearizedPosition ;
256260
@@ -295,13 +299,12 @@ function updateShape(gd, index, opt, value) {
295299 var path = gd . _fullLayout . _shapelayer . append ( 'path' )
296300 . attr ( attrs )
297301 . 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 ) ;
301305
302306 if ( clipAxes ) {
303- path . call ( Plotly . Drawing . setClipUrl ,
304- 'clip' + gd . _fullLayout . _uid + clipAxes ) ;
307+ path . call ( Drawing . setClipUrl , 'clip' + gd . _fullLayout . _uid + clipAxes ) ;
305308 }
306309}
307310
@@ -311,8 +314,8 @@ function decodeDate(convertToPx) {
311314
312315function shapePath ( gd , options ) {
313316 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 ) ,
316319 gs = gd . _fullLayout . _size ,
317320 x2l ,
318321 x2p ,
@@ -450,14 +453,14 @@ shapes.calcAutorange = function(gd) {
450453 shape = shapeList [ i ] ;
451454 ppad = shape . line . width / 2 ;
452455 if ( shape . xref !== 'paper' ) {
453- ax = Plotly . Axes . getFromId ( gd , shape . xref ) ;
456+ ax = Axes . getFromId ( gd , shape . xref ) ;
454457 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 } ) ;
456459 }
457460 if ( shape . yref !== 'paper' ) {
458- ax = Plotly . Axes . getFromId ( gd , shape . yref ) ;
461+ ax = Axes . getFromId ( gd , shape . yref ) ;
459462 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 } ) ;
461464 }
462465 }
463466} ;
0 commit comments