[education/rkward] /: Remeber visibility-state of plots across reloads, and add buttons to
Thomas Friedrichsmeier
null at kde.org
Sun Aug 24 16:08:55 BST 2025
Git commit 50d33d5502f26b2c8cb5cdeff6db36dc7cab48e2 by Thomas Friedrichsmeier.
Committed on 24/08/2025 at 15:06.
Pushed by tfry into branch 'master'.
Remeber visibility-state of plots across reloads, and add buttons to
expand/close all
M +1 -1 VERSION.cmake
M +1 -1 rkward/rbackend/rpackages/rkward/DESCRIPTION
M +31 -1 rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
https://invent.kde.org/education/rkward/-/commit/50d33d5502f26b2c8cb5cdeff6db36dc7cab48e2
diff --git a/VERSION.cmake b/VERSION.cmake
index a0cf628f8..a50de1d77 100644
--- a/VERSION.cmake
+++ b/VERSION.cmake
@@ -1,3 +1,3 @@
# DO NOT CHANGE THIS FILE MANUALLY!
# It will be overwritten by scripts/set_dist_version.sh
-SET(RKVERSION_NUMBER 0.8.1z+0.8.2+devel4)
+SET(RKVERSION_NUMBER 0.8.1z+0.8.2+devel5)
diff --git a/rkward/rbackend/rpackages/rkward/DESCRIPTION b/rkward/rbackend/rpackages/rkward/DESCRIPTION
index a642f4618..f5e841620 100755
--- a/rkward/rbackend/rpackages/rkward/DESCRIPTION
+++ b/rkward/rbackend/rpackages/rkward/DESCRIPTION
@@ -15,7 +15,7 @@ LazyLoad: yes
Authors at R: c(person(given="Thomas", family="Friedrichsmeier", email="thomas.friedrichsmeier at kdemail.net", role=c("aut")), person(given="the RKWard", family="team",
email="rkward-devel at kde.org", role=c("cre","aut")))
Version: 0.8.2
-Date: 2025-06-03
+Date: 2025-06-04
RoxygenNote: 7.3.2
Collate:
'base_overrides.R'
diff --git a/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R b/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
index 71755e9c8..3534d600a 100644
--- a/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
+++ b/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
@@ -319,6 +319,35 @@ rk.eval.as.preview <- function(infile, outfile, echo=TRUE, env=new.env(parent=gl
}, add=TRUE)
suppressWarnings(try(rk.flush.output(ask=FALSE, style="preview", silent=TRUE)))
+ # TODO: It may be better to split out this and other long literals into separate files
+ .rk.cat.output(
+"<script>
+function expandPlots(expand) {
+ let elements = [...document.querySelectorAll('details')];
+
+ if (expand) {
+ elements.map(item => item.setAttribute('open', 'true'));
+ } else {
+ elements.map(item => item.removeAttribute('open'));
+ }
+};
+
+let plotelements = 0;
+function registerPlot(element) {
+ let index = ++plotelements;
+ if (index == 1) {
+ document.getElementById('plotbuttons').innerHTML=\'<div style=\"text-align:right\"><button onClick=\"expandPlots(true)\">Expand plots</button><button onClick=\"expandPlots(false)\">Collapse plots</button></div>\';
+ }
+ if (sessionStorage.getItem(window.location.pathname + 'plot' + index) == 'true') {
+ element.setAttribute('open', 'true');
+ }
+ element.addEventListener('toggle', (event) => {
+ sessionStorage.setItem(window.location.pathname + 'plot' + index, element.open ? 'true' : 'false')
+ });
+}
+</script>
+<span id='plotbuttons'></span>");
+
## set up handling of generated graphics:
devs <- list()
prevdev <- NULL
@@ -332,6 +361,7 @@ rk.eval.as.preview <- function(infile, outfile, echo=TRUE, env=new.env(parent=gl
# If a device already exists, let's open a new one to avoid touching it, unintentionally
# We don't want that to show in the preview, however, which may or may not plot anything at all
+ # NOTE: this does not help, if user script has unbalanced dev.off()-calls, of course
if (length(dev.list()) > 0) {
prevdev <- dev.cur()
rk.without.plot.history(RK())
@@ -354,7 +384,7 @@ rk.eval.as.preview <- function(infile, outfile, echo=TRUE, env=new.env(parent=gl
currev <- RK.revision(as.numeric(devnum))
if (devs[[devnum]] < currev) {
cur <- dev.cur()
- .rk.cat.output("<div align=\"right\"><details><summary>Plot updated (click to show)</summary><p>\n");
+ .rk.cat.output("<div align=\"right\"><details><script>registerPlot(document.currentScript.parentElement);</script><summary>Plot updated (click to show)</summary><p>\n");
#rk.graph.on(width=200, height=200, pointsize=6)
rk.graph.on()
out <- dev.cur()
More information about the rkward-tracker
mailing list