Path: blob/main/tests/plugins/test_heat_map_withtime.py
2533 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("""37var times = {{this.times}};3839{{this._parent.get_name()}}.timeDimension = L.timeDimension(40{times : times, currentTime: new Date(1)}41);4243var {{this._control_name}} = new L.Control.TimeDimensionCustom({{this.index}}, {44autoPlay: {{this.auto_play}},45backwardButton: {{this.backward_button}},46displayDate: {{this.display_index}},47forwardButton: {{this.forward_button}},48limitMinimumRange: {{this.limit_minimum_range}},49limitSliders: {{this.limit_sliders}},50loopButton: {{this.loop_button}},51maxSpeed: {{this.max_speed}},52minSpeed: {{this.min_speed}},53playButton: {{this.play_button}},54playReverseButton: {{this.play_reverse_button}},55position: "{{this.position}}",56speedSlider: {{this.speed_slider}},57speedStep: {{this.speed_step}},58styleNS: "{{this.style_NS}}",59timeSlider: {{this.time_slider}},60timeSliderDragUpdate: {{this.time_slider_drag_update}},61timeSteps: {{this.index_steps}}62})63.addTo({{this._parent.get_name()}});6465var {{this.get_name()}} = new TDHeatmap({{this.data}},66{heatmapOptions: {67radius: {{this.radius}},68blur: {{this.blur}},69minOpacity: {{this.min_opacity}},70maxOpacity: {{this.max_opacity}},71scaleRadius: {{this.scale_radius}},72useLocalExtrema: {{this.use_local_extrema}},73defaultWeight: 1,74{% if this.gradient %}gradient: {{ this.gradient }}{% endif %}75}76});77{{ this.get_name() }}.addTo({{ this._parent.get_name() }});78""")7980assert normalize(tmpl.render(this=hm)) in out818283