Skip to content

Commit

Permalink
Merge tag '23.2.2'
Browse files Browse the repository at this point in the history
23.2.2 (August 19, 2024)

Bug-fix release in the 23.2.x series.

CHANGES
-------

**Full Changelog**: 23.2.1...23.2.2

* ENH: Support PNGs and JPGs in reportlets (#126)
  • Loading branch information
effigies committed Aug 19, 2024
2 parents 12ed4b7 + dc54385 commit 8d602f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
23.2.2 (August 19, 2024)
========================
Bug-fix release in the 23.2.x series.

CHANGES
-------

**Full Changelog**: https://github.com/nipreps/nireports/compare/23.2.1...23.2.2

* ENH: Support PNGs and JPGs in reportlets (#126)


23.2.1 (May 07, 2024)
=====================
Bug-fix release in the 23.2.x series.
Expand Down
47 changes: 36 additions & 11 deletions nireports/assembler/reportlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@
from nireports.assembler import data
from nireports.assembler.misc import dict2html, read_crashfile

SVG_SNIPPET = [
"""\
IMG_SNIPPET = """\
<div class="reportlet">
<object class="svg-reportlet" type="image/svg+xml" data="./{name}" style="{style}">
Problem loading figure {name}. If the link below works, please try \
reloading the report in your browser.</object>
<img class="{ext}-reportlet" src="./{name}" style="{style}" />
</div>
<small>Get figure file: <a href="./{name}" target="_blank">{name}</a></small>
""",
"""\
"""

SVG_SNIPPET = """\
<div class="reportlet">
<img class="svg-reportlet" src="./{name}" style="{style}" />
<object class="{ext}-reportlet" type="image/{ext}+xml" data="./{name}" style="{style}">
Problem loading figure {name}. If the link below works, please try \
reloading the report in your browser.</object>
</div>
<small>Get figure file: <a href="./{name}" target="_blank">{name}</a></small>
""",
]
"""

METADATA_ACCORDION_BLOCK = """\
<div class="accordion accordion-flush" id="{metadata_id}">
Expand Down Expand Up @@ -265,10 +264,36 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat
style = {"width": "100%"} if is_static else {}
style.update(config.get("style", {}))

contents = SVG_SNIPPET[is_static].format(
snippet = IMG_SNIPPET if is_static else SVG_SNIPPET
contents = snippet.format(
ext=ext[1:],
name=html_anchor,
style="; ".join(f"{k}: {v}" for k, v in style.items()),
)
elif ext in (".png", ".jpg", ".jpeg"):
entities = dict(bidsfile.entities)
if desc_text:
desc_text = desc_text.format(**entities)

try:
html_anchor = src.relative_to(out_dir)
except ValueError:
html_anchor = src.relative_to(Path(layout.root))
dst = out_dir / html_anchor
dst.parent.mkdir(parents=True, exist_ok=True)
copyfile(src, dst, copy=True, use_hardlink=True)

style = {"width": "100%"}
style.update(config.get("style", {}))

snippet = IMG_SNIPPET
contents = snippet.format(
ext=ext[1:],
name=html_anchor,
style="; ".join(f"{k}: {v}" for k, v in style.items()),
)
else:
raise RuntimeError(f"Unsupported file extension: {ext}")

if contents:
self.components.append((contents, desc_text))
Expand Down

0 comments on commit 8d602f7

Please sign in to comment.