
    liX*                        d Z ddlmZ ddlZddlmZ ddlmZ  G d de      Z	 G d d	e	      Z
 G d
 de	      Z G d de      Zy)z"Chart builder and related objects.    )annotationsN)contextmanager)Workbookc                  H     e Zd ZdZ fdZed        Zed        Zd Z	 xZ
S )_BaseWorkbookWriterz:Base class for workbook writers, providing shared members.c                8    t         t        |           || _        y )N)superr   __init___chart_data)self
chart_data	__class__s     M/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pptx/chart/xlsx.pyr
   z_BaseWorkbookWriter.__init__   s    !413%    c                    t        j                         }| j                  |      5 \  }}| j                  ||       ddd       |j	                         S # 1 sw Y   |j	                         S xY w)z+bytes for Excel file containing chart_data.N)ioBytesIO_open_worksheet_populate_worksheetgetvaluer   	xlsx_fileworkbook	worksheets       r   	xlsx_blobz_BaseWorkbookWriter.xlsx_blob   sb     JJL	!!), 	:0E9$$Xy9	:!!##	:!!##s   AA,c              #  t   K   t        |ddi      }|j                         }||f |j                          yw)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   z#_BaseWorkbookWriter._open_worksheet   s<      IT':;**,		!!s   68c                    t        d      )zy
        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   z'_BaseWorkbookWriter._populate_worksheet'   s    
 ""EFFr   )__name__
__module____qualname____doc__r
   propertyr   r   r   r   __classcell__)r   s   @r   r   r      s9    D& $ $ 
 
Gr   r   c                  Z    e Zd ZdZed        Zd Zd Zed        Z	d Z
d Zd Zd	 Zd
 Zy)CategoryWorkbookWriterz
    Determines Excel worksheet layout and can write an Excel workbook from
    a CategoryChartData object. Serves as the authority for Excel worksheet
    ranges.
    c                    | j                   j                  }|j                  dk(  rt        d      t	        t        d      |j                  z   dz
        }|j                  dz   }d||fz  S )z|
        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   r.   	right_col
bottom_rows       r   categories_refz%CategoryWorkbookWriter.categories_ref6   sm     %%00
q @AAC:#3#33a78	**Q.
#y*&===r   c                *    d| j                  |      z  S )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_refz&CategoryWorkbookWriter.series_name_refC   s      7 7 ???r   c                b     dj                   di | j                  |      t        |      dz   dS )zy
        The Excel worksheet reference to the values for this series (not
        including the column heading).
        z1Sheet1!${col_letter}$2:${col_letter}${bottom_row}r-   )
col_letterr5    )formatr8   lenr9   s     r   
values_refz!CategoryWorkbookWriter.values_refK   s>    
 JBII 
"55f=!&kAo
 	
r   c                    | dk  s| dkD  rt        d      d}| r6| dz  }|dk(  rd}t        t        d      |z   dz
        }||z   }| dz
  dz  } | r6|S )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'.
        r-   i @  z&column_number must be in range 1-16384    r   r,   )r0   r1   r2   )column_numbercol_ref	remainderr=   s       r   _column_referencez(CategoryWorkbookWriter._column_referenceW   s~     1 5EFF %*IA~	SX	1A56J 7*G +Q.25M  r   c                L    | j                  ||       | j                  ||       y)a  
        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   z*CategoryWorkbookWriter._populate_worksheetw   s$     	x38Y/r   c                p    d|j                   j                  z   |j                  z   }| j                  |      S )zj
        The letter of the Excel worksheet column in which the data for a
        series appears.
        r-   )r.   r/   indexrH   )r   r:   rE   s      r   r8   z)CategoryWorkbookWriter._series_col_letter   s4    
 F--333fllB%%m44r   c                    | j                   j                  }|j                  d|j                  i      }|j                  }t        |j                        D ]!  \  }}||z
  dz
  }| j                  ||||       # y)aF  
        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_formatr-   N)r   r.   
add_formatnumber_formatr/   	enumeratelevels_write_cat_column)	r   r   r   r.   rO   r/   idxlevelcols	            r   rJ   z(CategoryWorkbookWriter._write_categories   s|     %%00
((,
8P8P)QR
  #J$5$56 	FJC#+/C""9c5*E	Fr   c                p    |j                  ||d       |D ]  \  }}|dz   }|j                  ||||         y)z
        Write a category column defined by *level* to *worksheet* at offset
        *col* and formatted with *num_format*.
        
   r-   N)
set_columnwrite)r   r   rW   rV   rO   offnamerows           r   rT   z(CategoryWorkbookWriter._write_cat_column   sD    
 	S#r* 	8IC'COOCdJ7	8r   c                8   | j                   j                  j                  }t        | j                         D ]b  \  }}|j	                  d|j
                  i      }||z   }|j                  d||j                         |j                  d||j                  |       d y)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.
        rO   r   r-   N)
