@@ -46,7 +46,7 @@ tap.test('parse:', t => {
4646 } )
4747 } )
4848
49- function assertEqualSize ( browserSize , pageSize ) {
49+ function assertEqualSize ( browserSize , pageSize , landscape ) {
5050 // Browser size is always integer pixels
5151 var bW = browserSize . width
5252 var bH = browserSize . height
@@ -64,36 +64,55 @@ tap.test('parse:', t => {
6464 // Round
6565 pW = Math . ceil ( pW )
6666 pH = Math . ceil ( pH )
67- t . equal ( bW , pW , 'browser and page should have the same width' )
68- t . equal ( bH , pH , 'browser and page should have the same height' )
67+ t . equal ( bW , landscape ? pH : pW , 'browser and page should have the same width' )
68+ t . equal ( bH , landscape ? pW : pH , 'browser and page should have the same height' )
6969 }
7070
7171 // Browser size and page size should be the same assuming a DPI of 96
7272 // to make sure plotly.js figures are appropriately sized right away for print
7373 [
74+ // [pageSize defined at top-level?, pageSize, landscape?]
7475 [ true , { height : 1000 , width : 1000 } ] ,
7576 [ true , 'Letter' ] ,
7677 [ false , { height : 1000 , width : 1000 } ] ,
77- [ false , 'Letter' ]
78+ [ false , 'Letter' ] ,
79+ [ true , { height : 1000 , width : 1000 } , true ] ,
80+ [ true , 'Letter' , true ] ,
81+ [ false , { height : 1000 , width : 1000 } , true ] ,
82+ [ false , 'Letter' , true ]
7883 ] . forEach ( arg => {
7984 var toplevel = arg [ 0 ]
8085 var pageSize = arg [ 1 ]
86+ var landscape = arg [ 2 ]
8187 t . test ( `should size window and page properly when ${ toplevel ? '' : 'pdf_options.' } pageSize is given` , t => {
8288 var body = mock ( )
8389 if ( toplevel ) {
8490 body . pageSize = pageSize
91+ body . pdf_options = { }
8592 } else {
8693 body . pdf_options = { pageSize : pageSize }
8794 }
95+ if ( landscape ) body . pdf_options . landscape = landscape
8896 fn ( body , { } , { } , ( errorCode , result ) => {
8997 t . equal ( errorCode , null )
9098 t . same ( result . pdfOptions . pageSize , pageSize )
91- assertEqualSize ( result . browserSize , result . pdfOptions . pageSize )
99+ assertEqualSize ( result . browserSize , result . pdfOptions . pageSize , landscape )
92100 t . end ( )
93101 } )
94102 } )
95103 } )
96104
105+ t . test ( 'pdf_options.pageSize overrides top-level pageSize' , t => {
106+ var body = mock ( )
107+ body . pageSize = { height : 1000 , width : 1000 }
108+ body . pdf_options = { pageSize : { height : 2000 , width : 2000 } }
109+ fn ( body , { } , { } , ( errorCode , result ) => {
110+ t . equal ( errorCode , null )
111+ t . same ( result . browserSize , { height : 8 , width : 8 } )
112+ t . end ( )
113+ } )
114+ } )
115+
97116 t . test ( 'should passthrough pdf_options' , t => {
98117 var body = mock ( )
99118 body . pdf_options = { pageSize : 'Letter' , marginsType : 1 , crazyOptions : true }
0 commit comments