@openshift-migration-advisor/shared-components 0.27.0 → 0.28.0-47af17e06309

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/charts/MigrationDonutChart.d.ts.map +1 -1
  2. package/dist/charts/MigrationDonutChart.js +7 -0
  3. package/dist/report/ChartExportProvider.d.ts +4 -3
  4. package/dist/report/ChartExportProvider.d.ts.map +1 -1
  5. package/dist/report/ChartExportProvider.js +7 -4
  6. package/dist/report/ClustersOverview.d.ts +24 -0
  7. package/dist/report/ClustersOverview.d.ts.map +1 -0
  8. package/dist/report/ClustersOverview.js +228 -0
  9. package/dist/report/ClustersOverviewStyles.d.ts +12 -0
  10. package/dist/report/ClustersOverviewStyles.d.ts.map +1 -0
  11. package/dist/report/ClustersOverviewStyles.js +101 -0
  12. package/dist/report/CpuAndMemoryOverview.d.ts +19 -0
  13. package/dist/report/CpuAndMemoryOverview.d.ts.map +1 -0
  14. package/dist/report/CpuAndMemoryOverview.js +112 -0
  15. package/dist/report/FeatureStatusBadge.js +1 -1
  16. package/dist/report/StorageOverview.d.ts +27 -0
  17. package/dist/report/StorageOverview.d.ts.map +1 -0
  18. package/dist/report/StorageOverview.js +319 -0
  19. package/dist/report/VMMigrationStatus.d.ts +33 -0
  20. package/dist/report/VMMigrationStatus.d.ts.map +1 -0
  21. package/dist/report/VMMigrationStatus.js +129 -0
  22. package/dist/report/captureChartElement.d.ts +6 -1
  23. package/dist/report/captureChartElement.d.ts.map +1 -1
  24. package/dist/report/captureChartElement.js +41 -12
  25. package/dist/report/chartExport.d.ts +23 -0
  26. package/dist/report/chartExport.d.ts.map +1 -1
  27. package/dist/report/chartExport.js +21 -1
  28. package/dist/report/chartExportContext.d.ts +6 -2
  29. package/dist/report/chartExportContext.d.ts.map +1 -1
  30. package/dist/report/dashboardStyles.d.ts +6 -0
  31. package/dist/report/dashboardStyles.d.ts.map +1 -1
  32. package/dist/report/dashboardStyles.js +7 -4
  33. package/dist/report/index.d.ts +6 -2
  34. package/dist/report/index.d.ts.map +1 -1
  35. package/dist/report/index.js +4 -0
  36. package/dist/report/pdfExport.d.ts +2 -2
  37. package/dist/report/pdfExport.d.ts.map +1 -1
  38. package/dist/report/pdfExport.js +52 -3
  39. package/package.json +2 -2
  40. package/src/charts/MigrationDonutChart.tsx +9 -0
  41. package/src/report/ChartExportProvider.tsx +18 -6
  42. package/src/report/ClustersOverview.tsx +451 -0
  43. package/src/report/ClustersOverviewStyles.ts +110 -0
  44. package/src/report/CpuAndMemoryOverview.tsx +277 -0
  45. package/src/report/FeatureStatusBadge.tsx +1 -1
  46. package/src/report/StorageOverview.tsx +629 -0
  47. package/src/report/VMMigrationStatus.tsx +358 -0
  48. package/src/report/__tests__/ChartExportProvider.test.tsx +110 -2
  49. package/src/report/__tests__/ClustersOverview.test.tsx +241 -0
  50. package/src/report/__tests__/CpuAndMemoryOverview.test.tsx +200 -0
  51. package/src/report/__tests__/StorageOverview.test.tsx +223 -0
  52. package/src/report/__tests__/VMMigrationStatus.test.tsx +178 -0
  53. package/src/report/__tests__/captureChartElement.test.ts +120 -0
  54. package/src/report/__tests__/chartExportPackagers.test.ts +75 -0
  55. package/src/report/captureChartElement.ts +55 -10
  56. package/src/report/chartExport.ts +41 -1
  57. package/src/report/chartExportContext.tsx +9 -1
  58. package/src/report/dashboardStyles.ts +7 -4
  59. package/src/report/index.ts +22 -0
  60. package/src/report/pdfExport.ts +81 -2
