global: snapshot

This commit is contained in:
nym21
2026-02-12 22:52:57 +01:00
parent 3bc20a0a46
commit b779edc0d6
60 changed files with 8720 additions and 1504 deletions

View File

@@ -9,7 +9,7 @@ export const canCapture = !ios || canShare;
* @param {HTMLCanvasElement} args.screenshot
* @param {number} args.chartWidth
* @param {HTMLElement} args.parent
* @param {{ top: { element: HTMLElement }, bottom: { element: HTMLElement } }} args.legends
* @param {{ element: HTMLElement }[]} args.legends
*/
export function capture({ screenshot, chartWidth, parent, legends }) {
const dpr = screenshot.width / chartWidth;
@@ -22,8 +22,8 @@ export function capture({ screenshot, chartWidth, parent, legends }) {
const title = (parent.querySelector("h1")?.textContent ?? "").toUpperCase();
const hasTitle = title.length > 0;
const hasTopLegend = legends.top.element.children.length > 0;
const hasBottomLegend = legends.bottom.element.children.length > 0;
const hasTopLegend = legends[0].element.children.length > 0;
const hasBottomLegend = legends[1].element.children.length > 0;
const titleOffset = hasTitle ? titleHeight : 0;
const topLegendOffset = hasTopLegend ? legendHeight : 0;
const bottomOffset = hasBottomLegend ? legendHeight : 0;
@@ -80,7 +80,7 @@ export function capture({ screenshot, chartWidth, parent, legends }) {
// Top legend
if (hasTopLegend) {
drawLegend(legends.top.element, pad + titleOffset + topLegendOffset / 2);
drawLegend(legends[0].element, pad + titleOffset + topLegendOffset / 2);
}
// Chart
@@ -89,7 +89,7 @@ export function capture({ screenshot, chartWidth, parent, legends }) {
// Bottom legend
if (hasBottomLegend) {
drawLegend(
legends.bottom.element,
legends[1].element,
pad +
titleOffset +
topLegendOffset +

File diff suppressed because it is too large Load Diff

View File

@@ -9,9 +9,13 @@ export function createLegend() {
scroller.append(items);
element.append(scroller);
scroller.addEventListener("wheel", (e) => e.stopPropagation());
scroller.addEventListener("touchstart", (e) => e.stopPropagation());
scroller.addEventListener("touchmove", (e) => e.stopPropagation());
/** @param {HTMLElement} el */
function captureScroll(el) {
el.addEventListener("wheel", (e) => e.stopPropagation());
el.addEventListener("touchstart", (e) => e.stopPropagation());
el.addEventListener("touchmove", (e) => e.stopPropagation());
}
captureScroll(items);
/** @type {AnySeries | null} */
let hoveredSeries = null;
@@ -37,6 +41,7 @@ export function createLegend() {
let prefix = null;
const separator = window.document.createElement("span");
separator.textContent = "|";
captureScroll(separator);
return {
element,
@@ -47,6 +52,7 @@ export function createLegend() {
if (prefix) prefix.replaceWith(el);
else scroller.insertBefore(el, items);
prefix = el;
captureScroll(el);
el.after(separator);
},
/**