gradio/js/dataframe/static/StaticDataframe.svelte
pngwn afac000633
significantly improve the performance of gr.Dataframe for large datasets (#5342)
* virtualise the dataframe

* add changeset

* fix non visible df

* add changeset

* tweak width calculation

* check client

* add changeset

* fix weird heights

* add changeset

* remove logs

* add changeset

* fix height measurement

* fix tests

* fix rendering for short dataframes

* cleanup

* add changeset

* fix scroll and loading

* fix scollbars and loading border

* fix scollbars and loading border

* add changeset

* fix many bugs

* fixes

* maybe this

* tweaks

* fix everything

* notebooks

* remove comments

* fix things

* fix visibility issue

* tweak

* fix demos

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-09-07 19:36:42 +01:00

101 lines
2.3 KiB
Svelte

<script lang="ts">
import { afterUpdate } from "svelte";
import type { Gradio, SelectData } from "@gradio/utils";
import { Block } from "@gradio/atoms";
import Table from "../shared";
import { StatusTracker } from "@gradio/statustracker";
import type { LoadingStatus } from "@gradio/statustracker";
type Headers = string[];
type Data = (string | number)[][];
type Datatype = "str" | "markdown" | "html" | "number" | "bool" | "date";
export let headers: Headers = [];
export let elem_id = "";
export let elem_classes: string[] = [];
export let visible = true;
export let value: { data: Data; headers: Headers } = {
data: [["", "", ""]],
headers: ["1", "2", "3"]
};
let old_value: string = JSON.stringify(value);
export let value_is_output = false;
export let col_count: [number, "fixed" | "dynamic"];
export let row_count: [number, "fixed" | "dynamic"];
export let label: string | null = null;
export let wrap: boolean;
export let datatype: Datatype | Datatype[];
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let gradio: Gradio<{
change: never;
select: SelectData;
input: never;
}>;
export let latex_delimiters: {
left: string;
right: string;
display: boolean;
}[];
export let height: number | undefined = undefined;
export let loading_status: LoadingStatus;
function handle_change(): void {
gradio.dispatch("change");
if (!value_is_output) {
gradio.dispatch("input");
}
}
afterUpdate(() => {
value_is_output = false;
});
$: {
if (JSON.stringify(value) !== old_value) {
old_value = JSON.stringify(value);
handle_change();
}
}
if (
(Array.isArray(value) && value?.[0]?.length === 0) ||
value.data?.[0]?.length === 0
) {
value = {
data: [Array(col_count?.[0] || 3).fill("")],
headers: Array(col_count?.[0] || 3)
.fill("")
.map((_, i) => `${i + 1}`)
};
}
</script>
<Block
{visible}
padding={false}
{elem_id}
{elem_classes}
container={false}
{scale}
{min_width}
allow_overflow={false}
>
<StatusTracker {...loading_status} border={true} />
<Table
{label}
{row_count}
{col_count}
values={value}
{headers}
on:change={({ detail }) => {
value = detail;
}}
on:select={(e) => gradio.dispatch("select", e.detail)}
{wrap}
{datatype}
{latex_delimiters}
editable={false}
{height}
/>
</Block>