@@ -0,0 +1,178 @@
1
+ import "@testing-library/jest-dom";
2
+ import { cleanup, render, screen } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { afterEach, describe, expect, it, vi } from "vitest";
5
+ import type { MigrationDonutChartProps } from "../../charts/MigrationDonutChart.js";
6
+ import { chartColorFailure, chartColorSuccess } from "../constants.js";
7
+ import { VMMigrationStatus } from "../VMMigrationStatus.js";
8
+
9
+ const donutProps = vi.hoisted(() => ({
10
+ current: null as MigrationDonutChartProps | null,
11
+ }));
12
+
13
+ vi.mock("../../charts/MigrationDonutChart.js", () => ({
14
+ MigrationDonutChart: (props: MigrationDonutChartProps): JSX.Element => {
15
+ donutProps.current = props;
16
+ return (
17
+ <div data-testid="migration-donut">
18
+ {props.title} {props.subTitle}
19
+ </div>
20
+ );
21
+ },
22
+ }));
23
+
24
+ afterEach(() => {
25
+ donutProps.current = null;
26
+ cleanup();
27
+ });
28
+
29
+ const renderedDonut = (): MigrationDonutChartProps => {
30
+ const props = donutProps.current;
31
+ if (!props) {
32
+ throw new Error("expected a migration-status donut to render");
33
+ }
34
+ return props;
35
+ };
36
+
37
+ const selectView = async (name: string): Promise<void> => {
38
+ const user = userEvent.setup();
39
+ await user.click(
40
+ screen.getByRole("button", { name: "No issues vs with issues" }),
41
+ );
42
+ await user.click(screen.getByRole("menuitem", { name }));
43
+ };
44
+
45
+ describe("VMMigrationStatus", () => {
46
+ it("shows the empty state when there are no VMs", () => {
47
+ render(<VMMigrationStatus data={{ migratable: 0, nonMigratable: 0 }} />);
48
+
49
+ expect(screen.getByText("VM Migration Status")).toBeInTheDocument();
50
+ expect(
51
+ screen.getByText("Migration status data not collected"),
52
+ ).toBeInTheDocument();
53
+ expect(screen.queryByTestId("migration-donut")).not.toBeInTheDocument();
54
+ });
55
+
56
+ it("renders the migratable vs not-ready donut", () => {
57
+ render(<VMMigrationStatus data={{ migratable: 7, nonMigratable: 3 }} />);
58
+
59
+ expect(screen.getByTestId("migration-donut")).toHaveTextContent("10 VMs");
60
+
61
+ const props = renderedDonut();
62
+ expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
63
+ ["Migratable", 7],
64
+ ["Not ready for migration", 3],
65
+ ]);
66
+ expect(props.legend).toEqual({
67
+ Migratable: chartColorSuccess,
68
+ "Not ready for migration": chartColorFailure,
69
+ });
70
+ expect(props.legendVariant).toBe("html");
71
+ expect(props.subTitleColor).toBe(
72
+ "var(--pf-t--global--text--color--subtle)",
73
+ );
74
+ });
75
+
76
+ it("drills down into readiness when a donut slice is clicked", () => {
77
+ const onReadinessSelect = vi.fn();
78
+ render(
79
+ <VMMigrationStatus
80
+ data={{ migratable: 7, nonMigratable: 3 }}
81
+ onReadinessSelect={onReadinessSelect}
82
+ />,
83
+ );
84
+
85
+ const props = renderedDonut();
86
+ const [migratable, notReady] = props.data;
87
+ if (!migratable || !notReady) {
88
+ throw new Error("expected both readiness slices");
89
+ }
90
+
91
+ props.onItemClick?.(migratable);
92
+ expect(onReadinessSelect).toHaveBeenLastCalledWith(true);
93
+
94
+ props.onItemClick?.(notReady);
95
+ expect(onReadinessSelect).toHaveBeenLastCalledWith(false);
96
+ });
97
+
98
+ it("forwards the center-title click", () => {
99
+ const onTitleClick = vi.fn();
100
+ render(
101
+ <VMMigrationStatus
102
+ data={{ migratable: 1, nonMigratable: 0 }}
103
+ onTitleClick={onTitleClick}
104
+ />,
105
+ );
106
+
107
+ renderedDonut().onTitleClick?.();
108
+ expect(onTitleClick).toHaveBeenCalledTimes(1);
109
+ });
110
+
111
+ it("renders the issue breakdown bars in category order", async () => {
112
+ render(
113
+ <VMMigrationStatus
114
+ data={{ migratable: 1, nonMigratable: 9 }}
115
+ issuesBreakdown={{
116
+ critical: 3,
117
+ error: 2,
118
+ warning: 5,
119
+ information: 1,
120
+ advisory: 0,
121
+ }}
122
+ />,
123
+ );
124
+
125
+ await selectView("With issues breakdown");
126
+
127
+ expect(screen.queryByTestId("migration-donut")).not.toBeInTheDocument();
128
+ expect(screen.getByTitle("Critical: 3 VMs")).toBeInTheDocument();
129
+ expect(screen.getByTitle("Warning: 5 VMs")).toBeInTheDocument();
130
+ expect(screen.getByTitle("Advisory: 0 VMs")).toBeInTheDocument();
131
+ expect(
132
+ screen.getByText(/Totals may exceed the unique VM count/),
133
+ ).toBeInTheDocument();
134
+ });
135
+
136
+ it("drills down into a concern category when a bar is clicked", async () => {
137
+ const onCategorySelect = vi.fn();
138
+ render(
139
+ <VMMigrationStatus
140
+ data={{ migratable: 1, nonMigratable: 9 }}
141
+ issuesBreakdown={{
142
+ critical: 3,
143
+ error: 2,
144
+ warning: 5,
145
+ information: 1,
146
+ advisory: 0,
147
+ }}
148
+ onCategorySelect={onCategorySelect}
149
+ />,
150
+ );
151
+
152
+ await selectView("With issues breakdown");
153
+ await userEvent.setup().click(screen.getByTitle("Warning: 5 VMs"));
154
+
155
+ expect(onCategorySelect).toHaveBeenCalledWith("Warning");
156
+ });
157
+
158
+ it("shows the breakdown empty state when no issue data was collected", async () => {
159
+ render(<VMMigrationStatus data={{ migratable: 1, nonMigratable: 9 }} />);
160
+
161
+ await selectView("With issues breakdown");
162
+
163
+ expect(
164
+ screen.getByText("Issues breakdown data not collected"),
165
+ ).toBeInTheDocument();
166
+ });
167
+
168
+ it("passes the chart legend variant through", () => {
169
+ render(
170
+ <VMMigrationStatus
171
+ legendVariant="chart"
172
+ data={{ migratable: 1, nonMigratable: 1 }}
173
+ />,
174
+ );
175
+
176
+ expect(renderedDonut().legendVariant).toBe("chart");
177
+ });
178
+ });
@@ -16,6 +16,12 @@ const mockedHtml2Canvas = vi.mocked(html2canvas);
16
16
  afterEach(() => {
17
17
  mockedHtml2Canvas.mockClear();
18
18
  document.body.replaceChildren();
19
+ document.documentElement.classList.remove(
20
+ "pf-v6-theme-dark",
21
+ "pf-v5-theme-dark",
22
+ );
23
+ document.documentElement.style.colorScheme = "";
24
+ document.body.style.colorScheme = "";
19
25
  });
