Generate HTML representation of the animation. Parameters ---------- fps : int, optional Movie frame rate (per second). If not set, the frame rate from the animation's frame interval. embed_frames : bool, optional default_mode
(self, fps=None, embed_frames=True, default_mode=None)
| 1351 | return 'Video too large to embed.' |
| 1352 | |
| 1353 | def to_jshtml(self, fps=None, embed_frames=True, default_mode=None): |
| 1354 | """ |
| 1355 | Generate HTML representation of the animation. |
| 1356 | |
| 1357 | Parameters |
| 1358 | ---------- |
| 1359 | fps : int, optional |
| 1360 | Movie frame rate (per second). If not set, the frame rate from |
| 1361 | the animation's frame interval. |
| 1362 | embed_frames : bool, optional |
| 1363 | default_mode : str, optional |
| 1364 | What to do when the animation ends. Must be one of ``{'loop', |
| 1365 | 'once', 'reflect'}``. Defaults to ``'loop'`` if the *repeat* |
| 1366 | parameter is True, otherwise ``'once'``. |
| 1367 | |
| 1368 | Returns |
| 1369 | ------- |
| 1370 | str |
| 1371 | An HTML representation of the animation embedded as a js object as |
| 1372 | produced with the `.HTMLWriter`. |
| 1373 | """ |
| 1374 | if fps is None and hasattr(self, '_interval'): |
| 1375 | # Convert interval in ms to frames per second |
| 1376 | fps = 1000 / self._interval |
| 1377 | |
| 1378 | # If we're not given a default mode, choose one base on the value of |
| 1379 | # the _repeat attribute |
| 1380 | if default_mode is None: |
| 1381 | default_mode = 'loop' if getattr(self, '_repeat', |
| 1382 | False) else 'once' |
| 1383 | |
| 1384 | if not hasattr(self, "_html_representation"): |
| 1385 | # Can't open a NamedTemporaryFile twice on Windows, so use a |
| 1386 | # TemporaryDirectory instead. |
| 1387 | with TemporaryDirectory() as tmpdir: |
| 1388 | path = Path(tmpdir, "temp.html") |
| 1389 | writer = HTMLWriter(fps=fps, |
| 1390 | embed_frames=embed_frames, |
| 1391 | default_mode=default_mode) |
| 1392 | self.save(str(path), writer=writer) |
| 1393 | self._html_representation = path.read_text() |
| 1394 | |
| 1395 | return self._html_representation |
| 1396 | |
| 1397 | def _repr_html_(self): |
| 1398 | """IPython display hook for rendering.""" |
no test coverage detected