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
1 change: 1 addition & 0 deletions changelog.d/fixed/7426-dashboard-sparkline-bounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed dashboard sparklines failing to render large data sets that exceed the JavaScript function argument limit. (#7426) (@houko)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ describe("Sparkline", () => {

expect(container.querySelector("svg")).toBeNull();
});

it("renders data sets larger than the JavaScript argument limit", () => {
const data = Array.from({ length: 150_000 }, (_, index) => index % 100);

expect(() => render(<Sparkline data={data} />)).not.toThrow();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export function Sparkline({
}: SparklineProps) {
const uid = useId().replace(/[^a-zA-Z0-9]/g, "");
if (!data || data.length < 2) return null;
const max = Math.max(...data);
const min = Math.min(...data);
let min = data[0];
let max = data[0];
for (let i = 1; i < data.length; i += 1) {
min = Math.min(min, data[i]);
max = Math.max(max, data[i]);
}
const range = max - min || 1;
const stepX = width / (data.length - 1);
const pts = data.map((v, i) => {
Expand Down