@@ -24,21 +24,24 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
24
24
Whether the Layer will be included in LayerControls.
25
25
show: bool, default True
26
26
Whether the layer will be shown on opening (only for overlays).
27
-
27
+ init_timestamp: int, default 0
28
+ Initial time-stamp index on the slider. Must be in the range
29
+ `[-L, L-1]`, where `L` is the maximum number of time stamps in
30
+ `styledict`. For example, use `-1` to initialize the slider to the
31
+ latest timestamp.
28
32
"""
29
33
_template = Template (u"""
30
34
{% macro script(this, kwargs) %}
31
35
var timestamps = {{ this.timestamps|tojson }};
32
36
var styledict = {{ this.styledict|tojson }};
33
- var current_timestamp = timestamps[0];
34
-
37
+ var current_timestamp = timestamps[{{ this.init_timestamp }}];
35
38
// insert time slider
36
39
d3.select("body").insert("p", ":first-child").append("input")
37
40
.attr("type", "range")
38
41
.attr("width", "100px")
39
42
.attr("min", 0)
40
43
.attr("max", timestamps.length - 1)
41
- .attr("value", 0 )
44
+ .attr("value", {{ this.init_timestamp }} )
42
45
.attr("id", "slider")
43
46
.attr("step", "1")
44
47
.style('align', 'center');
@@ -135,7 +138,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
135
138
]
136
139
137
140
def __init__ (self , data , styledict , name = None , overlay = True , control = True ,
138
- show = True ):
141
+ show = True , init_timestamp = 0 ):
139
142
super (TimeSliderChoropleth , self ).__init__ (name = name , overlay = overlay ,
140
143
control = control , show = show )
141
144
self .data = GeoJson .process_data (GeoJson ({}), data )
@@ -157,3 +160,9 @@ def __init__(self, data, styledict, name=None, overlay=True, control=True,
157
160
158
161
self .timestamps = timestamps
159
162
self .styledict = styledict
163
+ assert - len (timestamps ) <= init_timestamp < len (timestamps ), (
164
+ 'init_timestamp must be in the range [-{}, {}) but got {}' .format (
165
+ len (timestamps ), len (timestamps ), init_timestamp ))
166
+ if init_timestamp < 0 :
167
+ init_timestamp = len (timestamps ) + init_timestamp
168
+ self .init_timestamp = init_timestamp
0 commit comments