Skip to content

Build your personal knowledge base with Trilium Notes

client/content manager/space usage: UI improvements

Adorian Doranbe2e7961ae45
diff --git a/apps/client/src/test/dom_events.ts b/apps/client/src/test/dom_events.ts
new file mode 100644
index 0000000000..0883b41f74
--- /dev/null
+++ b/apps/client/src/test/dom_events.ts
@@ -0,0 +1,19 @@
+/**
+ * Teaches happy-dom the mouse `on*` properties every real browser exposes.
+ *
+ * Preact picks the event name to listen for by probing the element for the matching IDL property.
+ * happy-dom's SVG (and some HTML) prototypes lack the mouse ones, so without this a `onMouseEnter`
+ * prop registers a listener under a case-mangled name and dispatched events never reach it — the
+ * component works in the browser but appears inert under test.
+ *
+ * Call from a spec's `beforeAll` when it dispatches mouse events at components.
+ */
+export function enableMouseEventProperties() {
+ for (const prototype of [ SVGElement.prototype, HTMLElement.prototype ]) {
+ for (const name of [ "onmouseenter", "onmouseleave", "onmousemove", "onclick" ]) {
+ if (!(name in prototype)) {
+ Object.defineProperty(prototype, name, { value: null, writable: true });
+ }
+ }
+ }
+}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 4f0118ac5b..6a00b842da 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2660,16 +2660,19 @@
"sort_by_date_created": "Creation date",
"no_items": "No active content found.",
"no_items_hint": "Scripts, themes, templates and snippets you create will be listed here.",
- "section_active_content": "Active Content",
+ "section_active_content": "Active Content & Templates",
"section_space_usage": "Space Usage"
},
"space_usage": {
"loading": "Measuring space usage...",
"view_overview": "Overview",
"view_browse": "Browse",
- "other_notes": "Other notes",
- "hidden_notes": "Hidden notes",
- "deleted_notes": "Deleted notes",
+ "other_notes_one": "1 other note",
+ "other_notes_other": "Other {{count}} notes",
+ "hidden_notes_one": "1 hidden note",
+ "hidden_notes_other": "{{count}} hidden notes",
+ "deleted_notes_one": "1 deleted note",
+ "deleted_notes_other": "{{count}} deleted notes",
"note_body": "Note content",
"revisions": "Revisions",
"others_notes_one": "{{count}} more note ({{size}})",
@@ -2684,6 +2687,7 @@
"center_subtree_size": "Subtree: <Size/>",
"center_subtree_size_hint": "Space this note and all of its descendants actually occupy, revisions included, with duplicated content counted once",
"back": "Back",
+ "current_note": "Current note:",
"status_content_one": "Total content size: {{size}} in {{count}} note ({{revisionsSize}} revisions, {{attachmentsSize}} note attachments)",
"status_content_other": "Total content size: {{size}} in {{count}} notes ({{revisionsSize}} revisions, {{attachmentsSize}} note attachments)",
"status_content_hint": "Space the content actually occupies: all notes (hidden ones included), attachments and revisions, with duplicated content counted once. The bracketed figures are the space only revisions, respectively only attachments, hold.",
diff --git a/apps/client/src/widgets/react/SegmentedChoice.tsx b/apps/client/src/widgets/react/SegmentedChoice.tsx
index d61d0095e3..ea3adec395 100644
--- a/apps/client/src/widgets/react/SegmentedChoice.tsx
+++ b/apps/client/src/widgets/react/SegmentedChoice.tsx
@@ -10,15 +10,16 @@ interface SegmentedChoiceProps<T extends string> {
*/
currentValue: string;
onChange: (newValue: T) => void;
+ className?: string;
}
/**
* A row of buttons acting as one exclusive choice, the current one highlighted — for switching
* between a few named views or sections where a dropdown would hide the alternatives.
*/
-export default function SegmentedChoice<T extends string>({ options, currentValue, onChange }: SegmentedChoiceProps<T>) {
+export default function SegmentedChoice<T extends string>({ options, currentValue, onChange, className }: SegmentedChoiceProps<T>) {
return (
- <ButtonGroup size="sm">
+ <ButtonGroup size="sm" className={className}>
{options.map(({ value, label }) => (
<Button
key={value}
diff --git a/apps/client/src/widgets/react/charts/DonutChart.css b/apps/client/src/widgets/react/charts/DonutChart.css
index 4f431ef2e9..16e8c2e835 100644
--- a/apps/client/src/widgets/react/charts/DonutChart.css
+++ b/apps/client/src/widgets/react/charts/DonutChart.css
@@ -31,8 +31,16 @@
);
}
+ /* An outline that traces the arc rather than its box: `outline` on a dashed circle would frame
+ the entire ring, since that is the element's extent. Blur-less shadows in the four directions
+ hug the painted shape instead, and stay inside the inter-segment gap. */
.donut-segment:hover {
- filter: brightness(1.12);
+ filter:
+ brightness(1.12)
+ drop-shadow(2px 0 0 var(--input-focus-outline-color))
+ drop-shadow(-2px 0 0 var(--input-focus-outline-color))
+ drop-shadow(0 2px 0 var(--input-focus-outline-color))
+ drop-shadow(0 -2px 0 var(--input-focus-outline-color));
}
.donut-clickable {
@@ -55,22 +63,6 @@
pointer-events: auto;
}
- /* The cursor-following tooltip. It must never catch the pointer, or it would flicker by
- stealing the hover it reports. */
- .donut-chart-tooltip {
- position: absolute;
- pointer-events: none;
- transform: translate(14px, 14px);
- }
-
- .donut-chart-tooltip-flipped {
- transform: translate(calc(-100% - 14px), 14px);
- }
-
- .donut-chart-tooltip .tooltip-inner {
- white-space: nowrap;
- max-width: none;
- }
}
@keyframes donut-sweep {
diff --git a/apps/client/src/widgets/react/charts/DonutChart.render.spec.tsx b/apps/client/src/widgets/react/charts/DonutChart.render.spec.tsx
index 0dbc160a6f..80ff9df704 100644
--- a/apps/client/src/widgets/react/charts/DonutChart.render.spec.tsx
+++ b/apps/client/src/widgets/react/charts/DonutChart.render.spec.tsx
@@ -1,20 +1,10 @@
import { render } from "preact";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
+import { enableMouseEventProperties } from "../../../test/dom_events";
import DonutChart, { type DonutRing } from "./DonutChart";
-// Preact decides the event name by probing for the element's on* IDL property; happy-dom's SVG (and
-// some HTML) prototypes lack the mouse ones, so without this the handlers register under a
-// case-mangled name and dispatched events never connect. Real browsers have these properties.
-beforeAll(() => {
- for (const prototype of [ SVGElement.prototype, HTMLElement.prototype ]) {
- for (const name of [ "onmouseenter", "onmouseleave", "onmousemove", "onclick" ]) {
- if (!(name in prototype)) {
- Object.defineProperty(prototype, name, { value: null, writable: true });
- }
- }
- }
-});
+beforeAll(enableMouseEventProperties);
let container: HTMLDivElement | undefined;
@@ -24,14 +14,9 @@ function renderChart(rings: DonutRing<string>[], center?: preact.ComponentChildr
return container;
}
-/** happy-dom lays nothing out, so the chart box is stated explicitly for the flip math. */
-function statChartBox(probe: HTMLElement) {
+function chartOf(probe: HTMLElement) {
const chart = probe.querySelector<HTMLElement>(".donut-chart");
if (!chart) throw new Error("No chart rendered");
- chart.getBoundingClientRect = () => ({
- left: 0, top: 0, width: 200, height: 200, right: 200, bottom: 200, x: 0, y: 0,
- toJSON: () => ({})
- } as DOMRect);
return chart;
}
@@ -99,47 +84,69 @@ describe("DonutChart rendering", () => {
expect(onSegmentClick.mock.calls[0][0]).toMatchObject({ id: "b", data: "b" });
});
- it("shows the cursor-following tooltip on hover, moves it, flips it past midline and hides it", async () => {
+ it("shows the cursor-following tooltip on hover, moves it, and hides it on leave", async () => {
const probe = renderChart([ ring() ]);
- const chart = statChartBox(probe);
+ const chart = chartOf(probe);
const [ a ] = [ ...probe.querySelectorAll<SVGCircleElement>("circle") ];
a.dispatchEvent(new MouseEvent("mouseenter", { clientX: 30, clientY: 40 }));
await flushRender();
- const tooltip = probe.querySelector<HTMLElement>(".donut-chart-tooltip");
+ const tooltip = probe.querySelector<HTMLElement>(".chart-tooltip");
expect(tooltip?.textContent).toBe("A tip");
// The Trilium look depends on riding the real tooltip classes.
expect(tooltip?.classList.contains("tooltip")).toBe(true);
expect(tooltip?.classList.contains("show")).toBe(true);
+ // Positioned fixed, straight from the viewport coordinates, so no clipping ancestor cuts it.
expect(tooltip?.style.left).toBe("30px");
- expect(tooltip?.classList.contains("donut-chart-tooltip-flipped")).toBe(false);
+ expect(tooltip?.style.top).toBe("40px");
- chart.dispatchEvent(new MouseEvent("mousemove", { clientX: 150, clientY: 60 }));
+ chart.dispatchEvent(new MouseEvent("mousemove", { clientX: 50, clientY: 60 }));
await flushRender();
- const moved = probe.querySelector<HTMLElement>(".donut-chart-tooltip");
- expect(moved?.style.left).toBe("150px");
+ const moved = probe.querySelector<HTMLElement>(".chart-tooltip");
+ expect(moved?.style.left).toBe("50px");
expect(moved?.style.top).toBe("60px");
- expect(moved?.classList.contains("donut-chart-tooltip-flipped")).toBe(true);
a.dispatchEvent(new MouseEvent("mouseleave"));
await flushRender();
- expect(probe.querySelector(".donut-chart-tooltip")).toBeNull();
+ expect(probe.querySelector(".chart-tooltip")).toBeNull();
+ });
+
+ it("flips the bubble at the viewport's midlines so it never runs off-screen", async () => {
+ const probe = renderChart([ ring() ]);
+ const [ a ] = [ ...probe.querySelectorAll<SVGCircleElement>("circle") ];
+ const flipsOf = (x: number, y: number) => {
+ a.dispatchEvent(new MouseEvent("mouseenter", { clientX: x, clientY: y }));
+ return flushRender().then(() => {
+ const classes = probe.querySelector(".chart-tooltip")?.classList;
+ return {
+ x: classes?.contains("chart-tooltip-flip-x"),
+ y: classes?.contains("chart-tooltip-flip-y")
+ };
+ });
+ };
+
+ const nearOrigin = { x: window.innerWidth * 0.25, y: window.innerHeight * 0.25 };
+ const nearCorner = { x: window.innerWidth * 0.75, y: window.innerHeight * 0.75 };
+
+ expect(await flipsOf(nearOrigin.x, nearOrigin.y)).toEqual({ x: false, y: false });
+ expect(await flipsOf(nearCorner.x, nearOrigin.y)).toEqual({ x: true, y: false });
+ expect(await flipsOf(nearOrigin.x, nearCorner.y)).toEqual({ x: false, y: true });
+ expect(await flipsOf(nearCorner.x, nearCorner.y)).toEqual({ x: true, y: true });
});
it("shows no tooltip for a segment without one, and clears on leaving the chart", async () => {
const probe = renderChart([ ring() ]);
- statChartBox(probe);
const [ a, b ] = [ ...probe.querySelectorAll<SVGCircleElement>("circle") ];
b.dispatchEvent(new MouseEvent("mouseenter", { clientX: 10, clientY: 10 }));
await flushRender();
- expect(probe.querySelector(".donut-chart-tooltip")).toBeNull();
+ expect(probe.querySelector(".chart-tooltip")).toBeNull();
a.dispatchEvent(new MouseEvent("mouseenter", { clientX: 10, clientY: 10 }));
await flushRender();
- expect(probe.querySelector(".donut-chart-tooltip")).not.toBeNull();
+ expect(probe.querySelector(".chart-tooltip")).not.toBeNull();
probe.querySelector(".donut-chart")?.dispatchEvent(new MouseEvent("mouseleave"));
await flushRender();
- expect(probe.querySelector(".donut-chart-tooltip")).toBeNull();
+ expect(probe.querySelector(".chart-tooltip")).toBeNull();
});
});
diff --git a/apps/client/src/widgets/react/charts/DonutChart.tsx b/apps/client/src/widgets/react/charts/DonutChart.tsx
index 3329ecece5..19c4bc5b2f 100644
--- a/apps/client/src/widgets/react/charts/DonutChart.tsx
+++ b/apps/client/src/widgets/react/charts/DonutChart.tsx
@@ -2,7 +2,8 @@ import "./DonutChart.css";
import clsx from "clsx";
import type { ComponentChildren } from "preact";
-import { useRef, useState } from "preact/hooks";
+
+import { useChartTooltip } from "./chart_tooltip";
export interface DonutSegment<T = unknown> {
/** Stable identity for reconciliation; unique within the ring. */
@@ -43,14 +44,6 @@ export const DONUT_VIEW_SIZE = 420;
const SEGMENT_GAP = 3;
-interface HoverState {
- text: string;
- x: number;
- y: number;
- /** Near the right edge the tooltip sits to the cursor's left instead of running off the chart. */
- flipped: boolean;
-}
-
/**
* One or more concentric donut rings, drawn as circle strokes: each segment is a `stroke-dasharray`
* arc, which is what makes navigation animate — dash geometry is plain CSS, so segments sweep in on
@@ -58,36 +51,18 @@ interface HoverState {
* height and keeps a square aspect where the width allows; center content overlays the hole as
* regular HTML.
*
- * Segment tooltips are the chart's own cursor-following bubble (Trilium-styled via `tooltip-inner`)
- * rather than anything anchored to the element: a dashed circle's bounding box is the whole ring,
- * so an anchored tooltip would hover far from the segment it describes.
+ * Segment tooltips are the shared cursor-following chart bubble rather than anything anchored to
+ * the element: a dashed circle's extent is the whole ring, so an anchored tooltip would hover far
+ * from the segment it describes.
*/
export default function DonutChart<T>({ rings, className, children }: DonutChartProps<T>) {
const half = DONUT_VIEW_SIZE / 2;
- const containerRef = useRef<HTMLDivElement>(null);
- const [ hover, setHover ] = useState<HoverState | null>(null);
-
- const positionOf = (event: { clientX: number, clientY: number }) => {
- const rect = containerRef.current?.getBoundingClientRect();
-
- /* v8 ignore next 3 -- the events only fire from inside the rendered container */
- if (!rect) {
- return { x: 0, y: 0, flipped: false };
- }
-
- const x = event.clientX - rect.left;
- return { x, y: event.clientY - rect.top, flipped: x > rect.width / 2 };
- };
+ const { containerRef, containerProps, showTooltip, hideTooltip, tooltipNode } = useChartTooltip<HTMLDivElement>();
return (
- <div
- ref={containerRef}
- className={clsx("donut-chart", className)}
- // Mouse events rather than pointer events: hover has no meaning on touch anyway, and
- // pointer handlers don't register correctly under the test DOM (see the render spec).
- onMouseMove={(event) => setHover((current) => current && { ...current, ...positionOf(event) })}
- onMouseLeave={() => setHover(null)}
- >
+ // Mouse events rather than pointer events: hover has no meaning on touch anyway, and
+ // pointer handlers don't register correctly under the test DOM (see the render spec).
+ <div ref={containerRef} className={clsx("donut-chart", className)} {...containerProps}>
<svg viewBox={`${-half} ${-half} ${DONUT_VIEW_SIZE} ${DONUT_VIEW_SIZE}`}>
{/* Rotated so every ring starts at 12 o'clock. */}
<g transform="rotate(-90)">
@@ -95,25 +70,15 @@ export default function DonutChart<T>({ rings, className, children }: DonutChart
<Ring
key={ring.id}
ring={ring}
- onSegmentHover={(segment, event) => setHover(segment?.tooltip && event
- ? { text: segment.tooltip, ...positionOf(event) }
- : null)}
+ onSegmentHover={(segment, event) => segment && event
+ ? showTooltip(segment.tooltip, event)
+ : hideTooltip()}
/>
))}
</g>
</svg>
{children && <div className="donut-chart-center">{children}</div>}
- {hover && (
- // The `tooltip show` classes matter: the themes set the tooltip colors on `.tooltip`
- // and scope the text color to `.tooltip .tooltip-inner` — a bare inner keeps the
- // theme's background but inherits the page's text color.
- <div
- className={clsx("tooltip", "show", "donut-chart-tooltip", hover.flipped && "donut-chart-tooltip-flipped")}
- style={{ left: hover.x, top: hover.y }}
- >
- <div className="tooltip-inner">{hover.text}</div>
- </div>
- )}
+ {tooltipNode}
</div>
);
}
diff --git a/apps/client/src/widgets/react/charts/Treemap.spec.tsx b/apps/client/src/widgets/react/charts/Treemap.spec.tsx
index ba278ded6a..6e603f31f9 100644
--- a/apps/client/src/widgets/react/charts/Treemap.spec.tsx
+++ b/apps/client/src/widgets/react/charts/Treemap.spec.tsx
@@ -1,5 +1,9 @@
import { render } from "preact";
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
+
+import { enableMouseEventProperties } from "../../../test/dom_events";
+
+beforeAll(enableMouseEventProperties);
// The container never gets a real layout under happy-dom, so the size hook is stubbed to give the
// treemap a canvas; everything else renders for real.
@@ -45,7 +49,7 @@ const ROOT: TreemapItem<string> = {
{ id: "small", value: 100, data: "small" }
]
},
- { id: "bucket", value: 100, className: "bucket-cell" },
+ { id: "bucket", value: 100, className: "bucket-cell", tooltip: "A crowd of notes" },
{ id: "empty", value: 0 },
{ id: "no-value" }
]
@@ -100,6 +104,33 @@ describe("Treemap", () => {
expect(renderTreemap(ROOT).querySelectorAll(".treemap-cell").length).toBe(0);
});
+ it("shows the app's own tooltip for a cell that carries one, and none for the others", async () => {
+ const probe = renderTreemap(ROOT);
+ const flushRender = () => new Promise((resolve) => setTimeout(resolve));
+
+ probe.querySelector('[data-href="#root/folder/big"]')
+ ?.dispatchEvent(new MouseEvent("mouseenter", { clientX: 10, clientY: 10 }));
+ await flushRender();
+ // A note cell is described by the note preview tooltip instead, via its data-href.
+ expect(probe.querySelector(".chart-tooltip")).toBeNull();
+
+ probe.querySelector(".bucket-cell")
+ ?.dispatchEvent(new MouseEvent("mouseenter", { clientX: 10, clientY: 10 }));
+ await flushRender();
+ const tooltip = probe.querySelector<HTMLElement>(".chart-tooltip");
+ expect(tooltip?.textContent).toBe("A crowd of notes");
+ expect(tooltip?.classList.contains("tooltip")).toBe(true);
+
+ // No native tooltip anywhere: the browser's own bubble is never what the app shows.
+ for (const cell of probe.querySelectorAll(".treemap-cell")) {
+ expect(cell.getAttribute("title")).toBeNull();
+ }
+
+ probe.querySelector(".bucket-cell")?.dispatchEvent(new MouseEvent("mouseleave"));
+ await flushRender();
+ expect(probe.querySelector(".chart-tooltip")).toBeNull();
+ });
+
it("gives bigger values proportionally bigger areas", () => {
const probe = renderTreemap(ROOT);
const areaOf = (selector: string) => {
diff --git a/apps/client/src/widgets/react/charts/Treemap.tsx b/apps/client/src/widgets/react/charts/Treemap.tsx
index 61f6240f44..a2dd475b6f 100644
--- a/apps/client/src/widgets/react/charts/Treemap.tsx
+++ b/apps/client/src/widgets/react/charts/Treemap.tsx
@@ -2,9 +2,10 @@ import "./Treemap.css";
import clsx from "clsx";
import { hierarchy, treemap, treemapSquarify } from "d3-hierarchy";
-import { useMemo, useRef } from "preact/hooks";
+import { useMemo } from "preact/hooks";
import { useElementSize } from "../hooks";
+import { useChartTooltip } from "./chart_tooltip";
export interface TreemapItem<T = unknown> {
/** Stable identity for reconciliation; unique across the whole tree. */
@@ -19,10 +20,11 @@ export interface TreemapItem<T = unknown> {
hue?: number;
/** Extra classes on the cell, for special entries the consumer styles itself. */
className?: string;
+ /** Text for the chart's own tooltip, for cells that identify themselves rather than a note. */
+ tooltip?: string;
/**
* Attributes sprinkled onto the cell element — the cells carry no text of their own, so this
- * is where identity comes from: `data-href` opts into the note tooltip, `title` gives plain
- * cells a native one.
+ * is the other way identity is given: `data-href` opts a cell into the note preview tooltip.
*/
attributes?: Record<string, string>;
/** The consumer's payload, handed back on click. */
@@ -51,7 +53,7 @@ const CELL_GAP = 3;
* surface color, which keeps the map coherent under any user theme.
*/
export default function Treemap<T>({ root, onItemClick, className }: TreemapProps<T>) {
- const containerRef = useRef<HTMLDivElement>(null);
+ const { containerRef, containerProps, showTooltip, hideTooltip, tooltipNode } = useChartTooltip<HTMLDivElement>();
const size = useElementSize(containerRef);
const width = Math.floor(size?.width ?? 0);
const height = Math.floor(size?.height ?? 0);
@@ -75,7 +77,7 @@ export default function Treemap<T>({ root, onItemClick, className }: TreemapProp
}, [ root, width, height ]);
return (
- <div ref={containerRef} className={clsx("treemap", className)}>
+ <div ref={containerRef} className={clsx("treemap", className)} {...containerProps}>
{cells.map((cell) => {
const item = cell.data;
const cellWidth = cell.x1 - cell.x0;
@@ -98,10 +100,13 @@ export default function Treemap<T>({ root, onItemClick, className }: TreemapProp
...(item.hue !== undefined && { "--treemap-hue": String(item.hue) })
}}
onClick={onItemClick && (() => onItemClick(item))}
+ onMouseEnter={(event) => showTooltip(item.tooltip, event)}
+ onMouseLeave={hideTooltip}
{...item.attributes}
/>
);
})}
+ {tooltipNode}
</div>
);
}
diff --git a/apps/client/src/widgets/react/charts/chart_tooltip.css b/apps/client/src/widgets/react/charts/chart_tooltip.css
new file mode 100644
index 0000000000..b5afc19371
--- /dev/null
+++ b/apps/client/src/widgets/react/charts/chart_tooltip.css
@@ -0,0 +1,28 @@
+/* The chart's own tooltip bubble: the app's tooltip look (`tooltip`/`tooltip-inner`, which the
+ themes paint), positioned from the pointer instead of anchored to a mark.
+
+ Fixed rather than absolute, so it escapes the charts' own clipping and the scroll container's —
+ a treemap fills its pane, and a cell near the bottom edge would otherwise show a cut-off bubble.
+ It must never catch the pointer, or it would flicker by stealing the hover it reports. */
+.chart-tooltip {
+ position: fixed;
+ pointer-events: none;
+ transform: translate(14px, 14px);
+}
+
+.chart-tooltip.chart-tooltip-flip-x {
+ transform: translate(calc(-100% - 14px), 14px);
+}
+
+.chart-tooltip.chart-tooltip-flip-y {
+ transform: translate(14px, calc(-100% - 14px));
+}
+
+.chart-tooltip.chart-tooltip-flip-x.chart-tooltip-flip-y {
+ transform: translate(calc(-100% - 14px), calc(-100% - 14px));
+}
+
+.chart-tooltip .tooltip-inner {
+ max-width: none;
+ white-space: nowrap;
+}
diff --git a/apps/client/src/widgets/react/charts/chart_tooltip.tsx b/apps/client/src/widgets/react/charts/chart_tooltip.tsx
new file mode 100644
index 0000000000..80e2283003
--- /dev/null
+++ b/apps/client/src/widgets/react/charts/chart_tooltip.tsx
@@ -0,0 +1,64 @@
+import "./chart_tooltip.css";
+
+import clsx from "clsx";
+import { useRef, useState } from "preact/hooks";
+
+interface ChartTooltipState {
+ text: string;
+ /** Viewport coordinates: the bubble is positioned fixed, so it escapes any clipping ancestor. */
+ x: number;
+ y: number;
+ /** Past the middle of the viewport the bubble sits before the cursor rather than running off. */
+ flipX: boolean;
+ flipY: boolean;
+}
+
+/**
+ * The tooltip a chart shows for the mark under the cursor: the app's own tooltip look, following
+ * the pointer.
+ *
+ * Charts can't use the anchored tooltips the rest of the UI uses. A donut segment is a dashed
+ * circle whose element extent is the whole ring, so an anchored bubble would float far from the arc
+ * it describes; a treemap can hold hundreds of cells, and giving each one its own tooltip instance
+ * would be wasteful. One pointer-positioned bubble per chart solves both.
+ */
+export function useChartTooltip<T extends HTMLElement>() {
+ const containerRef = useRef<T>(null);
+ const [ tooltip, setTooltip ] = useState<ChartTooltipState | null>(null);
+
+ const positionOf = (event: { clientX: number, clientY: number }) => ({
+ x: event.clientX,
+ y: event.clientY,
+ flipX: event.clientX > window.innerWidth / 2,
+ flipY: event.clientY > window.innerHeight / 2
+ });
+
+ return {
+ containerRef,
+ /** Spread on the chart's own element, so the bubble tracks the pointer and leaves with it. */
+ containerProps: {
+ onMouseMove: (event: { clientX: number, clientY: number }) =>
+ setTooltip((current) => current && { ...current, ...positionOf(event) }),
+ onMouseLeave: () => setTooltip(null)
+ },
+ /** Called by a mark on hover; a mark without tooltip text shows nothing. */
+ showTooltip: (text: string | undefined, event: { clientX: number, clientY: number }) =>
+ setTooltip(text ? { text, ...positionOf(event) } : null),
+ hideTooltip: () => setTooltip(null),
+ /** Render inside the chart, after its marks. */
+ tooltipNode: tooltip && (
+ // The `tooltip show` classes matter: the themes set the colours on `.tooltip` and scope
+ // the text colour to `.tooltip .tooltip-inner`, so a bare inner would inherit the page's.
+ <div
+ className={clsx(
+ "tooltip", "show", "chart-tooltip",
+ tooltip.flipX && "chart-tooltip-flip-x",
+ tooltip.flipY && "chart-tooltip-flip-y"
+ )}
+ style={{ left: tooltip.x, top: tooltip.y }}
+ >
+ <div className="tooltip-inner">{tooltip.text}</div>
+ </div>
+ )
+ };
+}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx
index 7e551a90f3..a151b56ffd 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/active_content.tsx
@@ -235,6 +235,7 @@ export default function ActiveContent({ note, sectionSwitcher }: ContentManagerS
</div>
<span className="active-content-toolbar-label">{t("content_manager.view_mode")}</span>
<SegmentedChoice
+ className="content-manager-view-choice"
options={VIEW_MODES}
currentValue={viewMode}
onChange={(newValue) => void setViewMode(newValue)}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/index.css b/apps/client/src/widgets/type_widgets/options/content_manager/index.css
new file mode 100644
index 0000000000..babb31d12a
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/index.css
@@ -0,0 +1,12 @@
+/* The header's action slot right-aligns what it holds, which suits page-level actions. This switch
+ is the page's primary navigation rather than an action, so it leads the row instead: the auto
+ margin on its trailing side pushes it back to the start. */
+.content-manager-section-switcher {
+ margin-inline-end: auto;
+}
+
+/* Each section's own view choice reads as secondary to the section switch above it. Set on the
+ buttons, which carry their own font size and so would not inherit one from the group. */
+.content-manager-view-choice button {
+ font-size: 0.85em;
+}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx
index a2bc1ef969..f1d8bbde80 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/index.tsx
@@ -1,3 +1,5 @@
+import "./index.css";
+
import type { ComponentChildren } from "preact";
import { useState } from "preact/hooks";
@@ -26,7 +28,9 @@ export interface ContentManagerSectionProps extends TypeWidgetProps {
export default function ContentManagerSettings(props: TypeWidgetProps) {
const [ section, setSection ] = useState<ContentManagerSection>("activeContent");
const sectionSwitcher = (
- <SegmentedChoice options={SECTIONS} currentValue={section} onChange={setSection} />
+ <div className="content-manager-section-switcher">
+ <SegmentedChoice options={SECTIONS} currentValue={section} onChange={setSection} />
+ </div>
);
return section === "spaceUsage"
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css
index 0148846bcd..b6b2cc669a 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.css
@@ -7,6 +7,7 @@
.space-usage-breadcrumb {
display: flex;
flex: 0 0 auto;
+ justify-content: center;
align-items: center;
gap: 0.35em;
padding-block: 6px;
@@ -14,6 +15,12 @@
white-space: nowrap;
}
+ /* Names what the path leads to, so a lone root crumb still reads as a location. */
+ .space-usage-crumb-label {
+ flex-shrink: 0;
+ opacity: 0.7;
+ }
+
.space-usage-crumb {
display: inline-block;
overflow: hidden;
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
index 70c99e9035..960c1b1e28 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/browse.tsx
@@ -34,7 +34,7 @@ export default function Browse() {
thickness: CHILDREN_RING_THICKNESS,
segments: usage ? buildChildrenSegments(usage, {
getTitle,
- deletedNotesLabel: t("space_usage.deleted_notes"),
+ deletedNotesLabel: t("space_usage.deleted_notes", { count: usage.deletedNotes?.noteCount ?? 0 }),
makeTooltip: segmentTooltip,
makeOthersTooltip: (count, size) =>
t("space_usage.others_notes", { count, size: formatSize(size) })
@@ -51,6 +51,7 @@ export default function Browse() {
return (
<div className="space-usage-browse">
<nav className="space-usage-breadcrumb">
+ <span className="space-usage-crumb-label">{t("space_usage.current_note")}</span>
{stack.map((id, index) => (
<Fragment key={`${index}/${id}`}>
{index > 0 && <span className="space-usage-crumb-separator" aria-hidden="true">›</span>}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css
index 2df9c1b1de..b92634ee69 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.css
@@ -18,6 +18,13 @@
min-height: 0;
}
+/* Lives in the sticky page header, which supplies its own spacing. The view choice sits at the
+ trailing edge, opposite the section switch that leads the row above it. */
+.space-usage-toolbar {
+ display: flex;
+ justify-content: flex-end;
+}
+
.space-usage-section {
display: flex;
flex: 1 1 auto;
@@ -49,24 +56,21 @@
}
}
-/* The bucket cells stand for no single note: identity comes from the border and texture rather
- than a hue (user themes make any fixed palette unreliable), and they respond to nothing.
+/* The bucket cells stand for no single note but for a crowd of them: the diagonal stripes set them
+ apart from the solid note cells without spending a hue (user themes make any fixed palette
+ unreliable), their hover tooltip says which crowd, and they respond to nothing.
Repeats .treemap-cell to outrank the primitive's cursor rule. */
.space-usage-overview {
.treemap-cell.treemap-cell-other,
.treemap-cell.treemap-cell-hidden,
- .treemap-cell.treemap-cell-deleted {
- --treemap-cell-background: transparent;
-
- border: 1px dashed var(--main-border-color);
- cursor: default;
- }
-
.treemap-cell.treemap-cell-deleted {
--treemap-cell-background: repeating-linear-gradient(
-45deg,
var(--accented-background-color) 0 5px,
transparent 5px 10px
);
+
+ border: 1px dashed var(--main-border-color);
+ cursor: default;
}
}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
index 5cedef8a6e..4892760df1 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/index.tsx
@@ -1,10 +1,11 @@
import "./index.css";
import type { SpaceUsageOverviewResponse } from "@triliumnext/commons";
-import { useState } from "preact/hooks";
+import { useMemo, useRef, useState } from "preact/hooks";
import { t } from "../../../../../services/i18n";
import { formatSize } from "../../../../../services/utils";
+import { useStaticTooltip } from "../../../../react/hooks";
import SegmentedChoice from "../../../../react/SegmentedChoice";
import OptionsPageHeader from "../../components/OptionsPageHeader";
import type { ContentManagerSectionProps } from "../index";
@@ -25,7 +26,14 @@ export default function SpaceUsage({ sectionSwitcher }: ContentManagerSectionPro
return (
<div className="space-usage-section">
<OptionsPageHeader actions={sectionSwitcher} below={
- <SegmentedChoice options={VIEWS} currentValue={view} onChange={setView} />
+ <div className="space-usage-toolbar">
+ <SegmentedChoice
+ className="content-manager-view-choice"
+ options={VIEWS}
+ currentValue={view}
+ onChange={setView}
+ />
+ </div>
} />
{view === "browse" && <Browse />}
@@ -35,27 +43,41 @@ export default function SpaceUsage({ sectionSwitcher }: ContentManagerSectionPro
{overview && (
<footer className="space-usage-status">
- <span title={t("space_usage.status_content_hint")}>
- {t("space_usage.status_content", {
+ <StatusEntry
+ text={t("space_usage.status_content", {
count: overview.content.noteCount,
size: formatSize(overview.content.size),
revisionsSize: formatSize(overview.content.revisionsSize),
attachmentsSize: formatSize(overview.content.attachmentsSize)
})}
- </span>
+ hint={t("space_usage.status_content_hint")}
+ />
<span className="space-usage-status-separator" aria-hidden="true">–</span>
- <span title={t("space_usage.status_deleted_hint")}>
- {t("space_usage.status_deleted", {
+ <StatusEntry
+ text={t("space_usage.status_deleted", {
count: overview.deletedNotes.noteCount,
size: formatSize(overview.deletedNotes.size)
})}
- </span>
+ hint={t("space_usage.status_deleted_hint")}
+ />
</footer>
)}
</div>
);
}
+/**
+ * One figure of the status line, with the app's tooltip explaining how it is measured — the
+ * distinctions between the figures (deduplicated vs per entity, what each covers) are worth a
+ * sentence, but not one taking up the bar itself.
+ */
+function StatusEntry({ text, hint }: { text: string, hint: string }) {
+ const ref = useRef<HTMLSpanElement>(null);
+ useStaticTooltip(ref, useMemo(() => ({ title: hint, placement: "top" }), [ hint ]));
+
+ return <span ref={ref}>{text}</span>;
+}
+
const VIEWS: { value: SpaceUsageView, label: string }[] = [
{ value: "overview", label: t("space_usage.view_overview") },
{ value: "browse", label: t("space_usage.view_browse") }
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx
index bb824fbbbe..b37507b3c8 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/note_usage_donut.tsx
@@ -3,7 +3,7 @@ import "./note_usage_donut.css";
import type { SpaceUsageNoteResponse } from "@triliumnext/commons";
import clsx from "clsx";
import type { ComponentChildren } from "preact";
-import { useMemo } from "preact/hooks";
+import { useMemo, useRef } from "preact/hooks";
import type React from "react";
import { Trans } from "react-i18next";
@@ -11,6 +11,7 @@ import appContext from "../../../../../components/app_context";
import { t } from "../../../../../services/i18n";
import { formatSize } from "../../../../../services/utils";
import DonutChart, { type DonutRing } from "../../../../react/charts/DonutChart";
+import { useStaticTooltip } from "../../../../react/hooks";
import { buildCompositionSegments, type UsageSegmentData, type UsageTooltipKind } from "./donut_segments";
export const COMPOSITION_RING_RADIUS = 133;
@@ -71,25 +72,37 @@ export default function NoteUsageDonut({ usage, title, notePath, outerRings = []
});
}}
>{title}</a>
- <span className="note-usage-donut-size" title={t("space_usage.center_note_size_hint")}>
- <SizeLine i18nKey="space_usage.center_note_size" size={usage.noteContentSize} />
- </span>
- <span className="note-usage-donut-size" title={t("space_usage.center_subtree_size_hint")}>
- <SizeLine i18nKey="space_usage.center_subtree_size" size={usage.subtreeContentSize} />
- </span>
+ <SizeLine
+ i18nKey="space_usage.center_note_size"
+ hintKey="space_usage.center_note_size_hint"
+ size={usage.noteContentSize}
+ />
+ <SizeLine
+ i18nKey="space_usage.center_subtree_size"
+ hintKey="space_usage.center_subtree_size_hint"
+ size={usage.subtreeContentSize}
+ />
</DonutChart>
);
}
-/** One labelled center line, the value emphasized; `<Trans>` lets translations reorder the parts. */
-function SizeLine({ i18nKey, size }: { i18nKey: string, size: number }) {
+/**
+ * One labelled center line, the value emphasized, with the app's tooltip explaining what the figure
+ * covers. `<Trans>` lets translations put the value wherever their wording needs it.
+ */
+function SizeLine({ i18nKey, hintKey, size }: { i18nKey: string, hintKey: string, size: number }) {
+ const ref = useRef<HTMLSpanElement>(null);
+ useStaticTooltip(ref, useMemo(() => ({ title: t(hintKey), placement: "bottom" }), [ hintKey ]));
+
return (
- <Trans
- i18nKey={i18nKey}
- components={{
- Size: <span className="note-usage-donut-size-value">{formatSize(size)}</span> as React.ReactElement
- }}
- />
+ <span ref={ref} className="note-usage-donut-size">
+ <Trans
+ i18nKey={i18nKey}
+ components={{
+ Size: <span className="note-usage-donut-size-value">{formatSize(size)}</span> as React.ReactElement
+ }}
+ />
+ </span>
);
}
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx
index 08af929052..ae2c896e2b 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview.tsx
@@ -8,10 +8,12 @@ import { buildOverviewModel, type OverviewCell } from "./overview_model";
/** The treemap over the whole database: every large note at its tree location. */
export default function Overview({ overview }: { overview: SpaceUsageOverviewResponse }) {
+ // The labels are formatted here rather than in the model, which stays free of i18n: a bucket
+ // stands for a crowd, so its tooltip names how many notes it holds.
const model = useMemo(() => buildOverviewModel(overview, {
- otherNotesLabel: t("space_usage.other_notes"),
- hiddenNotesLabel: t("space_usage.hidden_notes"),
- deletedNotesLabel: t("space_usage.deleted_notes"),
+ otherNotesLabel: t("space_usage.other_notes", { count: overview.otherNotes.noteCount }),
+ hiddenNotesLabel: t("space_usage.hidden_notes", { count: overview.hiddenNotes.noteCount }),
+ deletedNotesLabel: t("space_usage.deleted_notes", { count: overview.deletedNotes.noteCount }),
includeRevisions: false
}), [ overview ]);
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts
index 97ccddf881..76af076393 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.spec.ts
@@ -102,7 +102,7 @@ describe("buildOverviewModel", () => {
expect(childById(withRevisions, "/hidden-notes").value).toBe(5);
});
- it("appends inert bucket cells, identified by a plain title rather than a note tooltip", () => {
+ it("appends inert bucket cells, identified by the chart tooltip rather than a note preview", () => {
const model = build(response([], {
otherNotes: { size: 11, revisionsSize: 0, noteCount: 3 },
hiddenNotes: { size: 7, revisionsSize: 5, noteCount: 40 },
@@ -113,18 +113,20 @@ describe("buildOverviewModel", () => {
expect(other.value).toBe(11);
expect(other.hue).toBeUndefined();
expect(other.data).toEqual({});
- expect(other.attributes).toEqual({ title: "Other notes" });
+ expect(other.tooltip).toBe("Other notes");
+ // No `data-href`: a crowd of notes has no note preview to show.
+ expect(other.attributes).toBeUndefined();
// Hidden space gets a cell too — every byte the status line counts is on the map.
const hidden = childById(model, "/hidden-notes");
expect(hidden.value).toBe(7);
expect(hidden.className).toBe("treemap-cell-hidden");
- expect(hidden.attributes).toEqual({ title: "Hidden notes" });
+ expect(hidden.tooltip).toBe("Hidden notes");
const deleted = childById(model, "/deleted-notes");
expect(deleted.value).toBe(22);
expect(deleted.className).toBe("treemap-cell-deleted");
- expect(deleted.attributes).toEqual({ title: "Deleted notes" });
+ expect(deleted.tooltip).toBe("Deleted notes");
});
it("places an entry for the root itself as a top-level cell", () => {
diff --git a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts
index 0b7ee69766..1508acea9b 100644
--- a/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts
+++ b/apps/client/src/widgets/type_widgets/options/content_manager/space_usage/overview_model.ts
@@ -24,7 +24,7 @@ interface OverviewModelOptions {
* the status line counts has a cell somewhere.
*
* The cells carry no text — identity comes from hovering: note cells get the note preview tooltip
- * via `data-href`, the bucket cells a plain `title`.
+ * via `data-href`, the bucket cells the chart's own tooltip naming the crowd they stand for.
*/
export function buildOverviewModel(
overview: SpaceUsageOverviewResponse,
@@ -92,21 +92,21 @@ export function buildOverviewModel(
id: "/other-notes",
value: overview.otherNotes.size + (includeRevisions ? overview.otherNotes.revisionsSize : 0),
className: "treemap-cell-other",
- attributes: { title: otherNotesLabel },
+ tooltip: otherNotesLabel,
data: {}
},
{
id: "/hidden-notes",
value: overview.hiddenNotes.size + (includeRevisions ? overview.hiddenNotes.revisionsSize : 0),
className: "treemap-cell-hidden",
- attributes: { title: hiddenNotesLabel },
+ tooltip: hiddenNotesLabel,
data: {}
},
{
id: "/deleted-notes",
value: overview.deletedNotes.size,
className: "treemap-cell-deleted",
- attributes: { title: deletedNotesLabel },
+ tooltip: deletedNotesLabel,
data: {}
}
);