r   r.   r/   rR   rP   rQ   r[   r]   write_columnvalues)r   r   r   
col_offsetrU   r:   rO   
series_cols           r   rK   z$CategoryWorkbookWriter._write_series   s     %%0066
$T%5%56 	MKC!,,lF<P<P-QRJz)JOOAz6;;7""1j&--L		Mr   N)r#   r$   r%   r&   r'   r6   r;   rA   staticmethodrH   r   r8   rJ   rT   rK   r>   r   r   r*   r*   /   sU     
> 
>@

  >
05F8Mr   r*   c                  .    e Zd ZdZd Zd Zd Zd Zd Zy)XyWorkbookWriterz
    Determines Excel worksheet layout and can write an Excel workbook from XY
    chart data. Serves as the authority for Excel worksheet ranges.
    c                4    | j                  |      dz   }d|z  S )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.
        r-   zSheet1!$B$%d)series_table_row_offset)r   r:   r^   s      r   r;   z XyWorkbookWriter.series_name_ref   s$     **62Q6##r   c                B    |j                   dz  }|j                  }||z   S )zq
        Return the number of rows preceding the data table for *series* in
        the Excel worksheet.
           )rM   data_point_offset)r   r:   title_and_spacer_rowsdata_point_rowss       r   rh   z(XyWorkbookWriter.series_table_row_offset   s)    
 !'q 0 22$66r   c                Z    | j                  |      dz   }|t        |      z   dz
  }d||fz  S )zx
        The Excel worksheet reference to the X values for this chart (not
        including the column label).
        rj   r-   zSheet1!$A$%d:$A$%drh   r@   r   r:   top_rowr5   s       r   x_values_refzXyWorkbookWriter.x_values_ref   <    
 ..v6:s6{*Q.
#w
&;;;r   c                Z    | j                  |      dz   }|t        |      z   dz
  }d||fz  S )zx
        The Excel worksheet reference to the Y values for this chart (not
        including the column label).
        rj   r-   zSheet1!$B$%d:$B$%dro   rp   s       r   y_values_refzXyWorkbookWriter.y_values_ref   rs   r   c                   |j                  d| j                  j                  i      }| j                  D ]  }|j                  d|j                  i      }| j                  |      }|j	                  |dz   d|j
                  |       |j                  |d|j                         |j	                  |dz   d|j                  |        y)a#  
        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.
        rO   r-   r   N)	rP   r   rQ   rh   r`   x_valuesr[   r]   y_valuesr   r   r   chart_num_formatr:   series_num_formatoffsets          r   r   z$XyWorkbookWriter._populate_worksheet   s     $..d>N>N>\>\/]^&& 	VF ( 3 3\6CWCW4X Y11&9F""6A:q&//CSTOOFAv{{3""6A:q&//CTU	Vr   N)	r#   r$   r%   r&   r;   rh   rr   ru   r   r>   r   r   rf   rf      s!    
$7<<Vr   rf   c                      e Zd ZdZd Zd Zy)BubbleWorkbookWriterz^
    Service object that knows how to write an Excel workbook from bubble
    chart data.
    c                Z    | j                  |      dz   }|t        |      z   dz
  }d||fz  S )z
        The Excel worksheet reference to the range containing the bubble
        sizes for *series* (not including the column heading cell).
        rj   r-   zSheet1!$C$%d:$C$%dro   rp   s       r   bubble_sizes_refz%BubbleWorkbookWriter.bubble_sizes_ref   rs   r   c                   |j                  d| j                  j                  i      }| j                  D ]  }|j                  d|j                  i      }| j                  |      }|j	                  |dz   d|j
                  |       |j                  |d|j                         |j	                  |dz   d|j                  |       |j                  |dd       |j	                  |dz   d|j                  |        y)aN  
        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.
        rO   r-   r   rj   SizeN)
rP   r   rQ   rh   r`   rw   r[   r]   rx   bubble_sizesry   s          r   r   z(BubbleWorkbookWriter._populate_worksheet   s     $..d>N>N>\>\/]^&& 
	YF ( 3 3\6CWCW4X Y11&9F""6A:q&//CSTOOFAv{{3""6A:q&//CTUOOFAv.""6A:q&2E2EGWX
	Yr   N)r#   r$   r%   r&   r   r   r>   r   r   r~   r~      s    
<Yr   r~   )r&   
__future__r   r   
contextlibr   
xlsxwriterr   objectr   r*   rf   r~   r>   r   r   <module>r      sT    ( " 	 % !G& !GH@M0 @MF9V* 9Vx"Y+ "Yr   