@gradio/dataframe 0.6.6 → 0.6.8
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.
- package/CHANGELOG.md +20 -1
- package/Dataframe.stories.svelte +59 -81
- package/Index.svelte +44 -7
- package/package.json +4 -4
- package/shared/Table.svelte +13 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @gradio/dataframe
|
|
2
2
|
|
|
3
|
+
## 0.6.8
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- [#7564](https://github.com/gradio-app/gradio/pull/7564) [`5d1e8da`](https://github.com/gradio-app/gradio/commit/5d1e8dae5ac23f605c3b5f41dbe18751dff380a0) - batch UI updates on a per frame basis. Thanks @pngwn!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/upload@0.8.0
|
|
12
|
+
- @gradio/markdown@0.6.6
|
|
13
|
+
- @gradio/button@0.2.26
|
|
14
|
+
|
|
15
|
+
## 0.6.7
|
|
16
|
+
|
|
17
|
+
### Dependency updates
|
|
18
|
+
|
|
19
|
+
- @gradio/button@0.2.25
|
|
20
|
+
- @gradio/upload@0.7.7
|
|
21
|
+
|
|
3
22
|
## 0.6.6
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -386,4 +405,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
|
|
|
386
405
|
|
|
387
406
|
- Updated dependencies [[`667875b2`](https://github.com/gradio-app/gradio/commit/667875b2441753e74d25bd9d3c8adedd8ede11cd), [`37caa2e0`](https://github.com/gradio-app/gradio/commit/37caa2e0fe95d6cab8beb174580fb557904f137f)]:
|
|
388
407
|
- @gradio/upload@0.0.3
|
|
389
|
-
- @gradio/button@0.1.0
|
|
408
|
+
- @gradio/button@0.1.0
|
package/Dataframe.stories.svelte
CHANGED
|
@@ -24,15 +24,12 @@
|
|
|
24
24
|
<Story
|
|
25
25
|
name="Interactive dataframe"
|
|
26
26
|
args={{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
headers: ["Animal", "Votes"],
|
|
34
|
-
metadata: null
|
|
35
|
-
},
|
|
27
|
+
values: [
|
|
28
|
+
["Cat", 5],
|
|
29
|
+
["Horse", 3],
|
|
30
|
+
["Snake", 1]
|
|
31
|
+
],
|
|
32
|
+
headers: ["Animal", "Votes"],
|
|
36
33
|
label: "Animals",
|
|
37
34
|
col_count: [2, "dynamic"],
|
|
38
35
|
row_count: [3, "dynamic"]
|
|
@@ -42,15 +39,12 @@
|
|
|
42
39
|
<Story
|
|
43
40
|
name="Interactive dataframe with label"
|
|
44
41
|
args={{
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
headers: ["Animal", "Votes"],
|
|
52
|
-
metadata: null
|
|
53
|
-
},
|
|
42
|
+
values: [
|
|
43
|
+
["Cat", 5],
|
|
44
|
+
["Horse", 3],
|
|
45
|
+
["Snake", 1]
|
|
46
|
+
],
|
|
47
|
+
headers: ["Animal", "Votes"],
|
|
54
48
|
label: "Animals",
|
|
55
49
|
show_label: true,
|
|
56
50
|
col_count: [2, "dynamic"],
|
|
@@ -61,15 +55,13 @@
|
|
|
61
55
|
<Story
|
|
62
56
|
name="Interactive dataframe no label"
|
|
63
57
|
args={{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
metadata: null
|
|
72
|
-
},
|
|
58
|
+
values: [
|
|
59
|
+
["Cat", 5],
|
|
60
|
+
["Horse", 3],
|
|
61
|
+
["Snake", 1]
|
|
62
|
+
],
|
|
63
|
+
headers: ["Animal", "Votes"],
|
|
64
|
+
metadata: null,
|
|
73
65
|
label: "Animals",
|
|
74
66
|
show_label: false,
|
|
75
67
|
col_count: [2, "dynamic"],
|
|
@@ -80,15 +72,13 @@
|
|
|
80
72
|
<Story
|
|
81
73
|
name="Static dataframe"
|
|
82
74
|
args={{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
metadata: null
|
|
91
|
-
},
|
|
75
|
+
values: [
|
|
76
|
+
["Cat", 5],
|
|
77
|
+
["Horse", 3],
|
|
78
|
+
["Snake", 1]
|
|
79
|
+
],
|
|
80
|
+
headers: ["Animal", "Votes"],
|
|
81
|
+
|
|
92
82
|
label: "Animals",
|
|
93
83
|
col_count: [2, "dynamic"],
|
|
94
84
|
row_count: [3, "dynamic"],
|
|
@@ -99,19 +89,15 @@
|
|
|
99
89
|
<Story
|
|
100
90
|
name="Dataframe with different precisions"
|
|
101
91
|
args={{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
["1", "1.2", "1.21"]
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
},
|
|
92
|
+
values: [
|
|
93
|
+
[1.24, 1.24, 1.24],
|
|
94
|
+
[1.21, 1.21, 1.21]
|
|
95
|
+
],
|
|
96
|
+
headers: ["Precision=0", "Precision=1", "Precision=2"],
|
|
97
|
+
display_value: [
|
|
98
|
+
["1", "1.2", "1.24"],
|
|
99
|
+
["1", "1.2", "1.21"]
|
|
100
|
+
],
|
|
115
101
|
label: "Numbers",
|
|
116
102
|
col_count: [3, "dynamic"],
|
|
117
103
|
row_count: [2, "dynamic"],
|
|
@@ -122,15 +108,12 @@
|
|
|
122
108
|
<Story
|
|
123
109
|
name="Dataframe with markdown and math"
|
|
124
110
|
args={{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
headers: ["Type", "Example", "Roots"],
|
|
132
|
-
metadata: null
|
|
133
|
-
},
|
|
111
|
+
values: [
|
|
112
|
+
["Linear", "$y=x$", "Has a *maximum* of 1 root"],
|
|
113
|
+
["Quadratic", "$y=x^2$", "Has a *maximum* of 2 roots"],
|
|
114
|
+
["Cubic", "$y=x^3$", "Has a *maximum* of 3 roots"]
|
|
115
|
+
],
|
|
116
|
+
headers: ["Type", "Example", "Roots"],
|
|
134
117
|
datatype: ["str", "markdown", "markdown"],
|
|
135
118
|
latex_delimiters: [{ left: "$", right: "$", display: false }],
|
|
136
119
|
label: "Math",
|
|
@@ -143,23 +126,20 @@
|
|
|
143
126
|
<Story
|
|
144
127
|
name="Dataframe with different colors"
|
|
145
128
|
args={{
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
129
|
+
values: [
|
|
130
|
+
[800, 100, 800],
|
|
131
|
+
[200, 800, 700]
|
|
132
|
+
],
|
|
133
|
+
headers: ["Math", "Reading", "Writing"],
|
|
134
|
+
|
|
135
|
+
styling: [
|
|
136
|
+
[
|
|
137
|
+
"background-color:teal; color: white",
|
|
138
|
+
"1.2",
|
|
139
|
+
"background-color:teal; color: white"
|
|
150
140
|
],
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
styling: [
|
|
154
|
-
[
|
|
155
|
-
"background-color:teal; color: white",
|
|
156
|
-
"1.2",
|
|
157
|
-
"background-color:teal; color: white"
|
|
158
|
-
],
|
|
159
|
-
["1", "background-color:teal; color: white", "1.21"]
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
},
|
|
141
|
+
["1", "background-color:teal; color: white", "1.21"]
|
|
142
|
+
],
|
|
163
143
|
label: "Test scores",
|
|
164
144
|
col_count: [3, "dynamic"],
|
|
165
145
|
row_count: [2, "dynamic"],
|
|
@@ -170,13 +150,11 @@
|
|
|
170
150
|
<Story
|
|
171
151
|
name="Dataframe with column widths"
|
|
172
152
|
args={{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
headers: ["Narrow", "Wide", "Half"]
|
|
179
|
-
},
|
|
153
|
+
values: [
|
|
154
|
+
[800, 100, 800],
|
|
155
|
+
[200, 800, 700]
|
|
156
|
+
],
|
|
157
|
+
headers: ["Narrow", "Wide", "Half"],
|
|
180
158
|
label: "Test scores",
|
|
181
159
|
col_count: [3, "dynamic"],
|
|
182
160
|
row_count: [2, "dynamic"],
|
package/Index.svelte
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
</script>
|
|
5
5
|
|
|
6
6
|
<script lang="ts">
|
|
7
|
-
import { afterUpdate } from "svelte";
|
|
7
|
+
import { afterUpdate, tick } from "svelte";
|
|
8
8
|
import type { Gradio, SelectData } from "@gradio/utils";
|
|
9
9
|
import { Block } from "@gradio/atoms";
|
|
10
10
|
import Table from "./shared/Table.svelte";
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
headers: ["1", "2", "3"],
|
|
21
21
|
metadata: null
|
|
22
22
|
};
|
|
23
|
-
let old_value
|
|
23
|
+
let old_value = "";
|
|
24
24
|
export let value_is_output = false;
|
|
25
25
|
export let col_count: [number, "fixed" | "dynamic"];
|
|
26
26
|
export let row_count: [number, "fixed" | "dynamic"];
|
|
@@ -49,21 +49,44 @@
|
|
|
49
49
|
export let loading_status: LoadingStatus;
|
|
50
50
|
export let interactive: boolean;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
let _headers: Headers;
|
|
53
|
+
let display_value: string[][] | null;
|
|
54
|
+
let styling: string[][] | null;
|
|
55
|
+
let values: (string | number)[][];
|
|
56
|
+
async function handle_change(data?: {
|
|
57
|
+
data: Data;
|
|
58
|
+
headers: Headers;
|
|
59
|
+
metadata: Metadata;
|
|
60
|
+
}): Promise<void> {
|
|
61
|
+
let _data = data || value;
|
|
62
|
+
|
|
63
|
+
_headers = [...(_data.headers || headers)];
|
|
64
|
+
values = _data.data ? [..._data.data] : [];
|
|
65
|
+
display_value = _data?.metadata?.display_value
|
|
66
|
+
? [..._data?.metadata?.display_value]
|
|
67
|
+
: null;
|
|
68
|
+
styling = _data?.metadata?.styling ? [..._data?.metadata?.styling] : null;
|
|
69
|
+
await tick();
|
|
70
|
+
|
|
53
71
|
gradio.dispatch("change");
|
|
54
72
|
if (!value_is_output) {
|
|
55
73
|
gradio.dispatch("input");
|
|
56
74
|
}
|
|
57
75
|
}
|
|
76
|
+
|
|
77
|
+
handle_change();
|
|
78
|
+
|
|
58
79
|
afterUpdate(() => {
|
|
59
80
|
value_is_output = false;
|
|
60
81
|
});
|
|
82
|
+
|
|
61
83
|
$: {
|
|
62
|
-
if (JSON.stringify(value) !== old_value) {
|
|
84
|
+
if (old_value && JSON.stringify(value) !== old_value) {
|
|
63
85
|
old_value = JSON.stringify(value);
|
|
64
86
|
handle_change();
|
|
65
87
|
}
|
|
66
88
|
}
|
|
89
|
+
|
|
67
90
|
if (
|
|
68
91
|
(Array.isArray(value) && value?.[0]?.length === 0) ||
|
|
69
92
|
value.data?.[0]?.length === 0
|
|
@@ -76,6 +99,18 @@
|
|
|
76
99
|
metadata: null
|
|
77
100
|
};
|
|
78
101
|
}
|
|
102
|
+
|
|
103
|
+
async function handle_value_change(data: {
|
|
104
|
+
data: Data;
|
|
105
|
+
headers: Headers;
|
|
106
|
+
metadata: Metadata;
|
|
107
|
+
}): Promise<void> {
|
|
108
|
+
if (JSON.stringify(data) !== old_value) {
|
|
109
|
+
value = { ...data };
|
|
110
|
+
old_value = JSON.stringify(value);
|
|
111
|
+
handle_change(data);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
79
114
|
</script>
|
|
80
115
|
|
|
81
116
|
<Block
|
|
@@ -99,9 +134,11 @@
|
|
|
99
134
|
{show_label}
|
|
100
135
|
{row_count}
|
|
101
136
|
{col_count}
|
|
102
|
-
{
|
|
103
|
-
{
|
|
104
|
-
|
|
137
|
+
{values}
|
|
138
|
+
{display_value}
|
|
139
|
+
{styling}
|
|
140
|
+
headers={_headers}
|
|
141
|
+
on:change={(e) => handle_value_change(e.detail)}
|
|
105
142
|
on:select={(e) => gradio.dispatch("select", e.detail)}
|
|
106
143
|
{wrap}
|
|
107
144
|
{datatype}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/dataframe",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"katex": "^0.16.7",
|
|
19
19
|
"marked": "^12.0.0",
|
|
20
20
|
"@gradio/atoms": "^0.5.3",
|
|
21
|
-
"@gradio/
|
|
21
|
+
"@gradio/button": "^0.2.26",
|
|
22
|
+
"@gradio/markdown": "^0.6.6",
|
|
22
23
|
"@gradio/statustracker": "^0.4.8",
|
|
23
|
-
"@gradio/
|
|
24
|
-
"@gradio/upload": "^0.7.6",
|
|
24
|
+
"@gradio/upload": "^0.8.0",
|
|
25
25
|
"@gradio/utils": "^0.3.0"
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
package/shared/Table.svelte
CHANGED
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
export let label: string | null = null;
|
|
22
22
|
export let show_label = true;
|
|
23
23
|
export let headers: Headers = [];
|
|
24
|
-
let values: (string | number)[][];
|
|
25
|
-
export let value: { data: Data; headers: Headers; metadata: Metadata } | null;
|
|
24
|
+
export let values: (string | number)[][] = [];
|
|
26
25
|
export let col_count: [number, "fixed" | "dynamic"];
|
|
27
26
|
export let row_count: [number, "fixed" | "dynamic"];
|
|
28
27
|
export let latex_delimiters: {
|
|
@@ -41,21 +40,10 @@
|
|
|
41
40
|
export let column_widths: string[] = [];
|
|
42
41
|
|
|
43
42
|
let selected: false | [number, number] = false;
|
|
44
|
-
let display_value: string[][] | null =
|
|
45
|
-
let styling: string[][] | null =
|
|
43
|
+
export let display_value: string[][] | null = null;
|
|
44
|
+
export let styling: string[][] | null = null;
|
|
46
45
|
let t_rect: DOMRectReadOnly;
|
|
47
46
|
|
|
48
|
-
$: {
|
|
49
|
-
if (value) {
|
|
50
|
-
headers = value.headers;
|
|
51
|
-
values = value.data;
|
|
52
|
-
display_value = value?.metadata?.display_value ?? null;
|
|
53
|
-
styling = value?.metadata?.styling ?? null;
|
|
54
|
-
} else if (values === null) {
|
|
55
|
-
values = [];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
47
|
const dispatch = createEventDispatcher<{
|
|
60
48
|
change: {
|
|
61
49
|
data: (string | number)[][];
|
|
@@ -69,6 +57,7 @@
|
|
|
69
57
|
|
|
70
58
|
const get_data_at = (row: number, col: number): string | number =>
|
|
71
59
|
data?.[row]?.[col]?.value;
|
|
60
|
+
|
|
72
61
|
$: {
|
|
73
62
|
if (selected !== false) {
|
|
74
63
|
const [row, col] = selected;
|
|
@@ -77,6 +66,7 @@
|
|
|
77
66
|
}
|
|
78
67
|
}
|
|
79
68
|
}
|
|
69
|
+
|
|
80
70
|
let els: Record<
|
|
81
71
|
string,
|
|
82
72
|
{ cell: null | HTMLTableCellElement; input: null | HTMLInputElement }
|
|
@@ -87,6 +77,7 @@
|
|
|
87
77
|
function make_id(): string {
|
|
88
78
|
return Math.random().toString(36).substring(2, 15);
|
|
89
79
|
}
|
|
80
|
+
|
|
90
81
|
function make_headers(_head: Headers): HeadersWithIDs {
|
|
91
82
|
let _h = _head || [];
|
|
92
83
|
if (col_count[1] === "fixed" && _h.length < col_count[0]) {
|
|
@@ -105,6 +96,7 @@
|
|
|
105
96
|
return { id: _id, value: JSON.stringify(i + 1) };
|
|
106
97
|
});
|
|
107
98
|
}
|
|
99
|
+
|
|
108
100
|
return _h.map((h, i) => {
|
|
109
101
|
const _id = make_id();
|
|
110
102
|
els[_id] = { cell: null, input: null };
|
|
@@ -157,7 +149,9 @@
|
|
|
157
149
|
_headers = make_headers(headers);
|
|
158
150
|
|
|
159
151
|
old_headers = headers.slice();
|
|
152
|
+
trigger_change();
|
|
160
153
|
}
|
|
154
|
+
|
|
161
155
|
$: if (!dequal(values, old_val)) {
|
|
162
156
|
data = process_data(values as (string | number)[][]);
|
|
163
157
|
old_val = values as (string | number)[][];
|
|
@@ -167,7 +161,7 @@
|
|
|
167
161
|
|
|
168
162
|
let old_val: undefined | (string | number)[][] = undefined;
|
|
169
163
|
|
|
170
|
-
|
|
164
|
+
async function trigger_change(): Promise<void> {
|
|
171
165
|
dispatch("change", {
|
|
172
166
|
data: data.map((r) => r.map(({ value }) => value)),
|
|
173
167
|
headers: _headers.map((h) => h.value),
|
|
@@ -175,6 +169,7 @@
|
|
|
175
169
|
? null
|
|
176
170
|
: { display_value: display_value, styling: styling }
|
|
177
171
|
});
|
|
172
|
+
}
|
|
178
173
|
|
|
179
174
|
function get_sort_status(
|
|
180
175
|
name: string,
|
|
@@ -425,6 +420,8 @@
|
|
|
425
420
|
selected = [index ? index + 1 : data.length - 1, 0];
|
|
426
421
|
}
|
|
427
422
|
|
|
423
|
+
$: data && trigger_change();
|
|
424
|
+
|
|
428
425
|
async function add_col(): Promise<void> {
|
|
429
426
|
parent.focus();
|
|
430
427
|
if (col_count[1] !== "dynamic") return;
|