diff --git a/doc/changes/latest.inc b/doc/changes/latest.inc index a791ca728c7..837599dcd16 100644 --- a/doc/changes/latest.inc +++ b/doc/changes/latest.inc @@ -19,7 +19,7 @@ Enhancements ~~~~~~~~~~~~ - Update the ``notebook`` 3d backend to use ``ipyvtk_simple`` for a better integration within ``Jupyter`` (:gh:`8503` by `Guillaume Favelier`_) -- Add toggle-all button to :class:`mne.Report` HTML (:gh:`8723` by `Eric Larson`_) +- Add toggle-all button to :class:`mne.Report` HTML and ``width`` argument to :meth:`mne.Report.add_bem_to_section` (:gh:`8723` by `Eric Larson`_) - Speed up :func:`mne.inverse_sparse.tf_mixed_norm` using STFT/ISTFT linearity (:gh:`8697` by `Eric Larson`_) @@ -35,6 +35,8 @@ Bugs - Fix bug with :func:`mne.io.read_raw_nicolet` where header type values such as num_sample and duration_in_sec where not parsed properly (:gh:`8712` by `Alex Gramfort`_) +- Fix bug with ``replace`` argument of :meth:`mne.Report.add_bem_to_section` and :meth:`mne.Report.add_slider_to_section` (:gh:`8723` by `Eric Larson`_) + API changes ~~~~~~~~~~~ diff --git a/mne/report.py b/mne/report.py index d0dc542a939..1da31621aa8 100644 --- a/mne/report.py +++ b/mne/report.py @@ -24,11 +24,12 @@ from .io import read_raw_fif, read_info from .io.pick import _DATA_CH_TYPES_SPLIT from .source_space import _mri_orientation -from .utils import (logger, verbose, get_subjects_dir, warn, +from .utils import (logger, verbose, get_subjects_dir, warn, _ensure_int, fill_doc, _check_option, _validate_type, _safe_input) from .viz import (plot_events, plot_alignment, plot_cov, plot_projs_topomap, plot_compare_evokeds) from .viz.misc import _plot_mri_contours, _get_bem_plotting_surfaces +from .viz.utils import _ndarray_to_fig, _figure_agg from .forward import read_forward_solution from .epochs import read_epochs from .minimum_norm import read_inverse_operator @@ -52,14 +53,6 @@ ############################################################################### # PLOTTING FUNCTIONS -def _ndarray_to_fig(img): - """Convert to MPL figure, adapted from matplotlib.image.imsave.""" - figsize = np.array(img.shape[:2][::-1]) / 100. - fig = _figure_agg(dpi=100, figsize=figsize, frameon=False) - fig.figimage(img) - return fig - - def _fig_to_img(fig, image_format='png', scale=None, **kwargs): """Plot figure and create a binary image.""" # fig can be ndarray, mpl Figure, Mayavi Figure, or callable that produces @@ -401,14 +394,6 @@ def open_report(fname, **params): ############################################################################### # IMAGE FUNCTIONS -def _figure_agg(**kwargs): - from matplotlib.figure import Figure - from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas - fig = Figure(**kwargs) - FigureCanvas(fig) - return fig - - def _build_image_png(data, cmap='gray'): """Build an image encoded in base64.""" import matplotlib.pyplot as plt @@ -417,7 +402,7 @@ def _build_image_png(data, cmap='gray'): if figsize[0] == 1: figsize = tuple(figsize[1:]) data = data[:, :, 0] - fig = _figure_agg(figsize=figsize, dpi=1.0, frameon=False) + fig = _figure_agg(figsize=figsize, dpi=100, frameon=False) cmap = getattr(plt.cm, cmap, plt.cm.gray) fig.figimage(data, cmap=cmap) output = BytesIO() @@ -546,6 +531,7 @@ def _build_html_slider(slices_range, slides_klass, slider_id, const [all, on, off] = getAllOnOff(); const a = $('.mnetoggleall-btn').children(); if (all.length == on.length) + /* If this character is changed, it should be changed in the HTML below as well */ a.html('☒') else a.html('☑') @@ -575,11 +561,28 @@ def _build_html_slider(slices_range, slides_klass, slider_id, if (location.hash) shiftWindow(); window.addEventListener("hashchange", shiftWindow); + /* Prevent navbar from covering content */ + function fixNavbarPadding() { + $('body').css('padding-top', parseInt($('#main-navbar').css("height"))-30); + } + $(window).resize(function () { fixNavbarPadding(); }); + $(window).load(function () { fixNavbarPadding(); }); + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.attributeName === "class") { + var attributeValue = $(mutation.target).prop(mutation.attributeName); + if (attributeValue.includes(" in") || attributeValue.includes(" collapse")) { + fixNavbarPadding(); + } + } + }); + }); + /* Update things when document is ready */ $( document ).ready(function() { updateToggleAllButton(); + observer.observe($("#viewnavbar")[0], {attributes: true}); }); -
-