@@ -72,6 +72,20 @@ describe('Pie defaults', function() {
7272        var  out  =  _supply ( { type : 'pie' ,  values : [ 1 ,  2 ] ,  textfont : { color : 'blue' } } ,  { font : { color : 'red' } } ) ; 
7373        expect ( out . insidetextfont . color ) . toBe ( 'blue' ) ; 
7474    } ) ; 
75+ 
76+     it ( 'should only coerce *automargin* if there are outside labels' ,  function ( )  { 
77+         var  out  =  _supply ( { type : 'pie' ,  labels : [ 'A' ,  'B' ] ,  values : [ 1 ,  2 ] ,  automargin : true } ) ; 
78+         expect ( out . automargin ) . toBe ( true ,  'dflt textposition' ) ; 
79+ 
80+         var  out2  =  _supply ( { type : 'pie' ,  labels : [ 'A' ,  'B' ] ,  values : [ 1 ,  2 ] ,  automargin : true ,  textposition : 'inside' } ) ; 
81+         expect ( out2 . automargin ) . toBe ( undefined ,  'textposition inside' ) ; 
82+ 
83+         var  out3  =  _supply ( { type : 'pie' ,  labels : [ 'A' ,  'B' ] ,  values : [ 1 ,  2 ] ,  automargin : true ,  textposition : 'none' } ) ; 
84+         expect ( out3 . automargin ) . toBe ( undefined ,  'textposition none' ) ; 
85+ 
86+         var  out4  =  _supply ( { type : 'pie' ,  labels : [ 'A' ,  'B' ] ,  values : [ 1 ,  2 ] ,  automargin : true ,  textposition : 'outside' } ) ; 
87+         expect ( out4 . automargin ) . toBe ( true ,  'textposition outside' ) ; 
88+     } ) ; 
7589} ) ; 
7690
7791describe ( 'Pie traces' ,  function ( )  { 
@@ -864,6 +878,82 @@ describe('Pie traces', function() {
864878        . then ( done ) ; 
865879    } ) ; 
866880
881+     it ( 'should grow and shrink margins under *automargin:true*' ,  function ( done )  { 
882+         var  data  =  [ { 
883+             type : 'pie' , 
884+             values : [ 1 ,  2 ,  3 ,  4 ,  5 ] , 
885+             labels : [ 'apples' ,  'oranges' ,  'blueberries' ,  'lemons' ,  'watermelon' ] , 
886+             textinfo : 'label+text+value+percent' , 
887+             textposition : 'outside' , 
888+             automargin : false 
889+         } ] ; 
890+         var  layout  =  { 
891+             width : 400 ,  height : 400 , 
892+             margin : { t : 0 ,  b : 0 ,  l : 0 ,  r : 0 } , 
893+             showlegend : false 
894+         } ; 
895+ 
896+         var  previousSize ; 
897+         function  assertSize ( msg ,  actual ,  exp )  { 
898+             for ( var  k  in  exp )  { 
899+                 var  parts  =  exp [ k ] . split ( '|' ) ; 
900+                 var  op  =  parts [ 0 ] ; 
901+ 
902+                 var  method  =  { 
903+                     '=' : 'toBe' , 
904+                     '~=' : 'toBeWithin' , 
905+                     grew : 'toBeGreaterThan' , 
906+                     shrunk : 'toBeLessThan' 
907+                 } [ op ] ; 
908+ 
909+                 var  val  =  previousSize [ k ] ; 
910+                 var  msgk  =  msg  +  ' '  +  k  +  ( parts [ 1 ]  ? ' |'  +  parts [ 1 ]  : '' ) ; 
911+                 var  args  =  op  ===  '~='  ? [ val ,  1.1 ,  msgk ]  : [ val ,  msgk ,  '' ] ; 
912+ 
913+                 expect ( actual [ k ] ) [ method ] ( args [ 0 ] ,  args [ 1 ] ,  args [ 2 ] ) ; 
914+             } 
915+         } 
916+ 
917+         function  check ( msg ,  restyleObj ,  exp )  { 
918+             return  function ( )  { 
919+                 return  Plotly . restyle ( gd ,  restyleObj ) . then ( function ( )  { 
920+                     var  gs  =  Lib . extendDeep ( { } ,  gd . _fullLayout . _size ) ; 
921+                     assertSize ( msg ,  gs ,  exp ) ; 
922+                     previousSize  =  gs ; 
923+                 } ) ; 
924+             } ; 
925+         } 
926+ 
927+         Plotly . plot ( gd ,  data ,  layout ) 
928+         . then ( function ( )  { 
929+             var  gs  =  gd . _fullLayout . _size ; 
930+             previousSize  =  Lib . extendDeep ( { } ,  gs ) ; 
931+         } ) 
932+         . then ( check ( 'automargin:true' ,  { automargin : true } ,  { 
933+             t : 'grew' ,  l : 'grew' , 
934+             b : 'grew' ,  r : 'grew' 
935+         } ) ) 
936+         . then ( check ( 'smaller font size' ,  { 'outsidetextfont.size' : 8 } ,  { 
937+             t : 'shrunk' ,  l : 'shrunk' , 
938+             b : 'shrunk' ,  r : 'shrunk' 
939+         } ) ) 
940+         . then ( check ( 'arrayOk textposition' ,  { 
941+             textposition : [ [ 'outside' ,  'outside' ,  'inside' ,  'inside' ,  'outside' ] ] , 
942+             'outsidetextfont.size' : 12 
943+         } ,  { 
944+             t : '~=' ,  l : 'shrunk' , 
945+             b : 'grew' ,  r : 'grew' 
946+         } ) ) 
947+         . then ( check ( 'automargin:false' ,  { automargin : false } ,  { 
948+             t : 'shrunk' ,  l : 'shrunk' , 
949+             b : 'shrunk' ,  r : 'shrunk' 
950+         } ) ) 
951+         . catch ( failTest ) 
952+         . then ( done ) ; 
953+     } ) ; 
954+ } ) ; 
955+ 
956+ describe ( 'Pie texttemplate:' ,  function ( )  { 
867957    checkTextTemplate ( [ { 
868958        type : 'pie' , 
869959        values : [ 1 ,  5 ,  3 ,  2 ] , 
0 commit comments