U
    e»{j¸  ã                   @   sö   d dl mZmZmZ d dlmZ d dlm  m	Z
 d dlmZ ddlmZ G d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d� Zee d ZdZdZG dd„ dƒZddddeddfdd„Ze
 dee¡ dS )é    )ÚabspathÚdirnameÚjoinN)Úexterné   )ÚTablec                   @   s:   e Zd ZdZe dd¡Ze dd¡Zejdgd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.Zstring_list)ZcfgtypeN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_configZ
ConfigItemÚ
jquery_urlÚdatatables_urlÚcss_urls© r   r   úU/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/table/jsviewer.pyr      s    ÿþýr   Z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>
)Zsorting_script1Zsorting_script2a  
$(document).ready(function() {{
    $('#{tid}').dataTable({{
        order: [],
        pageLength: {display_length},
        lengthMenu: {display_length_menu},
        pagingType: "full_numbers",
        columnDefs: [{{targets: {sort_columns}, type: "optionalnum"}}]
    }});
}} );
z³body {font-family: sans-serif;}
table.dataTable {width: auto !important; margin: 0 !important;}
.dataTables_filter, .dataTables_paginate {float: left !important; margin-left:1em}
zñtable.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                   @   sN   e Zd ZdZddd„Zedd„ ƒZedd	„ ƒZd
d„ Zddd„Z	d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.

    Fé2   c                 C   sV   || _ dddddddgdddddddgg| _|| _| jD ]}||kr8| d	|¡ q8d S )
Né
   é   r   éd   iô  iè  éÿÿÿÿZAllr   )Ú_use_local_filesÚdisplay_length_menuÚdisplay_lengthÚinsert)ÚselfZuse_local_filesr   ÚLr   r   r   Ú__init__…   s    þ
zJSViewer.__init__c                 C   s2   | j r"dttdƒ dttdƒ gS tjtjgS d S )Núfile://zjquery-3.6.0.min.jszjquery.dataTables.min.js)r   r   ÚEXTERN_JS_DIRÚconfr   r   ©r    r   r   r   Újquery_urls�   s
    þzJSViewer.jquery_urlsc                 C   s    | j rdttdƒ gS tjS d S )Nr#   zjquery.dataTables.css)r   r   ÚEXTERN_CSS_DIRr%   r   r&   r   r   r   r   š   s    zJSViewer.css_urlsc                 C   s&   | j rdttdƒ S tjd d… S d S )Nr#   zjquery.dataTables.minéýÿÿÿ)r   r   r$   r%   r   r&   r   r   r   Ú_jstable_file¡   s    zJSViewer._jstable_fileNú[]c                 C   s<   d|d k	r|nt › d�}|tj| j| j|  ¡ ||d�7 }|S )Nz<style>z</style>)r   r   r   ÚtidÚsort_columns)ÚDEFAULT_CSS_NBÚIPYNB_JS_SCRIPTÚformatr   r   r*   )r    Útable_idr   r-   Úhtmlr   r   r   Úipynb§   s    ûzJSViewer.ipynbÚtable0c                 C   s   t j| j| j||d� ¡ S )N)r   r   r,   r-   )ÚHTML_JS_SCRIPTr0   r   r   Ústrip)r    r1   r-   r   r   r   Úhtml_js²   s    üzJSViewer.html_js)Fr   )Nr+   )r4   r+   )r	   r
   r   r   r"   Úpropertyr'   r   r*   r3   r7   r   r   r   r   r   t   s   

	

r   iˆ  zdisplay compactFc	              	   C   sœ   |d krdt | ƒ› �}|pi }tf |Ž}	dd„ t| j ¡ ƒD ƒ}
||||	j|	j|	j||
d�dœ}|rn| |¡ |t	| ƒk r†| d |… } | j
|d||d� d S )NÚtablec                 S   s"   g | ]\}}|j jjd kr|‘qS )Ziufc)ÚinfoZdtypeÚkind)Ú.0ÚiÚcolr   r   r   Ú
<listcomp>Ì   s   þz(write_table_jsviewer.<locals>.<listcomp>)r1   r-   )r1   Útable_classr   ZcssfilesZjsfilesr   r2   )r0   ÚhtmldictÚ	overwrite)Úidr   Ú	enumerateÚcolumnsÚvaluesr   r'   r7   ÚupdateÚlenÚwrite)r9   Úfilenamer1   Ú	max_linesr@   Zjskwargsr   rA   rB   ZjsvZsortable_columnsZhtml_optionsr   r   r   Úwrite_table_jsviewer»   s&    
þú
rL   Zjsviewer)Úos.pathr   r   r   Zastropy.configÚconfigr   Zastropy.io.registryÚioÚregistryZio_registryZastropyr   r9   r   ZConfigNamespacer   r%   Ú__file__r$   r(   Z_SORTING_SCRIPT_PART_1Z_SORTING_SCRIPT_PART_2Údictr/   r5   ZDEFAULT_CSSr.   r   rL   Zregister_writerr   r   r   r   Ú<module>   sD    ÿîÿþÿJ÷
&