@@ -49,7 +49,7 @@ def __init__(self, start_date=datetime(2018, 1, 1), end_date=datetime(2023, 12,
49
49
index = (0 , 11 ), # Default to a 11-month interval
50
50
orientation = "horizontal" ,
51
51
continuous_update = False ,
52
- readout = False ,
52
+ readout = True ,
53
53
behaviour = "drag" ,
54
54
layout = {"width" : "90%" , "height" : "100px" , "margin" : "0 auto 0 auto" },
55
55
style = {
@@ -61,14 +61,6 @@ def __init__(self, start_date=datetime(2018, 1, 1), end_date=datetime(2023, 12,
61
61
pd .to_datetime (start_date ) + pd .DateOffset (months = 12 ) - timedelta (days = 1 ),
62
62
]
63
63
64
- self .selected_range_widget = widgets .HTML (
65
- value = self ._get_selected_range_html (),
66
- layout = {"width" : "100%" , "margin" : "0 auto 0 auto" },
67
- )
68
-
69
- def _get_selected_range_html (self ):
70
- return f"<div style='text-align: center; font-size: 14px; position: relative; width: 100%; height: 10px; margin-top: 20px;'>Selected range: { self .selected_range [0 ].strftime ('%d %b %Y' )} to { self .selected_range [1 ].strftime ('%d %b %Y' )} </div>"
71
-
72
64
def on_slider_change (self , change ):
73
65
start , end = change ["new" ]
74
66
# keep the interval fixed
@@ -77,7 +69,6 @@ def on_slider_change(self, change):
77
69
end = start + pd .DateOffset (months = 11 )
78
70
self .interval_slider .value = (start , end )
79
71
self .selected_range = (start , end + pd .DateOffset (months = 1 ) - timedelta (days = 1 ))
80
- self .selected_range_widget .value = self ._get_selected_range_html ()
81
72
82
73
def show_slider (self ):
83
74
self .interval_slider .observe (self .on_slider_change , names = "value" )
@@ -93,40 +84,13 @@ def show_slider(self):
93
84
"""
94
85
)
95
86
96
- # Generate a list of dates for the ticks every 3 months
97
- tick_dates = pd .date_range (
98
- self .start_date , self .end_date + pd .DateOffset (months = 3 ), freq = "4ME"
99
- )
100
-
101
- # Create a list of tick labels in the format "Aug 2023"
102
- tick_labels = [date .strftime ("%b<br>%Y" ) for date in tick_dates ]
103
-
104
- # Calculate the positions of the ticks to align them with the slider
105
- total_days = (self .end_date - self .start_date ).days
106
- tick_positions = [
107
- ((date - self .start_date ).days / total_days * 100 ) for date in tick_dates
108
- ]
109
-
110
- # Create a text widget to display the tick labels with calculated positions
111
- tick_widget_html = "<div style='text-align: center; font-size: 12px; position: relative; height: 20px; margin-top: -40px; margin-left: 50px; margin-right: 80px'>"
112
- for label , position in zip (tick_labels , tick_positions ):
113
- tick_widget_html += f"<div style='position: absolute; left: { position } %; transform: translateX(-50%);'>{ label } </div>"
114
- tick_widget_html += "</div>"
115
-
116
- tick_widget = widgets .HTML (
117
- value = tick_widget_html ,
118
- layout = {"width" : "100%" , "margin" : "0 auto 100 auto" },
119
- )
120
-
121
87
# Arrange the text widget, interval slider, and tick widget using VBox
122
88
vbox_with_ticks = widgets .VBox (
123
89
[
124
90
descr_widget ,
125
91
self .interval_slider ,
126
- tick_widget ,
127
- self .selected_range_widget ,
128
92
],
129
- layout = {"height" : "220px " },
93
+ layout = {"height" : "150px " },
130
94
)
131
95
132
96
display (vbox_with_ticks )
0 commit comments