@@ -377,12 +377,19 @@ def update_sheet_raw(sheets_authentication_response, sheet, *updates):
377
377
378
378
@dataclass
379
379
class WorksheetRange :
380
+ """
381
+ A dataclass to represent a range of cells in a worksheet in the one-sided interval [top_left, bottom_right).
382
+ :param worksheet: the gspread.worksheet.Worksheet object
383
+ :param top_left: the top left cell of the range. This cell will be included in the range
384
+ :param bottom_right: the bottom right cell of the range. This cell will not be included in the range
385
+ """
380
386
worksheet : gspread .worksheet .Worksheet
381
387
top_left : gspread .cell .Cell
382
388
bottom_right : gspread .cell .Cell
383
389
384
390
@property
385
391
def range_dict (self ):
392
+ """The range as a dictionary for the sources field in the Google Sheets api"""
386
393
return {
387
394
"sheetId" : self .worksheet .id ,
388
395
"startRowIndex" : self .top_left .row - 1 ,
@@ -399,6 +406,16 @@ def _cell_to_grid_coordinate(cell, worksheet):
399
406
}
400
407
401
408
def add_chart_to_sheet (sheets_authentication_response , sheet , worksheet , chart_type , domain , series , ** chart_args ):
409
+ """
410
+ Add a chart to a specified workshet
411
+ :param sheets_authentication_response: the response from ga.authenticate. Must be for the sheets api v4
412
+ :param sheet: the gspread.Spreadsheet object
413
+ :param worksheet: the gspread.Worksheet object
414
+ :param chart_type: the type of chart to add
415
+ :param domain: the domain of the chart as a WorksheetRange. Must contain either one row or one column
416
+ :param series: the series of the chart as a WorksheetRange. Must contain either one row or one column
417
+ :param chart_args: other arguments to create the chart. See DEFAULT_CHART_ARGS
418
+ """
402
419
complete_chart_args = {** DEFAULT_CHART_ARGS , ** chart_args }
403
420
if complete_chart_args ["chart_position" ] is not None :
404
421
position_dict = {
@@ -415,7 +432,6 @@ def add_chart_to_sheet(sheets_authentication_response, sheet, worksheet, chart_t
415
432
formatted_domains = [
416
433
{
417
434
"domain" : {
418
- #TODO: would be nice to also support column references https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#DataSourceColumnReference
419
435
"sourceRange" : {
420
436
"sources" : [
421
437
domain .range_dict
@@ -425,6 +441,7 @@ def add_chart_to_sheet(sheets_authentication_response, sheet, worksheet, chart_t
425
441
"reversed" : complete_chart_args ["invert_x_axis" ],
426
442
},
427
443
]
444
+
428
445
formatted_series = [
429
446
{
430
447
"series" : {
0 commit comments