
    IR-e                        d dl mZmZmZ d dlmZ d dlmc m	Z
 d dlmZ ddlmZ  G d dej                  Z e            Z e e eej                  dd	d
                    Z e e eej                  dd	d                    ZdZdZd eee          z  Zeez   dz   ZdZdZ G d d          ZddddeddfdZ e
j        dee           dS )    )abspathdirnamejoinN)extern   )Tablec                   ~    e Zd ZdZ ej        dd          Z ej        dd          Z ej        dgdd	          Zd
S )Confz@
    Configuration parameters for `astropy.table.jsviewer`.
    z+https://code.jquery.com/jquery-3.6.0.min.jszThe URL to the jquery library.z>https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.jsz)The URL to the jquery datatables library.z<https://cdn.datatables.net/1.10.12/css/jquery.dataTables.cssz'The URLs to the css file(s) to include.string_list)cfgtypeN)	__name__
__module____qualname____doc___config
ConfigItem
jquery_urldatatables_urlcss_urls     6lib/python3.11/site-packages/astropy/table/jsviewer.pyr
   r
      sw          $#57W J (W'H3 N
 "w!	GH1  HHHr   r
   jquerydatajscssad  
var astropy_sort_num = function(a, b) {{
    var a_num = parseFloat(a);
    var b_num = parseFloat(b);

    if (isNaN(a_num) && isNaN(b_num))
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    else if (!isNaN(a_num) && !isNaN(b_num))
        return ((a_num < b_num) ? -1 : ((a_num > b_num) ? 1 : 0));
    else
        return isNaN(a_num) ? -1 : 1;
}}
z
jQuery.extend( jQuery.fn.dataTableExt.oSort, {{
    "optionalnum-asc": astropy_sort_num,
    "optionalnum-desc": function (a,b) {{ return -astropy_sort_num(a, b); }}
}});
a  
<script>
%(sorting_script1)s
require.config({{paths: {{
    datatables: '{datatables_url}'
}}}});
require(["datatables"], function(){{
    console.log("$('#{tid}').dataTable()");
    %(sorting_script2)s
    $('#{tid}').dataTable({{
        order: [],
        pageLength: {display_length},
        lengthMenu: {display_length_menu},
        pagingType: "full_numbers",
        columnDefs: [{{targets: {sort_columns}, type: "optionalnum"}}]
    }});
}});
</script>
)sorting_script1sorting_script2a  
$(document).ready(function() {{
    $('#{tid}').dataTable({{
        order: [],
        pageLength: {display_length},
        lengthMenu: {display_length_menu},
        pagingType: "full_numbers",
        columnDefs: [{{targets: {sort_columns}, type: "optionalnum"}}]
    }});
}} );
zbody {font-family: sans-serif;}
table.dataTable {width: auto !important; margin: 0 !important;}
.dataTables_filter, .dataTables_paginate {float: left !important; margin-left:1em}
ztable.dataTable {clear: both; width: auto !important; margin: 0 !important;}
.dataTables_info, .dataTables_length, .dataTables_filter, .dataTables_paginate{
display: inline-block; margin-right: 1em; }
.paginate_button { margin-right: 5px; }
c                   \    e Zd ZdZddZed             Zed             Zd Zdd
Z	ddZ
dS )JSViewera  Provides an interactive HTML export of a Table.

    This class provides an interface to the `DataTables
    <https://datatables.net/>`_ library, which allow to visualize interactively
    an HTML table. It is used by the `~astropy.table.Table.show_in_browser`
    method.

    Parameters
    ----------
    use_local_files : bool, optional
        Use local files or a CDN for JavaScript libraries. Default False.
    display_length : int, optional
        Number or rows to show. Default to 50.

    F2   c                     || _         g dg dg| _        || _        | j        D ]}||vr|                    d|           d S )N)
      r!   d       )r#   r$   r!   r%   r&   r'   Allr   )_use_local_filesdisplay_length_menudisplay_lengthinsert)selfuse_local_filesr,   Ls       r   __init__zJSViewer.__init__   sl     /,,,///$
  -) 	, 	,AQ&&N+++	, 	,r   c                     | j         r0dt          t          d          z   dt          t          d          z   gS t          j        t          j        gS )Nfile://zjquery-3.6.0.min.jszjquery.dataTables.min.js)r*   r   EXTERN_JS_DIRconfr   r   r.   s    r   jquery_urlszJSViewer.jquery_urls   sO      	:D0EFFFD0JKKK 
 OT%899r   c                 Z    | j         rdt          t          d          z   gS t          j        S )Nr3   zjquery.dataTables.css)r*   r   EXTERN_CSS_DIRr5   r   r6   s    r   r   zJSViewer.css_urls   s.      	!^5L M MMNN= r   c                 h    | j         rdt          t          d          z   S t          j        d d         S )Nr3   zjquery.dataTables.min)r*   r   r4   r5   r   r6   s    r   _jstable_filezJSViewer._jstable_file   s5      	,tM3JKKKK&ss++r   N[]c                     d||nt            d}|t                              | j        | j        |                                 ||          z  }|S )Nz<style>z</style>)r,   r+   r   tidsort_columns)DEFAULT_CSS_NBIPYNB_JS_SCRIPTformatr,   r+   r<   )r.   table_idr   r@   htmls        r   ipynbzJSViewer.ipynb   sc    M^MMM&&. $ 8--//% ' 
 
 	
 r   table0c                 v    t                               | j        | j        ||                                          S )N)r,   r+   r?   r@   )HTML_JS_SCRIPTrC   r,   r+   strip)r.   rD   r@   s      r   html_jszJSViewer.html_js   s<    $$. $ 8%	 % 
 

 %''	r   )Fr!   )Nr=   )rG   r=   )r   r   r   r   r1   propertyr7   r   r<   rF   rK   r   r   r   r    r    t   s          	, 	, 	, 	, : : X: ! ! X!, , ,	 	 	 	     r   r    i  zdisplay compactFc	           	         |dt          |            }|pi }t          di |}	d t          | j                                                  D             }
||||	j        |	j        |	                    ||
          d}|r|                    |           |t          |           k     r
| d |         } | 
                    |d||           d S )Ntablec                 >    g | ]\  }}|j         j        j        d v |S )iufc)infodtypekind).0icols      r   
<listcomp>z(write_table_jsviewer.<locals>.<listcomp>   s8       As8>&(( 	
(((r   )rD   r@   )rD   table_classr   cssfilesjsfilesr   rE   )rC   htmldict	overwriter   )idr    	enumeratecolumnsvaluesr   r7   rK   updatelenwrite)rN   filenamerD   	max_linesrX   jskwargsr   r[   r\   jsvsortable_columnshtml_optionss               r   write_table_jsviewerrj      s     &2e99&&~2H


X

C  4 4 6 677   "L?kk8:JkKK L  &H%%%3u::jyj!	KK,)KTTTTTr   jsviewer)os.pathr   r   r   astropy.configconfigr   astropy.io.registryioregistryio_registryastropyr   rN   r   ConfigNamespacer
   r5   __file__r4   r9   _SORTING_SCRIPT_PART_1_SORTING_SCRIPT_PART_2dictrB   rI   DEFAULT_CSSrA   r    rj   register_writerr   r   r   <module>r{      s   + * * * * * * * * *             ) ) ) ) ) ) ) ) )                7"   * tvv WWV_55xNNOOggfo66&%PPQQ  $ d*<R  %. 
 $D D D D D D D DT !#U #U #U #UL  J/C D D D D Dr   