Path: blob/main/tests/plugins/test_heat_map_withtime.py
1601 views
"""1Test HeatMapWithTime2------------3"""45import numpy as np67import folium8from folium import plugins9from folium.template import Template10from folium.utilities import normalize111213def test_heat_map_with_time():14np.random.seed(3141592)15initial_data = np.random.normal(size=(100, 2)) * np.array([[1, 1]]) + np.array(16[[48, 5]]17)18move_data = np.random.normal(size=(100, 2)) * 0.0119data = [(initial_data + move_data * i).tolist() for i in range(100)]20m = folium.Map([48.0, 5.0], zoom_start=6)21hm = plugins.HeatMapWithTime(data).add_to(m)2223out = normalize(m._parent.render())2425# We verify that the script imports are present.26script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.timedimension.min.js"></script>' # noqa27assert script in out28script = '<script src="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/pa7_hm.min.js"></script>' # noqa29assert script in out30script = '<script src="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/pa7_leaflet_hm.min.js"></script>' # noqa31assert script in out32script = '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.timedimension.control.css"/>' # noqa33assert script in out3435# We verify that the script part is correct.36tmpl = Template(37"""38var times = {{this.times}};3940{{this._parent.get_name()}}.timeDimension = L.timeDimension(41{times : times, currentTime: new Date(1)}42);4344var {{this._control_name}} = new L.Control.TimeDimensionCustom({{this.index}}, {45autoPlay: {{this.auto_play}},46backwardButton: {{this.backward_button}},47displayDate: {{this.display_index}},48forwardButton: {{this.forward_button}},49limitMinimumRange: {{this.limit_minimum_range}},50limitSliders: {{this.limit_sliders}},51loopButton: {{this.loop_button}},52maxSpeed: {{this.max_speed}},53minSpeed: {{this.min_speed}},54playButton: {{this.play_button}},55playReverseButton: {{this.play_reverse_button}},56position: "{{this.position}}",57speedSlider: {{this.speed_slider}},58speedStep: {{this.speed_step}},59styleNS: "{{this.style_NS}}",60timeSlider: {{this.time_slider}},61timeSliderDragUpdate: {{this.time_slider_drag_update}},62timeSteps: {{this.index_steps}}63})64.addTo({{this._parent.get_name()}});6566var {{this.get_name()}} = new TDHeatmap({{this.data}},67{heatmapOptions: {68radius: {{this.radius}},69blur: {{this.blur}},70minOpacity: {{this.min_opacity}},71maxOpacity: {{this.max_opacity}},72scaleRadius: {{this.scale_radius}},73useLocalExtrema: {{this.use_local_extrema}},74defaultWeight: 1,75{% if this.gradient %}gradient: {{ this.gradient }}{% endif %}76}77});78{{ this.get_name() }}.addTo({{ this._parent.get_name() }});79"""80)8182assert normalize(tmpl.render(this=hm)) in out838485