Skip to content

Commit 1b611f8

Browse files
Fixes grouped accordion borders and empty plot legends (#13523)
* fix grouped accordion borders and empty plot legends * add changeset * fix grouped accordion border thickness * add changeset * remove grouped accordion follow-up tests * fully hide empty native plot legends * fix native plot data row type --------- Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 9362fd9 commit 1b611f8

7 files changed

Lines changed: 138 additions & 14 deletions

File tree

‎.changeset/twelve-bobcats-dig.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@gradio/accordion": patch
3+
"@gradio/group": patch
4+
"@gradio/nativeplot": patch
5+
"gradio": patch
6+
---
7+
8+
fix:Fixes grouped accordion borders and empty plot legends

‎js/accordion/Index.svelte‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
const gradio = new AccordionGradio(props);
2828
2929
let label = $derived(gradio.shared.label || "");
30+
let elem_classes = $derived([
31+
...(gradio.shared.elem_classes || []),
32+
"gr-accordion"
33+
]);
3034
3135
let visibility: boolean | "hidden" = $derived(
3236
gradio.shared.visible === true ? true : "hidden"
3337
);
3438
</script>
3539

36-
<Block
37-
elem_id={gradio.shared.elem_id}
38-
elem_classes={gradio.shared.elem_classes}
39-
visible={visibility}
40-
>
40+
<Block elem_id={gradio.shared.elem_id} {elem_classes} visible={visibility}>
4141
{#if gradio.shared.loading_status}
4242
<StatusTracker
4343
autoscroll={gradio.shared.autoscroll}

‎js/group/Group.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ describe("Group", () => {
5656
expect(el).not.toBeNull();
5757
expect(el).toBeVisible();
5858
});
59+
60+
test("uses border-color-primary for grouped child separators", async () => {
61+
const { container } = await render(Group, {});
62+
const group = container.querySelector(".gr-group") as HTMLElement;
63+
const styler = container.querySelector(".styler") as HTMLElement;
64+
65+
group.style.setProperty("--block-border-color", "rgb(255, 0, 0)");
66+
group.style.setProperty("--border-color-primary", "rgb(0, 128, 0)");
67+
68+
expect(getComputedStyle(styler).backgroundColor).toBe("rgb(0, 128, 0)");
69+
});
5970
});
6071

6172
describe("Children / slot", () => {

‎js/group/Index.svelte‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<style>
3434
div {
3535
border: var(--block-border-width) solid var(--border-color-primary);
36-
background: var(--block-border-color);
36+
background: var(--border-color-primary);
3737
border-radius: var(--block-radius);
3838
display: flex;
3939
flex-direction: column;
@@ -44,6 +44,9 @@
4444
border: none;
4545
border-radius: 0;
4646
}
47+
div > :global(.gr-accordion:not(.absolute)) {
48+
border: none !important;
49+
}
4750
.hide {
4851
display: none;
4952
}

‎js/nativeplot/Index.svelte‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,16 @@
656656
color: gradio.props.color
657657
? {
658658
field: escape_field_name(gradio.props.color),
659-
legend: {
660-
orient: "bottom",
661-
title: gradio.props.color_title,
662-
values: gradio.props.colors_in_legend?.length
663-
? [...gradio.props.colors_in_legend]
664-
: undefined
665-
},
659+
legend:
660+
gradio.props.colors_in_legend?.length === 0
661+
? null
662+
: {
663+
orient: "bottom",
664+
title: gradio.props.color_title,
665+
values: gradio.props.colors_in_legend
666+
? [...gradio.props.colors_in_legend]
667+
: undefined
668+
},
666669
scale:
667670
gradio.props.value!.datatypes[gradio.props.color] ===
668671
"nominal"

‎js/nativeplot/NativePlot.test.ts‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { test, describe, afterEach, expect } from "vitest";
2+
import { cleanup, render, waitFor } from "@self/tootils/render";
3+
import { run_shared_prop_tests } from "@self/tootils/shared-prop-tests";
4+
5+
import NativePlot from "./Index.svelte";
6+
import type { NativePlotProps } from "./types";
7+
8+
const plot_value = {
9+
columns: ["x", "y", "series"],
10+
data: [
11+
[1, 4, "alpha"],
12+
[2, 5, "alpha"],
13+
[1, 7, "beta"],
14+
[2, 8, "beta"]
15+
],
16+
datatypes: {
17+
x: "quantitative",
18+
y: "quantitative",
19+
series: "nominal"
20+
},
21+
mark: "line"
22+
} satisfies NativePlotProps["value"];
23+
24+
const default_props = {
25+
value: plot_value,
26+
x: "x",
27+
y: "y",
28+
color: null,
29+
title: null,
30+
x_title: null,
31+
y_title: null,
32+
color_title: null,
33+
x_bin: null,
34+
y_aggregate: undefined,
35+
color_map: null,
36+
colors_in_legend: null,
37+
x_lim: null,
38+
y_lim: null,
39+
x_label_angle: 0,
40+
y_label_angle: 0,
41+
x_axis_format: null,
42+
y_axis_format: null,
43+
x_axis_labels_visible: true,
44+
caption: null,
45+
sort: null,
46+
tooltip: "axis" as const,
47+
buttons: null,
48+
_selectable: false,
49+
label: "Native Plot",
50+
show_label: false,
51+
scale: null,
52+
min_width: 160,
53+
loading_status: undefined,
54+
height: 260
55+
};
56+
57+
run_shared_prop_tests({
58+
component: NativePlot,
59+
name: "NativePlot",
60+
base_props: { ...default_props, value: null },
61+
has_label: false
62+
});
63+
64+
async function waitForChart(container: HTMLElement): Promise<void> {
65+
await waitFor(() => {
66+
expect(container.querySelector("svg")).toBeInTheDocument();
67+
});
68+
}
69+
70+
describe("Props: colors_in_legend", () => {
71+
afterEach(() => cleanup());
72+
73+
test("colors_in_legend: [] hides all color legend entries", async () => {
74+
const { container } = await render(NativePlot, {
75+
...default_props,
76+
color: "series",
77+
colors_in_legend: []
78+
});
79+
80+
await waitForChart(container);
81+
82+
expect(container).not.toHaveTextContent("alpha");
83+
expect(container).not.toHaveTextContent("beta");
84+
expect(container).not.toHaveTextContent("series");
85+
});
86+
87+
test("colors_in_legend limits visible color legend entries", async () => {
88+
const { container } = await render(NativePlot, {
89+
...default_props,
90+
color: "series",
91+
colors_in_legend: ["alpha"]
92+
});
93+
94+
await waitForChart(container);
95+
96+
expect(container).toHaveTextContent("alpha");
97+
expect(container).not.toHaveTextContent("beta");
98+
});
99+
});

‎js/nativeplot/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LoadingStatus } from "@gradio/statustracker";
33

44
export interface PlotData {
55
columns: string[];
6-
data: [string | number][];
6+
data: (string | number)[][];
77
datatypes: Record<string, "quantitative" | "temporal" | "nominal">;
88
mark: "line" | "point" | "bar";
99
}

0 commit comments

Comments
 (0)