@@ -213,6 +213,46 @@ def _append_view_filters(self, params) -> None:
213213 params [name ] = value
214214
215215
216+ class _ImagePDFCommonExportOptions (_DataExportOptions ):
217+ def __init__ (self , maxage = - 1 , viz_height = None , viz_width = None ):
218+ super ().__init__ (maxage = maxage )
219+ self .viz_height = viz_height
220+ self .viz_width = viz_width
221+
222+ @property
223+ def viz_height (self ):
224+ return self ._viz_height
225+
226+ @viz_height .setter
227+ @property_is_int (range = (0 , sys .maxsize ), allowed = (None ,))
228+ def viz_height (self , value ):
229+ self ._viz_height = value
230+
231+ @property
232+ def viz_width (self ):
233+ return self ._viz_width
234+
235+ @viz_width .setter
236+ @property_is_int (range = (0 , sys .maxsize ), allowed = (None ,))
237+ def viz_width (self , value ):
238+ self ._viz_width = value
239+
240+ def get_query_params (self ) -> dict :
241+ params = super ().get_query_params ()
242+
243+ # XOR. Either both are None or both are not None.
244+ if (self .viz_height is None ) ^ (self .viz_width is None ):
245+ raise ValueError ("viz_height and viz_width must be specified together" )
246+
247+ if self .viz_height is not None :
248+ params ["vizHeight" ] = self .viz_height
249+
250+ if self .viz_width is not None :
251+ params ["vizWidth" ] = self .viz_width
252+
253+ return params
254+
255+
216256class CSVRequestOptions (_DataExportOptions ):
217257 extension = "csv"
218258
@@ -221,15 +261,15 @@ class ExcelRequestOptions(_DataExportOptions):
221261 extension = "xlsx"
222262
223263
224- class ImageRequestOptions (_DataExportOptions ):
264+ class ImageRequestOptions (_ImagePDFCommonExportOptions ):
225265 extension = "png"
226266
227267 # if 'high' isn't specified, the REST API endpoint returns an image with standard resolution
228268 class Resolution :
229269 High = "high"
230270
231- def __init__ (self , imageresolution = None , maxage = - 1 ):
232- super ().__init__ (maxage = maxage )
271+ def __init__ (self , imageresolution = None , maxage = - 1 , viz_height = None , viz_width = None ):
272+ super ().__init__ (maxage = maxage , viz_height = viz_height , viz_width = viz_width )
233273 self .image_resolution = imageresolution
234274
235275 def get_query_params (self ):
@@ -239,7 +279,7 @@ def get_query_params(self):
239279 return params
240280
241281
242- class PDFRequestOptions (_DataExportOptions ):
282+ class PDFRequestOptions (_ImagePDFCommonExportOptions ):
243283 class PageType :
244284 A3 = "a3"
245285 A4 = "a4"
@@ -261,29 +301,9 @@ class Orientation:
261301 Landscape = "landscape"
262302
263303 def __init__ (self , page_type = None , orientation = None , maxage = - 1 , viz_height = None , viz_width = None ):
264- super ().__init__ (maxage = maxage )
304+ super ().__init__ (maxage = maxage , viz_height = viz_height , viz_width = viz_width )
265305 self .page_type = page_type
266306 self .orientation = orientation
267- self .viz_height = viz_height
268- self .viz_width = viz_width
269-
270- @property
271- def viz_height (self ):
272- return self ._viz_height
273-
274- @viz_height .setter
275- @property_is_int (range = (0 , sys .maxsize ), allowed = (None ,))
276- def viz_height (self , value ):
277- self ._viz_height = value
278-
279- @property
280- def viz_width (self ):
281- return self ._viz_width
282-
283- @viz_width .setter
284- @property_is_int (range = (0 , sys .maxsize ), allowed = (None ,))
285- def viz_width (self , value ):
286- self ._viz_width = value
287307
288308 def get_query_params (self ) -> dict :
289309 params = super ().get_query_params ()
@@ -293,14 +313,4 @@ def get_query_params(self) -> dict:
293313 if self .orientation :
294314 params ["orientation" ] = self .orientation
295315
296- # XOR. Either both are None or both are not None.
297- if (self .viz_height is None ) ^ (self .viz_width is None ):
298- raise ValueError ("viz_height and viz_width must be specified together" )
299-
300- if self .viz_height is not None :
301- params ["vizHeight" ] = self .viz_height
302-
303- if self .viz_width is not None :
304- params ["vizWidth" ] = self .viz_width
305-
306316 return params
0 commit comments