
    ~ZiX*                        S r SSKJr  SSKrSSKJr  SSKJr   " S S\5      r	 " S S	\	5      r
 " S
 S\	5      r " S S\5      rg)z"Chart builder and related objects.    )annotationsN)contextmanager)Workbookc                  R   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r	S r
SrU =r$ )_BaseWorkbookWriter   z:Base class for workbook writers, providing shared members.c                6   > [         [        U ]  5         Xl        g )N)superr   __init___chart_data)self
chart_data	__class__s     i/var/www/eduai.edurigo.com/question_generate/ques_gen_env/lib/python3.13/site-packages/pptx/chart/xlsx.pyr   _BaseWorkbookWriter.__init__   s    !413%    c                    [         R                  " 5       nU R                  U5       u  p#U R                  X#5        SSS5        UR	                  5       $ ! , (       d  f       UR	                  5       $ = f)z+bytes for Excel file containing chart_data.N)ioBytesIO_open_worksheet_populate_worksheetgetvaluer   	xlsx_fileworkbook	worksheets       r   	xlsx_blob_BaseWorkbookWriter.xlsx_blob   s\     JJL	!!),0E$$X9 -!!## -,!!##s   A
A0c              #  r   #    [        USS05      nUR                  5       nX#4v   UR                  5         g7f)z
Enable XlsxWriter Worksheet object to be opened, operated on, and
then automatically closed within a `with` statement. A filename or
stream object (such as an `io.BytesIO` instance) is expected as
*xlsx_file*.
	in_memoryTN)r   add_worksheetcloser   s       r   r   #_BaseWorkbookWriter._open_worksheet   s9      IT':;**,	!!s   57c                    [        S5      e)za
Must be overridden by each subclass to provide the particulars of
writing the spreadsheet data.
z!must be provided by each subclass)NotImplementedErrorr   r   r   s      r   r   '_BaseWorkbookWriter._populate_worksheet'   s    
 ""EFFr   )r   )__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r   r   __static_attributes____classcell__)r   s   @r   r   r      s?    D& $ $ 
 
G Gr   r   c                  b    \ rS rSrSr\S 5       rS rS r\	S 5       r
S rS rS	 rS
 rS rSrg)CategoryWorkbookWriter/   z
Determines Excel worksheet layout and can write an Excel workbook from
a CategoryChartData object. Serves as the authority for Excel worksheet
ranges.
c                    U R                   R                  nUR                  S:X  a  [        S5      e[	        [        S5      UR                  -   S-
  5      nUR                  S-   nSX#4-  $ )zd
The Excel worksheet reference to the categories for this chart (not
including the column heading).
r   z!chart data contains no categoriesA   zSheet1!$A$2:$%s$%d)r   
categoriesdepth
ValueErrorchrord
leaf_count)r   r6   	right_col
bottom_rows       r   categories_ref%CategoryWorkbookWriter.categories_ref6   sk     %%00
q @AAC:#3#33a78	**Q.
#y&===r   c                *    SU R                  U5      -  $ )z
Return the Excel worksheet reference to the cell containing the name
for *series*. This also serves as the column heading for the series
values.
zSheet1!$%s$1)_series_col_letterr   seriess     r   series_name_ref&CategoryWorkbookWriter.series_name_refC   s      7 7 ???r   c                b    SR                   " S0 U R                  U5      [        U5      S-   S.D6$ )za
The Excel worksheet reference to the values for this series (not
including the column heading).
z1Sheet1!${col_letter}$2:${col_letter}${bottom_row}r5   )
col_letterr=    )formatrA   lenrB   s     r   
values_ref!CategoryWorkbookWriter.values_refK   s;    
 CII 
"55f=!&kAo
 	
r   c                    U S:  d  U S:  a  [        S5      eSnU (       a<  U S-  nUS:X  a  Sn[        [        S5      U-   S-
  5      nX1-   nU S-
  S-  n U (       a  M<  U$ )zReturn str Excel column reference like 'BQ' for *column_number*.

*column_number* is an int in the range 1-16384 inclusive, where
1 maps to column 'A'.
r5   i @  z&column_number must be in range 1-16384    r   r4   )r8   r9   r:   )column_numbercol_ref	remainderrG   s       r   _column_reference(CategoryWorkbookWriter._column_referenceW   s~     1 5EFF %*IA~	SX	1A56J *G +Q.25M m r   c                H    U R                  X5        U R                  X5        g)aV  
Write the chart data contents to *worksheet* in category chart
layout. Write categories starting in the first column starting in
the second row, and proceeding one column per category level (for
charts having multi-level categories). Write series as columns
starting in the next following column, placing the series title in
the first cell.
N)_write_categories_write_seriesr&   s      r   r   *CategoryWorkbookWriter._populate_worksheetw   s      	x38/r   c                p    SUR                   R                  -   UR                  -   nU R                  U5      $ )zR
The letter of the Excel worksheet column in which the data for a
series appears.
r5   )r6   r7   indexrS   )r   rC   rP   s      r   rA   )CategoryWorkbookWriter._series_col_letter   s4    
 F--333fllB%%m44r   c                    U R                   R                  nUR                  SUR                  05      nUR                  n[        UR                  5       H  u  pgXV-
  S-
  nU R                  X(Xt5        M      g)a  
Write the categories column(s) to *worksheet*. Categories start in
the first column starting in the second row, and proceeding one
column per category level (for charts having multi-level categories).
A date category is formatted as a date. All others are formatted
`General`.

num_formatr5   N)r   r6   
add_formatnumber_formatr7   	enumeratelevels_write_cat_column)	r   r   r   r6   r]   r7   idxlevelcols	            r   rV   (CategoryWorkbookWriter._write_categories   sm     %%00
((,
8P8P)QR
  #J$5$56JC+/C""95E 7r   c                l    UR                  X"S5        U H  u  pVUS-   nUR                  XrXd5        M     g)zl
Write a category column defined by *level* to *worksheet* at offset
*col* and formatted with *num_format*.

   r5   N)
set_columnwrite)r   r   re   rd   r]   offnamerows           r   rb   (CategoryWorkbookWriter._write_cat_column   s7    
 	Sr*IC'COOCd7 r   c                4   U R                   R                  R                  n[        U R                   5       H_  u  pEUR	                  SUR
                  05      nXC-   nUR                  SXuR                  5        UR                  SXuR                  U5        Ma     g)z
