gradio-pr-bot commited on
Commit
2f31542
·
verified ·
1 Parent(s): 3699098

Upload folder using huggingface_hub

Browse files
5.49.1/nativeplot/Example.svelte ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let title: string | null;
3
+ export let x: string;
4
+ export let y: string;
5
+ </script>
6
+
7
+ {#if title}
8
+ {title}
9
+ {:else}
10
+ {x} x {y}
11
+ {/if}
5.49.1/nativeplot/Index.svelte ADDED
@@ -0,0 +1,799 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Gradio, SelectData } from "@gradio/utils";
3
+ import { BlockTitle } from "@gradio/atoms";
4
+ import { Block } from "@gradio/atoms";
5
+ import {
6
+ FullscreenButton,
7
+ IconButtonWrapper,
8
+ IconButton
9
+ } from "@gradio/atoms";
10
+ import { StatusTracker } from "@gradio/statustracker";
11
+ import type { LoadingStatus } from "@gradio/statustracker";
12
+ import { onMount } from "svelte";
13
+
14
+ import type { TopLevelSpec as Spec } from "vega-lite";
15
+ import type { View } from "vega";
16
+ import { LineChart as LabelIcon, Download } from "@gradio/icons";
17
+ import { Empty } from "@gradio/atoms";
18
+
19
+ interface PlotData {
20
+ columns: string[];
21
+ data: [string | number][];
22
+ datatypes: Record<string, "quantitative" | "temporal" | "nominal">;
23
+ mark: "line" | "point" | "bar";
24
+ }
25
+ export let value: PlotData | null;
26
+ export let x: string;
27
+ export let y: string;
28
+ export let color: string | null = null;
29
+ $: unique_colors =
30
+ color && value && value.datatypes[color] === "nominal"
31
+ ? Array.from(new Set(_data.map((d) => d[color])))
32
+ : [];
33
+
34
+ export let title: string | null = null;
35
+ export let x_title: string | null = null;
36
+ export let y_title: string | null = null;
37
+ export let color_title: string | null = null;
38
+ export let x_bin: string | number | null = null;
39
+ export let y_aggregate:
40
+ | "sum"
41
+ | "mean"
42
+ | "median"
43
+ | "min"
44
+ | "max"
45
+ | undefined = undefined;
46
+ export let color_map: Record<string, string> | null = null;
47
+ export let x_lim: [number, number] | null = null;
48
+ export let y_lim: [number | null, number | null] | null = null;
49
+ $: x_lim = x_lim || null; // for some unknown reason, x_lim was getting set to undefined when used in re-render, so this line is needed
50
+ $: y_lim = y_lim || null;
51
+ $: [x_start, x_end] = x_lim === null ? [undefined, undefined] : x_lim;
52
+ $: [y_start, y_end] = y_lim || [undefined, undefined];
53
+ export let x_label_angle: number | null = null;
54
+ export let y_label_angle: number | null = null;
55
+ export let x_axis_labels_visible = true;
56
+ export let caption: string | null = null;
57
+ export let sort: "x" | "y" | "-x" | "-y" | string[] | null = null;
58
+ export let tooltip: "axis" | "none" | "all" | string[] = "axis";
59
+ export let show_fullscreen_button = false;
60
+ export let show_export_button = false;
61
+ let fullscreen = false;
62
+
63
+ function reformat_sort(
64
+ _sort: typeof sort
65
+ ):
66
+ | string
67
+ | "ascending"
68
+ | "descending"
69
+ | { field: string; order: "ascending" | "descending" }
70
+ | string[]
71
+ | null
72
+ | undefined {
73
+ if (_sort === "x") {
74
+ return "ascending";
75
+ } else if (_sort === "-x") {
76
+ return "descending";
77
+ } else if (_sort === "y") {
78
+ return { field: y, order: "ascending" };
79
+ } else if (_sort === "-y") {
80
+ return { field: y, order: "descending" };
81
+ } else if (_sort === null) {
82
+ return null;
83
+ } else if (Array.isArray(_sort)) {
84
+ return _sort;
85
+ }
86
+ }
87
+ $: _sort = reformat_sort(sort);
88
+ export let _selectable = false;
89
+ let _data: {
90
+ [x: string]: string | number;
91
+ }[];
92
+ export let gradio: Gradio<{
93
+ select: SelectData;
94
+ double_click: undefined;
95
+ clear_status: LoadingStatus;
96
+ }>;
97
+
98
+ $: x_temporal = value && value.datatypes[x] === "temporal";
99
+ $: _x_lim = x_lim && x_temporal ? [x_lim[0] * 1000, x_lim[1] * 1000] : x_lim;
100
+ let _x_bin: number | undefined;
101
+ let mouse_down_on_chart = false;
102
+ const SUFFIX_DURATION: Record<string, number> = {
103
+ s: 1,
104
+ m: 60,
105
+ h: 60 * 60,
106
+ d: 24 * 60 * 60
107
+ };
108
+ $: _x_bin = x_bin
109
+ ? typeof x_bin === "string"
110
+ ? 1000 *
111
+ parseInt(x_bin.substring(0, x_bin.length - 1)) *
112
+ SUFFIX_DURATION[x_bin[x_bin.length - 1]]
113
+ : x_bin
114
+ : undefined;
115
+ let _y_aggregate: typeof y_aggregate;
116
+ let aggregating: boolean;
117
+ $: {
118
+ if (value) {
119
+ if (value.mark === "point") {
120
+ aggregating = _x_bin !== undefined;
121
+ _y_aggregate = y_aggregate || aggregating ? "sum" : undefined;
122
+ } else {
123
+ aggregating = _x_bin !== undefined || value.datatypes[x] === "nominal";
124
+ _y_aggregate = y_aggregate ? y_aggregate : "sum";
125
+ }
126
+ }
127
+ }
128
+
129
+ function downsample(
130
+ data: PlotData["data"],
131
+ x_index: number,
132
+ y_index: number,
133
+ color_index: number | null,
134
+ x_start: number | undefined,
135
+ x_end: number | undefined
136
+ ): PlotData["data"] {
137
+ if (
138
+ data.length < 1000 ||
139
+ x_bin !== null ||
140
+ value?.mark !== "line" ||
141
+ value?.datatypes[x] === "nominal"
142
+ ) {
143
+ return data;
144
+ }
145
+ const bin_count = 250;
146
+ let min_max_bins_per_color: Record<
147
+ string,
148
+ [number | null, number, number | null, number][]
149
+ > = {};
150
+ if (x_start === undefined || x_end === undefined) {
151
+ data.forEach((row) => {
152
+ let x_value = row[x_index] as number;
153
+ if (x_start === undefined || x_value < x_start) {
154
+ x_start = x_value;
155
+ }
156
+ if (x_end === undefined || x_value > x_end) {
157
+ x_end = x_value;
158
+ }
159
+ });
160
+ }
161
+ if (x_start === undefined || x_end === undefined) {
162
+ return data;
163
+ }
164
+ const x_range = x_end - x_start;
165
+ const bin_size = x_range / bin_count;
166
+ data.forEach((row, i) => {
167
+ const x_value = row[x_index] as number;
168
+ const y_value = row[y_index] as number;
169
+ const color_value =
170
+ color_index !== null ? (row[color_index] as string) : "any";
171
+ const bin_index = Math.floor((x_value - (x_start as number)) / bin_size);
172
+ if (min_max_bins_per_color[color_value] === undefined) {
173
+ min_max_bins_per_color[color_value] = [];
174
+ }
175
+ min_max_bins_per_color[color_value][bin_index] = min_max_bins_per_color[
176
+ color_value
177
+ ][bin_index] || [
178
+ null,
179
+ Number.POSITIVE_INFINITY,
180
+ null,
181
+ Number.NEGATIVE_INFINITY
182
+ ];
183
+ if (y_value < min_max_bins_per_color[color_value][bin_index][1]) {
184
+ min_max_bins_per_color[color_value][bin_index][0] = i;
185
+ min_max_bins_per_color[color_value][bin_index][1] = y_value;
186
+ }
187
+ if (y_value > min_max_bins_per_color[color_value][bin_index][3]) {
188
+ min_max_bins_per_color[color_value][bin_index][2] = i;
189
+ min_max_bins_per_color[color_value][bin_index][3] = y_value;
190
+ }
191
+ });
192
+ const downsampled_data: PlotData["data"] = [];
193
+ Object.values(min_max_bins_per_color).forEach((bins) => {
194
+ bins.forEach(([min_index, _, max_index, __]) => {
195
+ let indices: number[] = [];
196
+ if (min_index !== null && max_index !== null) {
197
+ indices = [
198
+ Math.min(min_index, max_index),
199
+ Math.max(min_index, max_index)
200
+ ];
201
+ } else if (min_index !== null) {
202
+ indices = [min_index];
203
+ } else if (max_index !== null) {
204
+ indices = [max_index];
205
+ }
206
+ indices.forEach((index) => {
207
+ downsampled_data.push(data[index]);
208
+ });
209
+ });
210
+ });
211
+ return downsampled_data;
212
+ }
213
+ function reformat_data(
214
+ data: PlotData,
215
+ x_start: number | undefined,
216
+ x_end: number | undefined
217
+ ): {
218
+ [x: string]: string | number;
219
+ }[] {
220
+ let x_index = data.columns.indexOf(x);
221
+ let y_index = data.columns.indexOf(y);
222
+ let color_index = color ? data.columns.indexOf(color) : null;
223
+ let datatable = data.data;
224
+
225
+ if (x_start !== undefined && x_end !== undefined) {
226
+ const time_factor = data.datatypes[x] === "temporal" ? 1000 : 1;
227
+ const _x_start = x_start * time_factor;
228
+ const _x_end = x_end * time_factor;
229
+ let largest_before_start: Record<string, [number, number]> = {};
230
+ let smallest_after_end: Record<string, [number, number]> = {};
231
+ const _datatable = datatable.filter((row, i) => {
232
+ const x_value = row[x_index] as number;
233
+ const color_value =
234
+ color_index !== null ? (row[color_index] as string) : "any";
235
+ if (
236
+ x_value < _x_start &&
237
+ (largest_before_start[color_value] === undefined ||
238
+ x_value > largest_before_start[color_value][1])
239
+ ) {
240
+ largest_before_start[color_value] = [i, x_value];
241
+ }
242
+ if (
243
+ x_value > _x_end &&
244
+ (smallest_after_end[color_value] === undefined ||
245
+ x_value < smallest_after_end[color_value][1])
246
+ ) {
247
+ smallest_after_end[color_value] = [i, x_value];
248
+ }
249
+ return x_value >= _x_start && x_value <= _x_end;
250
+ });
251
+ datatable = [
252
+ ...Object.values(largest_before_start).map(([i, _]) => datatable[i]),
253
+ ...downsample(
254
+ _datatable,
255
+ x_index,
256
+ y_index,
257
+ color_index,
258
+ _x_start,
259
+ _x_end
260
+ ),
261
+ ...Object.values(smallest_after_end).map(([i, _]) => datatable[i])
262
+ ];
263
+ } else {
264
+ datatable = downsample(
265
+ datatable,
266
+ x_index,
267
+ y_index,
268
+ color_index,
269
+ undefined,
270
+ undefined
271
+ );
272
+ }
273
+
274
+ if (tooltip == "all" || Array.isArray(tooltip)) {
275
+ return datatable.map((row) => {
276
+ const obj: { [x: string]: string | number } = {};
277
+ data.columns.forEach((col, i) => {
278
+ obj[col] = row[i];
279
+ });
280
+ return obj;
281
+ });
282
+ }
283
+ return datatable.map((row) => {
284
+ const obj = {
285
+ [x]: row[x_index],
286
+ [y]: row[y_index]
287
+ };
288
+ if (color && color_index !== null) {
289
+ obj[color] = row[color_index];
290
+ }
291
+ return obj;
292
+ });
293
+ }
294
+ $: _data = value ? reformat_data(value, x_start, x_end) : [];
295
+ let old_value = value;
296
+ $: if (old_value !== value && view) {
297
+ old_value = value;
298
+ view.data("data", _data).runAsync();
299
+ }
300
+
301
+ const is_browser = typeof window !== "undefined";
302
+ let chart_element: HTMLDivElement;
303
+ $: computed_style = chart_element
304
+ ? window.getComputedStyle(chart_element)
305
+ : null;
306
+ let view: View;
307
+ let mounted = false;
308
+ let old_width: number;
309
+ let old_height: number;
310
+ let resizeObserver: ResizeObserver;
311
+
312
+ let vegaEmbed: typeof import("vega-embed").default;
313
+ async function load_chart(): Promise<void> {
314
+ if (mouse_down_on_chart) {
315
+ refresh_pending = true;
316
+ return;
317
+ }
318
+ if (view) {
319
+ view.finalize();
320
+ }
321
+ if (!value || !chart_element) return;
322
+ old_width = chart_element.offsetWidth;
323
+ old_height = chart_element.offsetHeight;
324
+ const spec = create_vega_lite_spec();
325
+ if (!spec) return;
326
+ resizeObserver = new ResizeObserver((el) => {
327
+ if (!el[0].target || !(el[0].target instanceof HTMLElement)) return;
328
+ if (
329
+ old_width === 0 &&
330
+ chart_element.offsetWidth !== 0 &&
331
+ value.datatypes[x] === "nominal"
332
+ ) {
333
+ // a bug where when a nominal chart is first loaded, the width is 0, it doesn't resize
334
+ load_chart();
335
+ } else {
336
+ const width_change = Math.abs(old_width - el[0].target.offsetWidth);
337
+ const height_change = Math.abs(old_height - el[0].target.offsetHeight);
338
+ if (width_change > 100 || height_change > 100) {
339
+ old_width = el[0].target.offsetWidth;
340
+ old_height = el[0].target.offsetHeight;
341
+ load_chart();
342
+ } else {
343
+ view.signal("width", el[0].target.offsetWidth).run();
344
+ if (fullscreen) {
345
+ view.signal("height", el[0].target.offsetHeight).run();
346
+ }
347
+ }
348
+ }
349
+ });
350
+
351
+ if (!vegaEmbed) {
352
+ vegaEmbed = (await import("vega-embed")).default;
353
+ }
354
+ vegaEmbed(chart_element, spec, { actions: false }).then(function (result) {
355
+ view = result.view;
356
+
357
+ resizeObserver.observe(chart_element);
358
+ var debounceTimeout: NodeJS.Timeout;
359
+ var lastSelectTime = 0;
360
+ view.addEventListener("dblclick", () => {
361
+ gradio.dispatch("double_click");
362
+ });
363
+ // prevent double-clicks from highlighting text
364
+ chart_element.addEventListener(
365
+ "mousedown",
366
+ function (e) {
367
+ if (e.detail > 1) {
368
+ e.preventDefault();
369
+ }
370
+ },
371
+ false
372
+ );
373
+ if (_selectable) {
374
+ view.addSignalListener("brush", function (_, value) {
375
+ if (Date.now() - lastSelectTime < 1000) return;
376
+ mouse_down_on_chart = true;
377
+ if (Object.keys(value).length === 0) return;
378
+ clearTimeout(debounceTimeout);
379
+ let range: [number, number] = value[Object.keys(value)[0]];
380
+ if (x_temporal) {
381
+ range = [range[0] / 1000, range[1] / 1000];
382
+ }
383
+ debounceTimeout = setTimeout(function () {
384
+ mouse_down_on_chart = false;
385
+ lastSelectTime = Date.now();
386
+ gradio.dispatch("select", {
387
+ value: range,
388
+ index: range,
389
+ selected: true
390
+ });
391
+ if (refresh_pending) {
392
+ refresh_pending = false;
393
+ load_chart();
394
+ }
395
+ }, 250);
396
+ });
397
+ }
398
+ });
399
+ }
400
+
401
+ let refresh_pending = false;
402
+
403
+ onMount(() => {
404
+ mounted = true;
405
+ return () => {
406
+ mounted = false;
407
+ if (view) {
408
+ view.finalize();
409
+ }
410
+ if (resizeObserver) {
411
+ resizeObserver.disconnect();
412
+ }
413
+ };
414
+ });
415
+
416
+ function export_chart(): void {
417
+ if (!view || !computed_style) return;
418
+
419
+ const block_background = computed_style.getPropertyValue(
420
+ "--block-background-fill"
421
+ );
422
+ const export_background = block_background || "white";
423
+
424
+ view.background(export_background).run();
425
+
426
+ view
427
+ .toImageURL("png", 2)
428
+ .then(function (url) {
429
+ view.background("transparent").run();
430
+
431
+ const link = document.createElement("a");
432
+ link.setAttribute("href", url);
433
+ link.setAttribute("download", "chart.png");
434
+ link.style.display = "none";
435
+ document.body.appendChild(link);
436
+ link.click();
437
+ document.body.removeChild(link);
438
+ })
439
+ .catch(function (err) {
440
+ console.error("Export failed:", err);
441
+ view.background("transparent").run();
442
+ });
443
+ }
444
+
445
+ $: _color_map = JSON.stringify(color_map);
446
+
447
+ $: title,
448
+ x_title,
449
+ y_title,
450
+ color_title,
451
+ x,
452
+ y,
453
+ color,
454
+ x_bin,
455
+ _y_aggregate,
456
+ _color_map,
457
+ x_start,
458
+ x_end,
459
+ y_start,
460
+ y_end,
461
+ caption,
462
+ sort,
463
+ mounted,
464
+ chart_element,
465
+ fullscreen,
466
+ computed_style && requestAnimationFrame(load_chart);
467
+
468
+ function create_vega_lite_spec(): Spec | null {
469
+ if (!value || !computed_style) return null;
470
+ let accent_color = computed_style.getPropertyValue("--color-accent");
471
+ let body_text_color = computed_style.getPropertyValue("--body-text-color");
472
+ let borderColorPrimary = computed_style.getPropertyValue(
473
+ "--border-color-primary"
474
+ );
475
+ let font_family = computed_style.fontFamily;
476
+ let title_weight = computed_style.getPropertyValue(
477
+ "--block-title-text-weight"
478
+ ) as
479
+ | "bold"
480
+ | "normal"
481
+ | 100
482
+ | 200
483
+ | 300
484
+ | 400
485
+ | 500
486
+ | 600
487
+ | 700
488
+ | 800
489
+ | 900;
490
+ const font_to_px_val = (font: string): number => {
491
+ return font.endsWith("px") ? parseFloat(font.slice(0, -2)) : 12;
492
+ };
493
+ let text_size_md = font_to_px_val(
494
+ computed_style.getPropertyValue("--text-md")
495
+ );
496
+ let text_size_sm = font_to_px_val(
497
+ computed_style.getPropertyValue("--text-sm")
498
+ );
499
+
500
+ /* eslint-disable complexity */
501
+ return {
502
+ $schema: "https://vega.github.io/schema/vega-lite/v5.17.0.json",
503
+ background: "transparent",
504
+ config: {
505
+ autosize: { type: "fit", contains: "padding" },
506
+ axis: {
507
+ labelFont: font_family,
508
+ labelColor: body_text_color,
509
+ titleFont: font_family,
510
+ titleColor: body_text_color,
511
+ titlePadding: 8,
512
+ tickColor: borderColorPrimary,
513
+ labelFontSize: text_size_sm,
514
+ gridColor: borderColorPrimary,
515
+ titleFontWeight: "normal",
516
+ titleFontSize: text_size_sm,
517
+ labelFontWeight: "normal",
518
+ domain: false,
519
+ labelAngle: 0,
520
+ titleLimit: chart_element.offsetHeight * 0.8
521
+ },
522
+ legend: {
523
+ labelColor: body_text_color,
524
+ labelFont: font_family,
525
+ titleColor: body_text_color,
526
+ titleFont: font_family,
527
+ titleFontWeight: "normal",
528
+ titleFontSize: text_size_sm,
529
+ labelFontWeight: "normal",
530
+ offset: 2
531
+ },
532
+ title: {
533
+ color: body_text_color,
534
+ font: font_family,
535
+ fontSize: text_size_md,
536
+ fontWeight: title_weight,
537
+ anchor: "middle"
538
+ },
539
+ view: { stroke: borderColorPrimary },
540
+ mark: {
541
+ stroke: value.mark !== "bar" ? accent_color : undefined,
542
+ fill: value.mark === "bar" ? accent_color : undefined,
543
+ cursor: "crosshair"
544
+ }
545
+ },
546
+ data: { name: "data" },
547
+ datasets: {
548
+ data: _data
549
+ },
550
+ layer: ["plot", ...(value.mark === "line" ? ["hover"] : [])].map(
551
+ (mode) => {
552
+ return {
553
+ encoding: {
554
+ size:
555
+ value.mark === "line"
556
+ ? mode == "plot"
557
+ ? {
558
+ condition: {
559
+ empty: false,
560
+ param: "hoverPlot",
561
+ value: 3
562
+ },
563
+ value: 2
564
+ }
565
+ : {
566
+ condition: { empty: false, param: "hover", value: 100 },
567
+ value: 0
568
+ }
569
+ : undefined,
570
+ opacity:
571
+ mode === "plot"
572
+ ? undefined
573
+ : {
574
+ condition: { empty: false, param: "hover", value: 1 },
575
+ value: 0
576
+ },
577
+ x: {
578
+ axis: {
579
+ ...(x_label_angle !== null && { labelAngle: x_label_angle }),
580
+ labels: x_axis_labels_visible,
581
+ ticks: x_axis_labels_visible
582
+ },
583
+ field: x,
584
+ title: x_title || x,
585
+ type: value.datatypes[x],
586
+ scale: _x_lim ? { domain: _x_lim } : undefined,
587
+ bin: _x_bin ? { step: _x_bin } : undefined,
588
+ sort: _sort
589
+ },
590
+ y: {
591
+ axis: y_label_angle ? { labelAngle: y_label_angle } : {},
592
+ field: y,
593
+ title: y_title || y,
594
+ type: value.datatypes[y],
595
+ scale: {
596
+ zero: false,
597
+ domainMin: y_start ?? undefined,
598
+ domainMax: y_end ?? undefined
599
+ },
600
+ aggregate: aggregating ? _y_aggregate : undefined
601
+ },
602
+ color: color
603
+ ? {
604
+ field: color,
605
+ legend: { orient: "bottom", title: color_title },
606
+ scale:
607
+ value.datatypes[color] === "nominal"
608
+ ? {
609
+ domain: unique_colors,
610
+ range: color_map
611
+ ? unique_colors.map((c) => color_map[c])
612
+ : undefined
613
+ }
614
+ : {
615
+ range: [
616
+ 100, 200, 300, 400, 500, 600, 700, 800, 900
617
+ ].map((n) =>
618
+ computed_style.getPropertyValue("--primary-" + n)
619
+ ),
620
+ interpolate: "hsl"
621
+ },
622
+ type: value.datatypes[color]
623
+ }
624
+ : undefined,
625
+ tooltip:
626
+ tooltip == "none"
627
+ ? undefined
628
+ : [
629
+ {
630
+ field: y,
631
+ type: value.datatypes[y],
632
+ aggregate: aggregating ? _y_aggregate : undefined,
633
+ title: y_title || y
634
+ },
635
+ {
636
+ field: x,
637
+ type: value.datatypes[x],
638
+ title: x_title || x,
639
+ format: x_temporal ? "%Y-%m-%d %H:%M:%S" : undefined,
640
+ bin: _x_bin ? { step: _x_bin } : undefined
641
+ },
642
+ ...(color
643
+ ? [
644
+ {
645
+ field: color,
646
+ type: value.datatypes[color]
647
+ }
648
+ ]
649
+ : []),
650
+ ...(tooltip === "axis"
651
+ ? []
652
+ : value?.columns
653
+ .filter(
654
+ (col) =>
655
+ col !== x &&
656
+ col !== y &&
657
+ col !== color &&
658
+ (tooltip === "all" || tooltip.includes(col))
659
+ )
660
+ .map((column) => ({
661
+ field: column,
662
+ type: value.datatypes[column]
663
+ })))
664
+ ]
665
+ },
666
+ strokeDash: {},
667
+ mark: { clip: true, type: mode === "hover" ? "point" : value.mark },
668
+ name: mode
669
+ };
670
+ }
671
+ ),
672
+ // @ts-ignore
673
+ params: [
674
+ ...(value.mark === "line"
675
+ ? [
676
+ {
677
+ name: "hoverPlot",
678
+ select: {
679
+ clear: "mouseout",
680
+ fields: color ? [color] : [],
681
+ nearest: true,
682
+ on: "mouseover",
683
+ type: "point" as "point"
684
+ },
685
+ views: ["hover"]
686
+ },
687
+ {
688
+ name: "hover",
689
+ select: {
690
+ clear: "mouseout",
691
+ nearest: true,
692
+ on: "mouseover",
693
+ type: "point" as "point"
694
+ },
695
+ views: ["hover"]
696
+ }
697
+ ]
698
+ : []),
699
+ ...(_selectable
700
+ ? [
701
+ {
702
+ name: "brush",
703
+ select: {
704
+ encodings: ["x"],
705
+ mark: { fill: "gray", fillOpacity: 0.3, stroke: "none" },
706
+ type: "interval" as "interval"
707
+ },
708
+ views: ["plot"]
709
+ }
710
+ ]
711
+ : [])
712
+ ],
713
+ width: chart_element.offsetWidth,
714
+ height: height || fullscreen ? "container" : undefined,
715
+ title: title || undefined
716
+ };
717
+ /* eslint-enable complexity */
718
+ }
719
+
720
+ export let label = "Textbox";
721
+ export let elem_id = "";
722
+ export let elem_classes: string[] = [];
723
+ export let visible: boolean | "hidden" = true;
724
+ export let show_label: boolean;
725
+ export let scale: number | null = null;
726
+ export let min_width: number | undefined = undefined;
727
+ export let loading_status: LoadingStatus | undefined = undefined;
728
+ export let height: number | undefined = undefined;
729
+ </script>
730
+
731
+ <Block
732
+ {visible}
733
+ {elem_id}
734
+ {elem_classes}
735
+ {scale}
736
+ {min_width}
737
+ allow_overflow={false}
738
+ padding={true}
739
+ {height}
740
+ bind:fullscreen
741
+ >
742
+ {#if loading_status}
743
+ <StatusTracker
744
+ autoscroll={gradio.autoscroll}
745
+ i18n={gradio.i18n}
746
+ {...loading_status}
747
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
748
+ />
749
+ {/if}
750
+ {#if show_fullscreen_button || show_export_button}
751
+ <IconButtonWrapper>
752
+ {#if show_export_button}
753
+ <IconButton Icon={Download} label="Export" on:click={export_chart} />
754
+ {/if}
755
+ {#if show_fullscreen_button}
756
+ <FullscreenButton
757
+ {fullscreen}
758
+ on:fullscreen={({ detail }) => {
759
+ fullscreen = detail;
760
+ }}
761
+ />
762
+ {/if}
763
+ </IconButtonWrapper>
764
+ {/if}
765
+ <BlockTitle {show_label} info={undefined}>{label}</BlockTitle>
766
+
767
+ {#if value && is_browser}
768
+ <div bind:this={chart_element}></div>
769
+
770
+ {#if caption}
771
+ <p class="caption">{caption}</p>
772
+ {/if}
773
+ {:else}
774
+ <Empty unpadded_box={true}><LabelIcon /></Empty>
775
+ {/if}
776
+ </Block>
777
+
778
+ <style>
779
+ div {
780
+ width: 100%;
781
+ height: 100%;
782
+ }
783
+ :global(#vg-tooltip-element) {
784
+ font-family: var(--font) !important;
785
+ font-size: var(--text-xs) !important;
786
+ box-shadow: none !important;
787
+ background-color: var(--block-background-fill) !important;
788
+ border: 1px solid var(--border-color-primary) !important;
789
+ color: var(--body-text-color) !important;
790
+ }
791
+ :global(#vg-tooltip-element .key) {
792
+ color: var(--body-text-color-subdued) !important;
793
+ }
794
+ .caption {
795
+ padding: 0 4px;
796
+ margin: 0;
797
+ text-align: center;
798
+ }
799
+ </style>
5.49.1/nativeplot/package.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/nativeplot",
3
+ "version": "0.8.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": {
12
+ "gradio": "./Index.svelte",
13
+ "svelte": "./dist/Index.svelte",
14
+ "types": "./dist/Index.svelte.d.ts"
15
+ },
16
+ "./example": {
17
+ "gradio": "./Example.svelte",
18
+ "svelte": "./dist/Example.svelte",
19
+ "types": "./dist/Example.svelte.d.ts"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "dependencies": {
24
+ "@gradio/atoms": "workspace:^",
25
+ "@gradio/icons": "workspace:^",
26
+ "@gradio/statustracker": "workspace:^",
27
+ "@gradio/theme": "workspace:^",
28
+ "@gradio/utils": "workspace:^",
29
+ "vega": "^5.23.0",
30
+ "vega-embed": "^6.25.0",
31
+ "vega-lite": "^5.17.0"
32
+ },
33
+ "devDependencies": {
34
+ "@gradio/preview": "workspace:^"
35
+ },
36
+ "peerDependencies": {
37
+ "svelte": "^4.0.0"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/gradio-app/gradio.git",
42
+ "directory": "js/nativeplot"
43
+ }
44
+ }