20
26
 
21
27
  describe("captureChartElement", () => {
@@ -129,4 +135,118 @@ describe("captureChartElement", () => {
129
135
 
130
136
  await captureChartElement(root);
131
137
  });
138
+
139
+ it("applies light theme on the clone and leaves the live document dark", async () => {
140
+ document.documentElement.classList.add("pf-v6-theme-dark");
141
+ const root = document.createElement("div");
142
+ const card = document.createElement("div");
143
+ card.className = "pf-v6-c-card";
144
+ card.style.backgroundColor = "rgb(30, 30, 30)";
145
+ card.style.border = "1px solid rgb(80, 80, 80)";
146
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
147
+ const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
148
+ text.style.fill = "rgb(255, 255, 255)";
149
+ text.textContent = "42";
150
+ svg.append(text);
151
+ card.append(svg);
152
+ root.append(card);
153
+ document.body.append(root);
154
+
155
+ mockedHtml2Canvas.mockImplementation(async (_element, options) => {
156
+ expect(
157
+ document.documentElement.classList.contains("pf-v6-theme-dark"),
158
+ ).toBe(true);
159
+
160
+ const clonedDoc = document.implementation.createHTMLDocument("export");
161
+ clonedDoc.documentElement.classList.add("pf-v6-theme-dark");
162
+ const cloneRoot = clonedDoc.createElement("div");
163
+ const cloneCard = clonedDoc.createElement("div");
164
+ cloneCard.className = "pf-v6-c-card";
165
+ cloneCard.style.backgroundColor = "rgb(30, 30, 30)";
166
+ const cloneSvg = clonedDoc.createElementNS(
167
+ "http://www.w3.org/2000/svg",
168
+ "svg",
169
+ );
170
+ const cloneText = clonedDoc.createElementNS(
171
+ "http://www.w3.org/2000/svg",
172
+ "text",
173
+ );
174
+ cloneText.style.fill = "rgb(255, 255, 255)";
175
+ cloneSvg.append(cloneText);
176
+ cloneCard.append(cloneSvg);
177
+ cloneRoot.append(cloneCard);
178
+ clonedDoc.body.append(cloneRoot);
179
+
180
+ await options?.onclone?.(clonedDoc, cloneRoot);
181
+
182
+ expect(
183
+ clonedDoc.documentElement.classList.contains("pf-v6-theme-dark"),
184
+ ).toBe(false);
185
+ expect(
186
+ document.documentElement.classList.contains("pf-v6-theme-dark"),
187
+ ).toBe(true);
188
+ expect(cloneCard.style.backgroundColor).toBe("rgb(255, 255, 255)");
189
+ expect(cloneCard.style.borderColor).toBe("rgb(224, 224, 224)");
190
+ expect(cloneText.style.fill).toBe("rgb(21, 21, 21)");
191
+
192
+ const canvas = document.createElement("canvas");
193
+ canvas.width = 1;
194
+ canvas.height = 1;
195
+ return canvas;
196
+ });
197
+
198
+ await captureChartElement(root);
199
+
200
+ expect(
201
+ document.documentElement.classList.contains("pf-v6-theme-dark"),
202
+ ).toBe(true);
203
+ expect(card.style.backgroundColor).toBe("rgb(30, 30, 30)");
204
+ });
205
+
206
+ it("relights tables and labels via the clone cascade, not by hand-painting them", async () => {
207
+ document.documentElement.classList.add("pf-v6-theme-dark");
208
+ const root = document.createElement("div");
209
+ const label = document.createElement("span");
210
+ label.className = "pf-v6-c-label pf-m-compact pf-m-outline";
211
+ const labelContent = document.createElement("span");
212
+ labelContent.className = "pf-v6-c-label__content";
213
+ label.append(labelContent);
214
+ root.append(label);
215
+ document.body.append(root);
216
+
217
+ mockedHtml2Canvas.mockImplementation(async (_element, options) => {
218
+ const clonedDoc = document.implementation.createHTMLDocument("export");
219
+ clonedDoc.documentElement.classList.add("pf-v6-theme-dark");
220
+ const cloneRoot = clonedDoc.createElement("div");
221
+ const cloneTh = clonedDoc.createElement("th");
222
+ cloneTh.className = "pf-v6-c-table__th";
223
+ const cloneLabelContent = clonedDoc.createElement("span");
224
+ cloneLabelContent.className = "pf-v6-c-label__content";
225
+ cloneRoot.append(cloneTh, cloneLabelContent);
226
+ clonedDoc.body.append(cloneRoot);
227
+
228
+ await options?.onclone?.(clonedDoc, cloneRoot);
229
+
230
+ // Dropping the dark class off the clone root is what relights these
231
+ // surfaces — the cascade does the work. We must NOT hand-paint inline
232
+ // colors onto PatternFly table/label nodes, and the live page stays dark.
233
+ expect(
234
+ clonedDoc.documentElement.classList.contains("pf-v6-theme-dark"),
235
+ ).toBe(false);
236
+ expect(cloneTh.style.backgroundColor).toBe("");
237
+ expect(cloneLabelContent.style.backgroundColor).toBe("");
238
+
239
+ const canvas = document.createElement("canvas");
240
+ canvas.width = 1;
241
+ canvas.height = 1;
242
+ return canvas;
243
+ });
244
+
245
+ await captureChartElement(root);
246
+
247
+ expect(
248
+ document.documentElement.classList.contains("pf-v6-theme-dark"),
249
+ ).toBe(true);
250
+ expect(labelContent.style.backgroundColor).toBe("");
251
+ });
132
252
  });
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import {
3
+ applyLightThemeToDocument,
3
4
  chartExportViewsFromLabels,
4
5
  restoreChartExportViews,
5
6
  sortRegisteredChartsByDocumentOrder,
@@ -7,6 +8,7 @@ import {
7
8
  } from "../chartExport.js";
8
9
  import { getChartExportFilename } from "../chartExportFilenames.js";
9
10
  import { buildHtmlReport, escapeHtml } from "../htmlExport.js";
11
+ import { buildPdfFromCharts } from "../pdfExport.js";
10
12
  import {
11
13
  fitPdfImageSize,
12
14
  placePdfBlock,
@@ -198,6 +200,63 @@ describe("placePdfBlock", () => {
198
200
  });
199
201
  });
