Skip to content

Commit 0adb3b2

Browse files
upgrade to vega lite 6, react-vega 8 (#5641)
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> Points of contact: - data explorer - column header charts - column preview in right panel - column preview in left panel - tracing panel - altair charts - mo.ui.altair_chart - chart builder Altair hasn't been released with the new version, although charts are supported, they raise a warning: `vega-component.tsx:81 The input spec uses Vega-Lite v5.20.1, but the current version of Vega-Lite is v6.4.1.` ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> ## 📋 Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [x] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [ ] I have added tests for the changes made. - [x] I have run the code and verified that it works as expected. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1e3f783 commit 0adb3b2

File tree

36 files changed

+927
-771
lines changed

36 files changed

+927
-771
lines changed

frontend/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"react-plotly.js": "^2.6.0",
153153
"react-resizable-panels": "2.1.9",
154154
"react-use-event-hook": "^0.9.6",
155-
"react-vega": "^7.7.1",
155+
"react-vega": "^8.0.0",
156156
"react-virtuoso": "^4.14.0",
157157
"reactflow": "^11.11.4",
158158
"remark-gfm": "^4.0.1",
@@ -168,8 +168,8 @@
168168
"typescript-memoize": "^1.1.1",
169169
"use-acp": "0.2.5",
170170
"use-resize-observer": "^9.1.0",
171-
"vega-lite": "^5.23.0",
172-
"vega-loader": "^4.5.3",
171+
"vega-lite": "^6.4.1",
172+
"vega-loader": "^5.1.0",
173173
"vega-tooltip": "^1.1.0",
174174
"vscode-jsonrpc": "^8.2.1",
175175
"vscode-languageserver-protocol": "^3.17.5",
@@ -249,6 +249,7 @@
249249
"stylelint": "^16.23.1",
250250
"stylelint-config-standard": "^36.0.1",
251251
"tailwindcss": "^4.1.15",
252+
"vega-typings": "^2.1.0",
252253
"vite": "npm:rolldown-vite@^7.1.19",
253254
"vite-plugin-top-level-await": "^1.6.0",
254255
"vite-plugin-wasm": "^3.5.0",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Copyright 2024 Marimo. All rights reserved. */
2+
3+
import React from "react";
4+
5+
export const LazyVegaEmbed = React.lazy(() =>
6+
import("react-vega").then((m) => ({ default: m.VegaEmbed })),
7+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Copyright 2024 Marimo. All rights reserved. */
2+
3+
import type { SignalListenerHandler } from "vega-typings";
4+
5+
export interface SignalListener {
6+
signalName: string;
7+
handler: SignalListenerHandler;
8+
}

frontend/src/components/data-table/charts/__tests__/__snapshots__/spec-snapshot.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`create vega spec > should create and augment a spec 1`] = `
44
{
5-
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
5+
"$schema": "https://vega.github.io/schema/vega-lite/v6.json",
66
"background": "white",
77
"config": {
88
"axis": {

frontend/src/components/data-table/charts/__tests__/spec-snapshot.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
22

3-
import type { TopLevelSpec } from "vega-lite/build/src/spec";
3+
import type { TopLevelSpec } from "vega-lite";
44
import { describe, expect, it } from "vitest";
55
import {
66
augmentSpecWithData,

frontend/src/components/data-table/charts/__tests__/spec.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
22

3-
import type { PositionDef } from "vega-lite/build/src/channeldef";
3+
import type { PositionDef } from "vega-lite/types_unstable/channeldef.js";
44
import { describe, expect, it } from "vitest";
55
import { invariant } from "@/utils/invariant";
66
import {
@@ -14,6 +14,7 @@ import { COUNT_FIELD, EMPTY_VALUE } from "../constants";
1414
import type { ChartSchemaType } from "../schemas";
1515
import {
1616
AGGREGATION_FNS,
17+
BIN_AGGREGATION,
1718
ChartType,
1819
NONE_VALUE,
1920
STRING_AGGREGATION_FNS,
@@ -169,7 +170,11 @@ describe("getAxisEncoding", () => {
169170
const expectedAggregate = (result as { aggregate?: string }).aggregate;
170171

171172
// For aggregations that are not valid for string data types, we should return undefined
172-
if (agg === NONE_VALUE || !STRING_AGGREGATION_FNS.includes(agg)) {
173+
if (
174+
agg === NONE_VALUE ||
175+
agg === BIN_AGGREGATION ||
176+
!STRING_AGGREGATION_FNS.includes(agg)
177+
) {
173178
expect(expectedAggregate).toBeUndefined();
174179
} else if (STRING_AGGREGATION_FNS.includes(agg)) {
175180
expect(expectedAggregate).toEqual(agg);
@@ -262,13 +267,13 @@ describe("getTooltips", () => {
262267
xAxis: { label: "X Axis" },
263268
};
264269

265-
const xEncoding = {
270+
const xEncoding: PositionDef<string> = {
266271
field: "x",
267272
type: "nominal",
268273
timeUnit: "year",
269274
aggregate: "sum",
270275
bin: { step: 10 },
271-
} as PositionDef<string>;
276+
};
272277

273278
const result = getTooltips({
274279
formValues,
@@ -345,7 +350,7 @@ describe("getTooltips", () => {
345350
});
346351

347352
it("should enhance tooltips with encoding parameters when field name matches encoding field", () => {
348-
const formValues = {
353+
const formValues: ChartSchemaType = {
349354
general: {
350355
xColumn: { type: "string" as const, aggregate: NONE_VALUE },
351356
yColumn: { type: "number" as const, aggregate: NONE_VALUE },
@@ -410,7 +415,7 @@ describe("getTooltips", () => {
410415
});
411416

412417
it("should handle count aggregate with no field set", () => {
413-
const formValues = {
418+
const formValues: ChartSchemaType = {
414419
general: {
415420
xColumn: {
416421
field: "category",

frontend/src/components/data-table/charts/chart-spec/encodings.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
22

3-
import type { Aggregate } from "vega-lite/build/src/aggregate";
4-
import type { BinParams } from "vega-lite/build/src/bin";
5-
import type { ColorDef, OffsetDef } from "vega-lite/build/src/channeldef";
6-
import type { Scale } from "vega-lite/build/src/scale";
3+
import type { Aggregate } from "vega-lite/types_unstable/aggregate.js";
4+
import type { BinParams } from "vega-lite/types_unstable/bin.js";
5+
import type {
6+
ColorDef,
7+
OffsetDef,
8+
} from "vega-lite/types_unstable/channeldef.js";
9+
import type { Scale } from "vega-lite/types_unstable/scale.js";
10+
import type { ColorScheme } from "vega-typings";
711
import type { z } from "zod";
812
import { COUNT_FIELD, DEFAULT_COLOR_SCHEME } from "../constants";
913
import type { AxisSchema, BinSchema, ChartSchemaType } from "../schemas";
1014
import {
1115
type AggregationFn,
1216
BIN_AGGREGATION,
1317
ChartType,
14-
type ColorScheme,
1518
NONE_VALUE,
1619
type SelectableDataType,
1720
STRING_AGGREGATION_FNS,

frontend/src/components/data-table/charts/chart-spec/spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import type {
66
Field,
77
PolarDef,
88
PositionDef,
9-
} from "vega-lite/build/src/channeldef";
10-
import type { Encoding } from "vega-lite/build/src/encoding";
11-
import type { Resolve } from "vega-lite/build/src/resolve";
12-
import type { FacetFieldDef } from "vega-lite/build/src/spec/facet";
9+
} from "vega-lite/types_unstable/channeldef.js";
10+
import type { Encoding } from "vega-lite/types_unstable/encoding.js";
11+
import type { Resolve } from "vega-lite/types_unstable/resolve.js";
12+
import type { FacetFieldDef } from "vega-lite/types_unstable/spec/facet.js";
1313
import type { z } from "zod";
1414
import type { ResolvedTheme } from "@/theme/useTheme";
1515
import type { TypedString } from "@/utils/typed";
@@ -285,7 +285,7 @@ function getBaseSpec(
285285
}
286286

287287
return {
288-
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
288+
$schema: "https://vega.github.io/schema/vega-lite/v6.json",
289289
background: theme === "dark" ? "dark" : "white",
290290
title: title,
291291
data: { values: [] },

frontend/src/components/data-table/charts/chart-spec/tooltips.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
ColorDef,
55
PositionDef,
66
StringFieldDef,
7-
} from "vega-lite/build/src/channeldef";
7+
} from "vega-lite/types_unstable/channeldef.js";
88
import type { DataType } from "@/core/kernel/messages";
99
import type { ChartSchemaType } from "../schemas";
1010
import { isFieldSet } from "./spec";

frontend/src/components/data-table/charts/chart-spec/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
22

3-
import type { StandardType } from "vega-lite/build/src/type";
3+
import type { StandardType } from "vega-lite/types_unstable/type.js";
44
import type { DataType } from "@/core/kernel/messages";
55
import type { Mark } from "@/plugins/impl/vega/types";
66
import { logNever } from "@/utils/assertNever";

0 commit comments

Comments
 (0)