o
    Pf$                     @   s   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ G dd	 d	eZG d
d de
eZdS )    )ListOptionalTextIOUnion)MacroElement)Template)
JSCSSMixin)GeoJson)Map)JsCodecamelize
get_boundsparse_optionsc                       sT   e Zd ZdZedZddgZ	ddeee	e
f dee f fdd	Zd
d Z  ZS )Timelinea'
  
    Create a layer from GeoJSON with time data to add to a map.

    To add time data, you need to do one of the following:

    * Add a 'start' and 'end' property to each feature. The start and end
      can be any comparable item.

    Alternatively, you can provide a `get_interval` function.

    * This function should be a JsCode object and take as parameter
      a GeoJson feature and return a dict containing values for
      'start', 'end', 'startExclusive' and 'endExcusive' (or false if no
      data could be extracted from the feature).
    * 'start' and 'end' can be any comparable items
    * 'startExclusive' and 'endExclusive' should be boolean values.

    Parameters
    ----------
    data: file, dict or str.
        The geojson data you want to plot.

    get_interval: JsCode, optional
        Called for each feature, and should return either a time range for the
        feature or `false`, indicating that it should not be included in the
        timeline. The time range object should have 'start' and 'end' properties.
        Optionally, the boolean keys 'startExclusive' and 'endExclusive' allow the
        interval to be considered exclusive.

        If `get_interval` is not provided, 'start' and 'end' properties are
        assumed to be present on each feature.

    Examples
    --------
    >>> from folium.plugins import Timeline, TimelineSlider
    >>> m = folium.Map()

    >>> data = requests.get(
    ...     "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson"
    ... ).json()

    >>> timeline = Timeline(
    ...     data,
    ...     get_interval=JsCode(
    ...         '''
    ...         function (quake) {
    ...            // earthquake data only has a time, so we'll use that as a "start"
    ...            // and the "end" will be that + some value based on magnitude
    ...            // 18000000 = 30 minutes, so a quake of magnitude 5 would show on the
    ...            // map for 150 minutes or 2.5 hours
    ...            return {
    ...                start: quake.properties.time,
    ...                end: quake.properties.time + quake.properties.mag * 1800000,
    ...            };
    ...         };
    ...     '''
    ...     ),
    ... ).add_to(m)
    >>> TimelineSlider(
    ...     auto_play=False,
    ...     show_ticks=True,
    ...     enable_keyboard_controls=True,
    ...     playback_duration=30000,
    ... ).add_timelines(timeline).add_to(m)

    Other keyword arguments are passed to the GeoJson layer, so you can pass
      `style`, `point_to_layer` and/or `on_each_feature`.

    a  
        {% macro script(this, kwargs) %}
          var {{ this.get_name() }}_options = {{ this.options|tojson }};
          {% for key, value in this.functions.items() %}
            {{ this.get_name() }}_options["{{key}}"] = {{ value }};
          {% endfor %}

          var {{ this.get_name() }} = L.timeline(
              {{ this.data|tojson }},
              {{ this.get_name() }}_options
          );
          {{ this.get_name() }}.addTo({{ this._parent.get_name() }});
        {% endmacro %}
    timelinezPhttps://cdn.jsdelivr.net/npm/leaflet.timeline@1.6.0/dist/leaflet.timeline.min.jsmomentzEhttps://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.jsNdataget_intervalc                    sv   t  | d| _|d ur||d< i | _t| D ]\}}t|tr0|j| jt	|< |
| qtdi || _d S )Nr   r    )super__init___name	functionslistitems
isinstancer   js_coder   popr   options)selfr   r   kwargskeyvalue	__class__r   c/home/deployuser/azure_apps/autowriter/venv/lib/python3.10/site-packages/folium/plugins/timeline.pyr   o   s   

zTimeline.__init__c                 C   s   t | jddS )z
        Computes the bounds of the object itself (not including it's children)
        in the form [[lat_min, lon_min], [lat_max, lon_max]].

        T)lonlat)r   r   )r!   r   r   r'   _get_self_bounds   s   zTimeline._get_self_bounds)N)__name__