200
202
 
203
+ describe("buildPdfFromCharts with extra text pages", () => {
204
+ it("appends a text page even when there are no chart captures", async () => {
205
+ const blob = await buildPdfFromCharts([], "Report", [
206
+ {
207
+ title: "Cluster sizing recommendations",
208
+ items: [
209
+ { label: "Cluster name", value: "cluster-1" },
210
+ { label: "Target platform", value: "Bare metal" },
211
+ {
212
+ label: "Total nodes",
213
+ value: "6 (3 workers + 3 control plane)",
214
+ },
215
+ { label: "Failover capacity", value: "1 failover nodes" },
216
+ { label: "Worker node size", value: "8 CPU, 32 GB memory" },
217
+ {
218
+ label: "Control plane node size",
219
+ value: "16 CPU, 64 GB memory",
220
+ },
221
+ ],
222
+ footer: "Note: estimates only.",
223
+ },
224
+ ]);
225
+
226
+ expect(blob).toBeInstanceOf(Blob);
227
+ expect(blob.size).toBeGreaterThan(0);
228
+ expect(blob.type).toBe("application/pdf");
229
+ });
230
+
231
+ it("paginates extra pages with many rows without throwing", async () => {
232
+ const manyItems = Array.from({ length: 60 }, (_, index) => ({
233
+ label: `Field ${index}`,
234
+ value: `Value ${index}`,
235
+ }));
236
+
237
+ const blob = await buildPdfFromCharts([], "Report", [
238
+ { title: "Cluster sizing recommendations", items: manyItems },
239
+ ]);
240
+
241
+ expect(blob.size).toBeGreaterThan(0);
242
+ });
243
+
244
+ it("supports multiple extra pages (e.g. one per sized cluster)", async () => {
245
+ const blob = await buildPdfFromCharts([], "Report", [
246
+ {
247
+ title: "Cluster sizing recommendations — cluster-a",
248
+ items: [{ label: "Cluster name", value: "cluster-a" }],
249
+ },
250
+ {
251
+ title: "Cluster sizing recommendations — cluster-b",
252
+ items: [{ label: "Cluster name", value: "cluster-b" }],
253
+ },
254
+ ]);
255
+
256
+ expect(blob.size).toBeGreaterThan(0);
257
+ });
258
+ });
259
+
201
260
  describe("buildHtmlReport", () => {
202
261
  it("embeds captured chart images and escapes the title", () => {
203
262
  const html = buildHtmlReport(
@@ -222,3 +281,19 @@ describe("buildHtmlReport", () => {
222
281
  expect(escapeHtml("it's")).toBe("it&#39;s");
223
282
  });
224
283
  });
284
+
285
+ describe("applyLightThemeToDocument", () => {
286
+ it("removes PatternFly dark theme classes from the given document", () => {
287
+ const clone = document.implementation.createHTMLDocument("export");
288
+ clone.documentElement.classList.add("pf-v6-theme-dark");
289
+ clone.body.style.colorScheme = "dark";
290
+
291
+ applyLightThemeToDocument(clone);
292
+
293
+ expect(clone.documentElement.classList.contains("pf-v6-theme-dark")).toBe(
294
+ false,
295
+ );
296
+ expect(clone.documentElement.style.colorScheme).toBe("light");
297
+ expect(clone.body.style.colorScheme).toBe("light");
298
+ });
299
+ });
@@ -1,12 +1,25 @@
1
+ import {
2
+ t_color_gray_20,
3
+ t_color_white,
4
+ t_global_text_color_regular,
5
+ } from "@patternfly/react-tokens";
1
6
  import html2canvas from "html2canvas-pro";
2
7
  import {
8
+ applyLightThemeToDocument,
3
9
  CHART_EXPORT_CAPTURING_ATTR,
4
10
  CHART_EXPORT_SCROLL_ATTR,
5
11
  shouldIgnoreChartExportElement,
6
12
  } from "./chartExport.js";
7
13
 
8
- /** CSS-pixel scale; 2x made zip-all of ~15 live cards too slow. */
9
- const CHART_CAPTURE_SCALE = 1;
14
+ /** Default scale for bulk exports; single-chart PNG uses a higher scale. */
15
+ const CHART_CAPTURE_SCALE_DEFAULT = 1;
16
+ export const CHART_CAPTURE_SCALE_SINGLE = 2;
17
+ const EXPORT_FONT_FAMILY = "RedHatText, Overpass, Helvetica, Arial, sans-serif";
18
+
19
+ export type CaptureChartElementOptions = {
20
+ /** Higher scale sharpens text in PNG exports; keep at 1 for bulk PDF/zip. */
21
+ scale?: number;
22
+ };
10
23
  const HIDDEN_LAYOUT_STYLE_KEYS = [
11
24
  "display",
12
25
  "position",
@@ -94,6 +107,10 @@ const PADDED_CAPTURE_SELECTOR =
94
107
  ".pf-v6-c-card__title, .pf-v6-c-card__header, .pf-v6-c-card__body";
95
108
  const CARD_CAPTURE_SELECTOR = ".pf-v6-c-card";
96
109
  const TRANSPARENT_FILLS = new Set(["", "transparent", "rgba(0, 0, 0, 0)"]);
110
+ /** PatternFly light-theme chrome. html2canvas inlines live computed SVG styles. */
111
+ const LIGHT_EXPORT_BACKGROUND = t_color_white.value;
112
+ const LIGHT_EXPORT_BORDER = t_color_gray_20.value;
113
+ const LIGHT_EXPORT_TEXT = t_global_text_color_regular.value;
97
114
 
98
115
  function queryCards(root: HTMLElement): HTMLElement[] {
99
116
  const cards = Array.from(
@@ -149,16 +166,35 @@ function readCardBorder(source: HTMLElement): {
149
166
  return { width, style, color };
150
167
  }
151
168
 
152
- function applyCardChrome(source: HTMLElement, dest: HTMLElement): void {
169
+ function applyCardChrome(
170
+ source: HTMLElement,
171
+ dest: HTMLElement,
172
+ colors: "computed" | "light",
173
+ ): void {
153
174
  const computed = window.getComputedStyle(source);
154
175
  dest.style.borderRadius = computed.borderRadius;
155
- dest.style.backgroundColor = resolvedFill(computed.backgroundColor);
156
176
  dest.style.overflow = "hidden";
177
+ dest.style.backgroundColor =
178
+ colors === "light"
179
+ ? LIGHT_EXPORT_BACKGROUND
180
+ : resolvedFill(computed.backgroundColor);
157
181
  const border = readCardBorder(source);
158
182
  if (border) {
159
183
  dest.style.borderWidth = border.width;
160
184
  dest.style.borderStyle = border.style;
161
- dest.style.borderColor = border.color;
185
+ dest.style.borderColor =
186
+ colors === "light" ? LIGHT_EXPORT_BORDER : border.color;
187
+ }
188
+ }
189
+
190
+ function applyLightThemeSvgText(root: HTMLElement): void {
191
+ for (const node of root.querySelectorAll("text, tspan")) {
192
+ if (!(node instanceof SVGElement)) {
193
+ continue;
194
+ }
195
+ node.style.fill = LIGHT_EXPORT_TEXT;
196
+ node.style.color = LIGHT_EXPORT_TEXT;
197
+ node.style.fontFamily = EXPORT_FONT_FAMILY;
162
198
  }
163
199
  }
164
200
 
@@ -218,7 +254,7 @@ function copyCardChrome(node: HTMLElement): {
218
254
  height: node.style.height,
219
255
  maxHeight: node.style.maxHeight,
220
256
  };
221
- applyCardChrome(node, node);
257
+ applyCardChrome(node, node, "computed");
222
258
  node.style.minHeight = "0px";
223
259
  node.style.height = "auto";
224
260
  node.style.maxHeight = "none";
@@ -234,7 +270,7 @@ function applyComputedStylesToClone(
234
270
  sourceCards.forEach((source, index) => {
235
271
  const dest = cloneCards[index];
236
272
  if (dest) {
237
- applyCardChrome(source, dest);
273
+ applyCardChrome(source, dest, "light");
238
274
  }
239
275
  });
240
276
 
@@ -331,7 +367,9 @@ function prepareCaptureLayout(element: HTMLElement): () => void {
331
367
 
332
368
  export async function captureChartElement(
333
369
  element: HTMLElement,
370
+ options: CaptureChartElementOptions = {},
334
371
  ): Promise<HTMLCanvasElement> {
372
+ const scale = options.scale ?? CHART_CAPTURE_SCALE_DEFAULT;
335
373
  const restoreHidden = revealHiddenChartAncestors(element);
336
374
  const restoreLayout = prepareCaptureLayout(element);
337
375
  element.setAttribute(CHART_EXPORT_CAPTURING_ATTR, "");
@@ -348,15 +386,22 @@ export async function captureChartElement(
348
386
  }
349
387
  return html2canvas(element, {
350
388
  useCORS: true,
351
- backgroundColor: null,
389
+ backgroundColor: LIGHT_EXPORT_BACKGROUND,
352
390
  logging: false,
353
- scale: CHART_CAPTURE_SCALE,
391
+ scale,
354
392
  imageTimeout: 0,
355
393
  ignoreElements: (node) =>
356
394
  node instanceof Element &&
357
395
  shouldIgnoreChartExportElement(node, element),
358
- onclone: (_clonedDoc, clonedElement) => {
396
+ onclone: (clonedDoc, clonedElement) => {
397
+ // Dropping the dark-theme class off the clone root makes every
398
+ // PatternFly CSS-variable surface (cards, tables, labels) resolve to
399
+ // light automatically — html2canvas reads computed styles from this
400
+ // clone. Only Victory's inlined SVG text needs explicit recoloring.
401
+ applyLightThemeToDocument(clonedDoc);
359
402
  applyComputedStylesToClone(element, clonedElement);
403
+ applyLightThemeSvgText(clonedElement);
404
+ clonedElement.style.fontFamily = EXPORT_FONT_FAMILY;
360
405
  },
361
406
  });
362
407
  } finally {
@@ -14,7 +14,7 @@ export const chartExportScrollProps = {
14
14
 
15
15
  export const chartExportRootStyle: CSSProperties = {
16
16
  width: "100%",
17
- height: "100%",
17
+ height: "auto",
18
18
  };
19
19
 
20
20
  export type ChartExportMeta = {
@@ -51,6 +51,24 @@ export type ChartCaptureSource = {
51
51
  capture: () => Promise<HTMLCanvasElement>;
52
52
  };
53
53
 
54
+ /** One label/value row rendered on a {@link PdfTextPage}. */
55
+ export type PdfTextPageItem = {
56
+ label: string;
57
+ value: string;
58
+ };
59
+
60
+ /**
61
+ * A native-text PDF page appended after the captured chart images.
62
+ *
63
+ * Used for content that is not a chart/card (e.g. calculated recommendations)
64
+ * but still needs to be part of the exported PDF.
65
+ */
66
+ export type PdfTextPage = {
67
+ title: string;
68
+ items: PdfTextPageItem[];
69
+ footer?: string;
70
+ };
71
+
54
72
  export function releaseCanvas(canvas: HTMLCanvasElement): void {
55
73
  canvas.width = 0;
56
74
  canvas.height = 0;
@@ -67,6 +85,28 @@ export function waitForChartExportPaint(): Promise<void> {
67
85
  });
68
86
  }
69
87
 
88
+ /** PatternFly applies dark tokens when this class is on `:root`. */
89
+ export const PATTERNFLY_DARK_THEME_CLASSES = [
90
+ "pf-v6-theme-dark",
91
+ "pf-v5-theme-dark",
92
+ ] as const;
93
+
94
+ /**
95
+ * Force PatternFly light tokens on a document (the html2canvas clone).
96
+ * Does not touch the live page.
97
+ */
98
+ export function applyLightThemeToDocument(root: Document): void {
99
+ for (const node of [root.documentElement, root.body]) {
100
+ if (!node) {
101
+ continue;
102
+ }
103
+ for (const className of PATTERNFLY_DARK_THEME_CLASSES) {
104
+ node.classList.remove(className);
105
+ }
106
+ node.style.colorScheme = "light";
107
+ }
108
+ }
109
+
70
110
  export function chartExportViewsFromLabels(
71
111
  titlePrefix: string,
72
112
  labels: Record<string, string>,
@@ -9,6 +9,7 @@ import {
9
9
  type ChartExportMeta,
10
10
  type ChartExportView,
11
11
  chartPngFilename,
12
+ type PdfTextPage,
12
13
  type RegisteredChart,
13
14
  } from "./chartExport.js";
14
15
 
@@ -17,7 +18,14 @@ export type ChartExportFormat = "pdf" | "png" | "html";
17
18
  export type ChartExportApi = {
18
19
  downloadChart: (id: string) => Promise<void>;
19
20
  downloadAll: () => Promise<void>;
20
- downloadPdf: (documentTitle: string) => Promise<void>;
21
+ /**
22
+ * @param extraPages - Native-text pages appended after the captured chart
23
+ * images (e.g. calculated recommendations that aren't rendered as charts).
24
+ */
25
+ downloadPdf: (
26
+ documentTitle: string,
27
+ extraPages?: PdfTextPage[],
28
+ ) => Promise<void>;
21
29
  downloadHtml: (documentTitle: string) => Promise<void>;
22
30
  downloadingChartId: string | null;
23
31
  exportingFormat: ChartExportFormat | null;
@@ -30,6 +30,12 @@ export const dashboardStyles = {
30
30
  height: 100%;
31
31
  `,
32
32
 
33
+ /**
34
+ * Flex child of {@link dashboardStyles.card}. `min-height: 0` lets the body
35
+ * shrink inside the card max-height; `overflow: auto` scrolls tables and tall
36
+ * charts when needed (phantom scrollbars on donut cards are avoided by the
37
+ * card layout and ChartExportSurface sizing, not a second body class).
38
+ */
33
39
  cardBodyScrollable: css`
34
40
  overflow: auto;
35
41
  `,
@@ -38,12 +44,9 @@ export const dashboardStyles = {
38
44
  // at the same specificity, which wins in the production build due to stylesheet
39
45
  // injection order. `!important` forces `hidden` regardless of that order.
40
46
  card: css`
41
- min-height: 430px;
42
- max-height: 520px;
43
- height: 100%;
47
+ height: 520px;
44
48
  display: flex;
45
49
  flex-direction: column;
46
- justify-content: space-between;
47
50
  overflow: hidden !important;
48
51
  `,
49
52