Write the series column(s) to *worksheet*. Series start in the column
following the last categories column, placing the series title in the
first cell.
r]   r   r5   N)
r   r6   r7   r`   r^   r_   rj   rl   write_columnvalues)r   r   r   
col_offsetrc   rC   r]   
series_cols           r   rW   $CategoryWorkbookWriter._write_series   s}     %%0066
$T%5%56KC!,,lF<P<P-QRJ)JOOAz;;7""1j--L	 7r   rH   N)r(   r)   r*   r+   r,   r-   r>   rD   rK   staticmethodrS   r   rA   rV   rb   rW   r.   rH   r   r   r1   r1   /   sU     
> 
>@

  >
05F8Mr   r1   c                  6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
XyWorkbookWriter   z
Determines Excel worksheet layout and can write an Excel workbook from XY
chart data. Serves as the authority for Excel worksheet ranges.
c                4    U R                  U5      S-   nSU-  $ )z
Return the Excel worksheet reference to the cell containing the name
for *series*. This also serves as the column heading for the series
Y values.
r5   zSheet1!$B$%d)series_table_row_offset)r   rC   rm   s      r   rD    XyWorkbookWriter.series_name_ref   s$     **62Q6##r   c                @    UR                   S-  nUR                  nX#-   $ )zY
Return the number of rows preceding the data table for *series* in
the Excel worksheet.
   )rZ   data_point_offset)r   rC   title_and_spacer_rowsdata_point_rowss       r   rz   (XyWorkbookWriter.series_table_row_offset   s'    
 !'q 0 22$66r   c                X    U R                  U5      S-   nU[        U5      -   S-
  nSX#4-  $ )z`
The Excel worksheet reference to the X values for this chart (not
including the column label).
r}   r5   zSheet1!$A$%d:$A$%drz   rJ   r   rC   top_rowr=   s       r   x_values_refXyWorkbookWriter.x_values_ref   :    
 ..v6:s6{*Q.
#w&;;;r   c                X    U R                  U5      S-   nU[        U5      -   S-
  nSX#4-  $ )z`
The Excel worksheet reference to the Y values for this chart (not
including the column label).
r}   r5   zSheet1!$B$%d:$B$%dr   r   s       r   y_values_refXyWorkbookWriter.y_values_ref   r   r   c                   UR                  SU R                  R                  05      nU R                   H  nUR                  SUR                  05      nU R                  U5      nUR	                  US-   SUR
                  U5        UR                  USUR                  5        UR	                  US-   SUR                  U5        M     g)z
Write chart data contents to *worksheet* in the standard XY chart
layout. Write the data for each series to a separate two-column
table, X values in column A and Y values in column B. Place the
series label in the first (heading) cell of the column.
r]   r5   r   N)	r^   r   r_   rz   rp   x_valuesrj   rl   y_valuesr   r   r   chart_num_formatrC   series_num_formatoffsets          r   r   $XyWorkbookWriter._populate_worksheet   s     $..d>N>N>\>\/]^&&F ( 3 3\6CWCW4X Y11&9F""6A:q&//CSTOOFAv{{3""6A:q&//CTU 'r   rH   N)r(   r)   r*   r+   r,   rD   rz   r   r   r   r.   rH   r   r   rw   rw      s!    
$7<<Vr   rw   c                  $    \ rS rSrSrS rS rSrg)BubbleWorkbookWriter   zR
Service object that knows how to write an Excel workbook from bubble
chart data.
c                X    U R                  U5      S-   nU[        U5      -   S-
  nSX#4-  $ )z~
The Excel worksheet reference to the range containing the bubble
sizes for *series* (not including the column heading cell).
r}   r5   zSheet1!$C$%d:$C$%dr   r   s       r   bubble_sizes_ref%BubbleWorkbookWriter.bubble_sizes_ref   r   r   c                   UR                  SU R                  R                  05      nU R                   H  nUR                  SUR                  05      nU R                  U5      nUR	                  US-   SUR
                  U5        UR                  USUR                  5        UR	                  US-   SUR                  U5        UR                  USS5        UR	                  US-   SUR                  U5        M     g)a  
Write chart data contents to *worksheet* in the bubble chart layout.
Write the data for each series to a separate three-column table with
X values in column A, Y values in column B, and bubble sizes in
column C. Place the series label in the first (heading) cell of the
values column.
r]   r5   r   r}   SizeN)
r^   r   r_   rz   rp   r   rj   rl   r   bubble_sizesr   s          r   r   (BubbleWorkbookWriter._populate_worksheet   s     $..d>N>N>\>\/]^&&F ( 3 3\6CWCW4X Y11&9F""6A:q&//CSTOOFAv{{3""6A:q&//CTUOOFAv.""6A:q&2E2EGWX 'r   rH   N)r(   r)   r*   r+   r,   r   r   r.   rH   r   r   r   r      s    
<Yr   r   )r,   
__future__r   r   
contextlibr   
xlsxwriterr   objectr   r1   rw   r   rH   r   r   <module>r      sT    ( " 	 % !G& !GH@M0 @MF9V* 9Vx"Y+ "Yr   