__module____qualname____doc__r   	_template
default_jsr   dictstrr   r   r   r   r)   __classcell__r   r   r%   r'   r      s    Fr   c                       s   e Zd ZdZedZddgZ										
ddedede	e
eeef  de	e
eeef  dededededef fddZdd Z fddZ  ZS )TimelineSlidera  
    Creates a timeline slider for timeline layers.

    Parameters
    ----------
    auto_play: bool, default True
        Whether the animation shall start automatically at startup.
    start: str, int or float, default earliest 'start' in GeoJson
        The beginning/minimum value of the timeline.
    end: str, int or float, default latest 'end' in GeoJSON
        The end/maximum value of the timeline.
    date_options: str, default "YYYY-MM-DD HH:mm:ss"
        A format string to render the currently active time in the control.
    enable_playback: bool, default True
        Show playback controls (i.e. prev/play/pause/next).
    enable_keyboard_controls: bool, default False
        Allow playback to be controlled using the spacebar (play/pause) and
        right/left arrow keys (next/previous).
    show_ticks: bool, default True
        Show tick marks on the slider
    steps: int, default 1000
        How many steps to break the timeline into.
        Each step will then be (end-start) / steps. Only affects playback.
    playback_duration: int, default 10000
        Minimum time, in ms, for the playback to take. Will almost certainly
        actually take at least a bit longer -- after each frame, the next
        one displays in playback_duration/steps ms, so each frame really
        takes frame processing time PLUS step time.

    Examples
    --------
    See the documentation for Timeline

    a0  
        {% macro header(this,kwargs) %}
            <style>
                .leaflet-bottom.leaflet-left {
                    width: 100%;
                }
                .leaflet-control-container .leaflet-timeline-controls {
                    box-sizing: border-box;
                    width: 100%;
                    margin: 0;
                    margin-bottom: 15px;
                }
            </style>
        {% endmacro %}

        {% macro script(this, kwargs) %}
          var {{ this.get_name() }}_options = {{ this.options|tojson }};
          {% for key, value in this.functions.items() %}
            {{ this.get_name() }}_options["{{key}}"] = {{ value }};
          {% endfor %}

          var {{ this.get_name() }} = L.timelineSliderControl(
              {{ this.get_name() }}_options
          );
          {{ this.get_name() }}.addTo({{ this._parent.get_name() }});

          {% for timeline in this.timelines %}
              {{ this.get_name() }}.addTimelines({{ timeline.get_name() }});
          {% endfor %}

        {% endmacro %}
    r   r   TYYYY-MM-DD HH:mm:ssNF  '  	auto_playdate_optionsstartendenable_playbackenable_keyboard_controls
show_ticksstepsplayback_durationc
                    s   t    d| _||
d< ||
d< ||
d< ||
d< ||
d< ||
d< ||
d< |	|
d	< td
| d |
d< i | _t|
 D ]\}}t|trQ|j| jt	|< |

| q;g | _tdi |
| _d S )Nr3   r7   r9   r:   r;   r<   r=   r>   durationzu
            function(date) {
                var newdate = new moment(date);
                return newdate.format("z");
            }
        format_outputr   )r   r   r   r   r   r   r   r   r   r   r   	timelinesr   r    )r!   r7   r8   r9   r:   r;   r<   r=   r>   r?   r"   r#   r$   r%   r   r'   r      s2   


zTimelineSlider.__init__c                 G   s   |  j |7  _ | S )zAdd timelines to the control)rB   )r!   argsr   r   r'   add_timelines  s   zTimelineSlider.add_timelinesc                    s*   t | jts
J dt jdi | d S )Nz1TimelineSlider can only be added to a Map object.r   )r   _parentr
   r   render)r!   r"   r%   r   r'   rF     s   zTimelineSlider.render)	Tr4   NNTFTr5   r6   )r*   r+   r,   r-   r   r.   r/   boolr1   r   r   intfloatr   rD   rF   r2   r   r   r%   r'   r3      sL    #$	
/r3   N)typingr   r   r   r   branca.elementr   jinja2r   folium.elementsr   folium.featuresr	   folium.foliumr
   folium.utilitiesr   r   r   r   r   r3   r   r   r   r'   <module>   s     