|
14 | 14 | from .._fiff.pick import _FNIRS_CH_TYPES_SPLIT, _picks_to_idx, channel_type, pick_types |
15 | 15 | from ..defaults import _handle_default |
16 | 16 | from ..utils import Bunch, _check_option, _clean_names, _is_numeric, _to_rgb, fill_doc |
17 | | -from .ui_events import ( |
18 | | - ChannelsSelect, |
19 | | - TimeChange, |
20 | | - link, |
21 | | - publish, |
22 | | - subscribe, |
23 | | -) |
| 17 | +from .ui_events import ChannelsSelect, TimeChange, link, publish, subscribe |
24 | 18 | from .utils import ( |
25 | 19 | DraggableColorbar, |
26 | 20 | SelectFromCollection, |
@@ -670,6 +664,8 @@ def _update_selectline(time): |
670 | 664 |
|
671 | 665 | ax._selectline = None |
672 | 666 | ax._selectcolor = "white" if face_brightness < 150 else "black" |
| 667 | + if orig_fig._current_time is not None: |
| 668 | + _update_selectline(orig_fig._current_time) |
673 | 669 |
|
674 | 670 | plt.connect("motion_notify_event", _cursor_vline) |
675 | 671 | plt.connect("axes_leave_event", _rm_cursor) |
@@ -1174,11 +1170,38 @@ def _plot_evoked_topo( |
1174 | 1170 |
|
1175 | 1171 | setattr(fig, "_current_time", None) |
1176 | 1172 |
|
1177 | | - def on_time_change(event, fig): |
| 1173 | + def _on_time_change(event, fig, tmin, tmax): |
1178 | 1174 | """Respond to a time change UI event.""" |
1179 | 1175 | fig._current_time = event.time |
1180 | 1176 |
|
1181 | | - subscribe(fig, "time_change", partial(on_time_change, fig=fig)) |
| 1177 | + # Draw a vertical line at the current time. |
| 1178 | + axs = fig.axes[0]._mne_axs |
| 1179 | + for subax in axs: |
| 1180 | + time = subax.x_s * event.time + subax.x_t |
| 1181 | + if "time_cursor" not in subax: |
| 1182 | + subax["time_cursor"] = subax.ax.axvline( |
| 1183 | + time, |
| 1184 | + subax.pos[1], |
| 1185 | + subax.pos[1] + subax.pos[3], |
| 1186 | + color=font_color, |
| 1187 | + linewidth=0.5, |
| 1188 | + ) |
| 1189 | + else: |
| 1190 | + subax.time_cursor.set_xdata([time, time]) |
| 1191 | + # Hide the vertical line when the time is out of bounds. |
| 1192 | + subax.time_cursor.set_visible(tmin <= event.time <= tmax) |
| 1193 | + fig.canvas.draw() |
| 1194 | + |
| 1195 | + subscribe( |
| 1196 | + fig, |
| 1197 | + "time_change", |
| 1198 | + partial( |
| 1199 | + _on_time_change, |
| 1200 | + fig=fig, |
| 1201 | + tmin=np.min([t[0] for t in times]), |
| 1202 | + tmax=np.max([t[-1] for t in times]), |
| 1203 | + ), |
| 1204 | + ) |
1182 | 1205 |
|
1183 | 1206 | add_background_image(fig, fig_background) |
1184 | 1207 |
|
|
0 commit comments