Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions docs/source/demos/fixlip/assets/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,23 +1098,30 @@
show(null);
}
});
// the demo's layout for its width: the room that its texts keep and the place of the excerpt
const layOut = () => {
setShift();
reserveRoom();
placeExcerpt();
if (state.focus === null) show(null);
};
// a new width lays the demo out again (in the next frame, outside the observer's callback)
let width = -1;
new ResizeObserver(([entry]) => {
const now = Math.round(entry.contentRect.width);
if (now === width) return;
const first = width < 0;
width = now;
requestAnimationFrame(() => {
setShift();
reserveRoom();
placeExcerpt();
if (state.focus === null) show(null);
});
// the first report is the width that the demo was built for and laid out with below
if (!first) requestAnimationFrame(layOut);
}).observe(root);

root.classList.add("fixlip-demo-ready");
reset();
setView(state.view);
// laid out before the browser paints the demo for the first time: a frame later, the demo
// would first show without the room it keeps, taller, and then move
layOut();
started = true;
}
})();
104 changes: 11 additions & 93 deletions docs/source/demos/fixlip/assets/figures.css
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,17 @@ article[role="main"] section:has(> .fixlip-opening) > h1 > a.headerlink {
.fixlip-opening {
display: flex;
flex-direction: column;
min-height: calc(100vh - var(--fixlip-opening-top, 8rem));
min-height: calc(100svh - var(--fixlip-opening-top, 8rem));
min-height: calc(100vh - var(--fixlip-opening-top, var(--fixlip-opening-guess)));
min-height: calc(100svh - var(--fixlip-opening-top, var(--fixlip-opening-guess)));
/* where the block starts until figures.js has measured it: under the title, and on a narrower
page under the bar of the docs too, so that the block does not change its height then */
--fixlip-opening-guess: 8.25rem;
}

@media (max-width: 67em) {
.fixlip-opening {
--fixlip-opening-guess: 11.3rem;
}
}

.fixlip-opening > .fixlip-demo {
Expand Down Expand Up @@ -1761,97 +1770,6 @@ article[role="main"] hr.docutils {
margin: 2.25rem 0;
}

/* -- the first page and the second page -------------------------------------------------------------- */

/* The title and the demo are the first page, and the write-up is the second. While the page is
scrolled, the first page stays where it is, and the second slides up over it like a sheet. The
first page recedes under it: it shrinks a little and dims. figures.js marks the section of the
page with fixlip-staged and measures the places: where the title and the block of the demo lie
on the page (--fixlip-title-top, --fixlip-opening-top), by how much the first page is higher than
the screen (--fixlip-over, the page scrolls by this much before the first page stays), and where
the sheet starts in the section (--fixlip-sheet-top). While it measures, the section has the
class fixlip-placing, and nothing is held. The first page lies under the section's own content
(the negative layers stay inside the section, which keeps its layers to itself), so the write-up
needs no layer of its own. Without the script, the page scrolls as one, and so it does on a
narrow screen, where the docs scroll the text column sideways and nothing can be held in it. */
@media screen and (min-width: 48.1em) {
article[role="main"] section.fixlip-staged {
position: relative;
isolation: isolate;
}

article[role="main"] section.fixlip-staged:not(.fixlip-placing) > h1,
article[role="main"] section.fixlip-staged:not(.fixlip-placing) > .fixlip-opening {
position: sticky;
z-index: -2;
}

article[role="main"] section.fixlip-staged:not(.fixlip-placing) > h1 {
top: calc(var(--fixlip-title-top, 0px) - var(--fixlip-over, 0px));
/* both parts shrink towards the same point, a little above the middle of the screen */
transform-origin: 50% calc(45vh - var(--fixlip-title-top, 0px) + var(--fixlip-over, 0px));
}

article[role="main"] section.fixlip-staged:not(.fixlip-placing) > .fixlip-opening {
top: calc(var(--fixlip-opening-top, 0px) - var(--fixlip-over, 0px));
transform-origin: 50% calc(45vh - var(--fixlip-opening-top, 0px) + var(--fixlip-over, 0px));
}

/* the sheet: the ground of the write-up, from a little under the end of the first page (so that
its shadow does not show there) to the end of the section, a little wider than the text */
article[role="main"] section.fixlip-staged::before {
content: "";
position: absolute;
z-index: -1;
top: calc(var(--fixlip-sheet-top, 100vh) + 2rem);
right: calc(-1 * var(--fixlip-sheet-bleed));
bottom: 0;
left: calc(-1 * var(--fixlip-sheet-bleed));
border-top: 1px solid var(--color-background-border, #eeebee);
border-radius: 1.25rem 1.25rem 0 0;
background: var(--color-background-primary, #ffffff);
box-shadow: 0 -1.5rem 2.5rem -1.75rem rgba(15, 18, 30, 0.35);
--fixlip-sheet-bleed: 1rem;
}

/* the edge of the sheet is the divider */
article[role="main"] section.fixlip-staged > .fixlip-opening + hr.docutils {
display: none;
}

article[role="main"] section.fixlip-staged > .fixlip-opening + hr.docutils + section.fixlip-summary {
margin-top: 4.5rem;
}
}

@media screen and (min-width: 67.1em) {
article[role="main"] section.fixlip-staged::before {
--fixlip-sheet-bleed: 2rem;
}
}

/* The first page recedes with the scroll position of the page, from where it starts to stay until
the sheet has covered most of the screen. The browser runs this with the scrolling itself. A
browser that cannot leaves the first page as it is under the sheet, and so does a reader who
asked for less motion. */
@supports (animation-timeline: scroll()) {
@media screen and (min-width: 48.1em) and (prefers-reduced-motion: no-preference) {
article[role="main"] section.fixlip-staged:not(.fixlip-placing) > h1,
article[role="main"] section.fixlip-staged:not(.fixlip-placing) > .fixlip-opening {
animation: fixlip-recede linear both;
animation-timeline: scroll(root block);
animation-range: var(--fixlip-over, 0px) calc(var(--fixlip-over, 0px) + 85vh);
}
}
}

@keyframes fixlip-recede {
to {
opacity: 0.2;
scale: 0.93;
}
}

/* -- the colors that the text names -------------------------------------------------------------------- */

/* Where the text or a caption names the red and the blue of the figures, the word is set in that
Expand Down
64 changes: 33 additions & 31 deletions docs/source/demos/fixlip/assets/figures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1545,18 +1545,12 @@
});
}

// The first page of the page is its title and the block of the demo (.fixlip-opening), which
// reaches to the end of the screen. The write-up is the second page. figures.css keeps the first
// page in place while the second slides over it, and needs the places for that: where the title
// and the block lie on the page, by how much the first page is higher than the screen, and where
// the second page starts in the section. They are measured with nothing held in place.
// The first screen of the page: the title and the block of the demo (.fixlip-opening), which
// reaches to the end of the screen (figures.css), for which it needs to know where it starts.
const opening = document.querySelector(".fixlip-opening");
const stage = opening?.parentElement;
const title = stage?.querySelector(":scope > h1");
const title = opening?.parentElement.querySelector(":scope > h1");
if (opening && title) {
stage.classList.add("fixlip-staged");
const place = () => {
stage.classList.add("fixlip-placing");
// the title stays on one line (figures.css), also in a font that runs wider than expected
title.style.fontSize = "";
const look = getComputedStyle(title);
Expand All @@ -1567,41 +1561,49 @@
const room = title.clientWidth;
if (width > room) title.style.fontSize = `${Math.floor((parseFloat(look.fontSize) * room * 10) / width) / 10}px`;
}
const down = window.scrollY;
const top = Math.round(opening.getBoundingClientRect().top + down);
stage.style.setProperty("--fixlip-title-top", `${Math.round(title.getBoundingClientRect().top + down)}px`);
stage.style.setProperty("--fixlip-opening-top", `${top}px`);
// the block now has its height for this place
const height = opening.offsetHeight;
const over = Math.max(0, top + height - document.documentElement.clientHeight);
stage.style.setProperty("--fixlip-over", `${over}px`);
const start = top + height - (stage.getBoundingClientRect().top + down);
stage.style.setProperty("--fixlip-sheet-top", `${Math.round(start)}px`);
stage.classList.remove("fixlip-placing");
const top = Math.round(opening.getBoundingClientRect().top + window.scrollY);
opening.style.setProperty("--fixlip-opening-top", `${top}px`);
};
place();
// the title wraps anew at another width, the demo grows with its note, the screen changes
const watch = new ResizeObserver(place);
watch.observe(stage);
watch.observe(opening);
// the title wraps anew at another width, the screen changes
new ResizeObserver(place).observe(opening.parentElement);
window.addEventListener("resize", place);

// the link under the demo leads to the write-up, which starts with the box of the summary (the
// label of the section lies inside the box)
const link = opening.querySelector(".fixlip-more a");
const summary = link && document.getElementById(link.hash.slice(1))?.closest("section");
// The page glides there, slower than the browser scrolls by itself: it starts and ends softly
// and takes longer for a longer way. The reader takes over with the wheel, a touch or a key.
let glide = 0;
const halt = () => cancelAnimationFrame(glide);
for (const kind of ["wheel", "touchstart", "keydown", "pointerdown"]) {
window.addEventListener(kind, halt, { passive: true });
}
link?.addEventListener("click", (event) => {
if (!summary) return;
event.preventDefault();
const calm = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
summary.scrollIntoView({ behavior: calm ? "auto" : "smooth", block: "start" });
halt();
history.replaceState(null, "", link.hash);
});
// a part of the first page that takes the focus while the write-up covers it comes into view
opening.addEventListener("focusin", () => {
if (window.scrollY > parseFloat(stage.style.getPropertyValue("--fixlip-over")) + 8) {
window.scrollTo({ top: 0 });
const from = window.scrollY;
const room = document.documentElement.scrollHeight - window.innerHeight;
const margin = parseFloat(getComputedStyle(summary).scrollMarginTop) || 0;
const to = Math.min(room, Math.round(summary.getBoundingClientRect().top + from - margin));
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
window.scrollTo({ top: to, behavior: "instant" });
return;
}
const time = Math.min(1700, Math.max(1000, 750 + Math.abs(to - from) * 0.6));
let start = 0;
const step = (now) => {
start ||= now;
const share = Math.min(1, (now - start) / time);
const eased = share < 0.5 ? 4 * share ** 3 : 1 - (-2 * share + 2) ** 3 / 2;
// the docs scroll smoothly by themselves, which would lag behind every step
window.scrollTo({ top: from + (to - from) * eased, behavior: "instant" });
if (share < 1) glide = requestAnimationFrame(step);
};
glide = requestAnimationFrame(step);
});
}

Expand Down
23 changes: 11 additions & 12 deletions docs/source/demos/fixlip/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,23 @@ explanation is defined as follows.
.. shapiq-definition:: Explanation
:name: fixlip-def-explanation

An explanation :math:`\mathbf{e}` consists of a constant :math:`\mathbf{e}_0 \in \mathbb{R}`, a
*main effect* :math:`\mathbf{e}_i \in \mathbb{R}` for each token, and an *interaction*
:math:`\mathbf{e}_{\{i,j\}} \in \mathbb{R}` for each pair of tokens, i.e.
An explanation :math:`\mathbf{e} \in \mathbb{R}^{\vert \mathcal{B} \vert}` assigns a constant
:math:`\mathbf{e}_0 \in \mathbb{R}`, a *main effect* :math:`\mathbf{e}_i \in \mathbb{R}` to each
token, and an *interaction* :math:`\mathbf{e}_{\{i,j\}} \in \mathbb{R}` to each pair of tokens,
for an *explanation basis*

.. math::

\mathbf{e} := \Big(
\mathcal{B} :=
\class{fixlip-brace}{\underbrace{\class{fixlip-braced}{
\mathbf{e}_0 \vphantom{(\mathbf{e}_{\{i,j\}})_{\{i,j\} \subseteq N_\mathcal{T}: i \neq j}}
}}_{\class{fixlip-braced}{\text{constant}\mathstrut}}}, \;
\{0\}
}}_{\class{fixlip-braced}{\text{constant}\mathstrut}}} \;\cup\;
\class{fixlip-brace}{\underbrace{\class{fixlip-braced}{
(\mathbf{e}_i)_{i \in N_\mathcal{I} \cup N_\mathcal{T}}
\vphantom{(\mathbf{e}_{\{i,j\}})_{\{i,j\} \subseteq N_\mathcal{T}: i \neq j}}
}}_{\class{fixlip-braced}{\text{main effects}\mathstrut}}}, \;
\{i: i \in N_\mathcal{I} \cup N_\mathcal{T}\}
}}_{\class{fixlip-braced}{\text{individual tokens}\mathstrut}}} \;\cup\;
\class{fixlip-brace}{\underbrace{\class{fixlip-braced}{
(\mathbf{e}_{\{i,j\}})_{\{i,j\} \subseteq N_\mathcal{I} \cup N_\mathcal{T}: i \neq j}
}}_{\class{fixlip-braced}{\text{interactions}\mathstrut}}}
\Big)
\{\{i,j\}: i,j \in N_\mathcal{I} \cup N_\mathcal{T}, i \neq j\}
}}_{\class{fixlip-braced}{\text{two-token interaction sets}\mathstrut}}}

:shapiq-statement:`fixlip-def-explanation` fixes the form of an explanation, but not its values. The
values should describe how the prediction changes when tokens are removed from the input. FIxLIP
Expand Down