@@ -19,6 +19,8 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
19
19
styledict: dict
20
20
A dictionary where the keys are the geojson feature ids and the values are
21
21
dicts of `{time: style_options_dict}`
22
+ date_options: str, default "ddd MMM DD YYYY"
23
+ A format string to render the currently active time in the control.
22
24
highlight: bool, default False
23
25
Whether to show a visual effect on mouse hover and click.
24
26
name : string, default None
@@ -44,6 +46,11 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
44
46
let styledict = {{ this.styledict|tojson }};
45
47
let current_timestamp = timestamps[{{ this.init_timestamp }}];
46
48
49
+ function formatDate(date) {
50
+ var newdate = new moment(date);
51
+ return newdate.format({{this.date_format|tojson}});
52
+ }
53
+
47
54
let slider_body = d3.select("body").insert("div", "div.folium-map")
48
55
.attr("id", "slider_{{ this.get_name() }}");
49
56
$("#slider_{{ this.get_name() }}").hide();
@@ -64,7 +71,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
64
71
.attr("step", "1")
65
72
.style('align', 'center');
66
73
67
- let datestring = new Date (parseInt(current_timestamp)*1000).toDateString( );
74
+ let datestring = formatDate (parseInt(current_timestamp)*1000);
68
75
d3.select("#slider_{{ this.get_name() }} > output").text(datestring);
69
76
70
77
let fill_map = function(){
@@ -84,7 +91,7 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
84
91
85
92
d3.select("#slider_{{ this.get_name() }} > input").on("input", function() {
86
93
current_timestamp = timestamps[this.value];
87
- var datestring = new Date (parseInt(current_timestamp)*1000).toDateString( );
94
+ let datestring = formatDate (parseInt(current_timestamp)*1000);
88
95
d3.select("#slider_{{ this.get_name() }} > output").text(datestring);
89
96
fill_map();
90
97
});
@@ -155,12 +162,19 @@ class TimeSliderChoropleth(JSCSSMixin, Layer):
155
162
"""
156
163
)
157
164
158
- default_js = [("d3v4" , "https://d3js.org/d3.v4.min.js" )]
165
+ default_js = [
166
+ ("d3v4" , "https://d3js.org/d3.v4.min.js" ),
167
+ (
168
+ "moment" ,
169
+ "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js" ,
170
+ ),
171
+ ]
159
172
160
173
def __init__ (
161
174
self ,
162
175
data ,
163
176
styledict ,
177
+ date_options : str = "ddd MMM DD YYYY" ,
164
178
highlight : bool = False ,
165
179
name = None ,
166
180
overlay = True ,
@@ -173,21 +187,21 @@ def __init__(
173
187
):
174
188
super ().__init__ (name = name , overlay = overlay , control = control , show = show )
175
189
self .data = GeoJson .process_data (GeoJson ({}), data )
190
+ self .date_format = date_options
176
191
self .highlight = highlight
177
192
178
193
self .stroke_opacity = stroke_opacity
179
194
self .stroke_width = stroke_width
180
195
self .stroke_color = stroke_color
181
196
182
197
if not isinstance (styledict , dict ):
183
- raise ValueError (
184
- f"styledict must be a dictionary, got { styledict !r} "
185
- ) # noqa
198
+ raise ValueError (f"styledict must be a dictionary, got { styledict !r} " )
199
+
186
200
for val in styledict .values ():
187
201
if not isinstance (val , dict ):
188
202
raise ValueError (
189
203
f"Each item in styledict must be a dictionary, got { val !r} "
190
- ) # noqa
204
+ )
191
205
192
206
# Make set of timestamps.
193
207
timestamps_set = set ()
0 commit comments