A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: dependency graph (#315)
Myles Scolnickef02a7f24d18
diff --git a/frontend/e2e-tests/layout-grid.spec.ts b/frontend/e2e-tests/layout-grid.spec.tsindex 1e68f12ac3..325dc7820d 100644--- a/frontend/e2e-tests/layout-grid.spec.ts+++ b/frontend/e2e-tests/layout-grid.spec.ts@@ -14,7 +14,7 @@ test("can run Grid layout", async ({ page }) => {await expect(page.getByText("Grid Layout")).toBeVisible();// Type in search box- await page.getByRole("textbox").fill("hello");+ await page.getByRole("textbox").last().fill("hello");// Verify dependent output updatedawait expect(page.getByText("Searching hello")).toBeVisible();@@ -46,7 +46,7 @@ test("can edit Grid layout", async ({ page }) => {await expect(bb1.x).toBeGreaterThan(bb2.x);// Can still use interactive elements- await page.getByRole("textbox").fill("hello");+ await page.getByRole("textbox").last().fill("hello");await expect(page.getByText("Searching hello")).toBeVisible();// Can toggle to Vertical layoutdiff --git a/frontend/package.json b/frontend/package.jsonindex 197e224c13..de4b3c9bb8 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -90,6 +90,7 @@"react-resizable-panels": "^0.0.55","react-use-event-hook": "^0.9.6","react-vega": "^7.6.0",+ "reactflow": "^11.9.4","tailwind-merge": "^1.14.0","tailwindcss-animate": "^1.0.7","timestring": "^7.0.0",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 5bceb43c38..754d5e6f86 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -239,6 +239,9 @@ dependencies:react-vega:specifier: ^7.6.0+ reactflow:+ specifier: ^11.9.4tailwind-merge:specifier: ^1.14.0version: 1.14.0@@ -4501,6 +4504,114 @@ packages:react: 18.2.0dev: false+ resolution: {integrity: sha512-bgwvqWxF09chwmdkyClpYEMaewBspdwjgLbbFlLf4SpWPFMYyuvCBQrcISsvy/EDEWO9i3Uj9ktgGAhvtSQsmA==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ classcat: 5.0.4+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ zustand: 4.4.3(@types/[email protected])([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false++ resolution: {integrity: sha512-x6e5p9iHjC6gd+4SoZ3DOOp0F1MefGKQ8hT6yPVdqxfo1+rV2WhrWvrX/MCoEu12Dp7457LdLfa0giy3aho8tQ==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ classcat: 5.0.4+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ zustand: 4.4.3(@types/[email protected])([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false++ resolution: {integrity: sha512-Ko7nKPOYalwDTTbRHi2+QXDiidSAcpUzGN3G+0B+QysLZkcaPCkpkMjjHiDC4c/Z1BJBzs1FRJg/T6BXaBnYkg==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ '@types/d3': 7.4.3+ '@types/d3-drag': 3.0.7+ '@types/d3-selection': 3.0.10+ '@types/d3-zoom': 3.0.8+ classcat: 5.0.4+ d3-drag: 3.0.0+ d3-selection: 3.0.0+ d3-zoom: 3.0.0+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ zustand: 4.4.3(@types/[email protected])([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false++ resolution: {integrity: sha512-Jo1R+uDey9IV7O2s3m0gK2+cZpg9M8hq2EZJb3NGfOSzMAPhj3mby0fNJIgTzycreuht0TpA51c2YfjGI3YIOw==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ '@types/d3-selection': 3.0.10+ '@types/d3-zoom': 3.0.8+ classcat: 5.0.4+ d3-selection: 3.0.0+ d3-zoom: 3.0.0+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ zustand: 4.4.3(@types/[email protected])([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false++ resolution: {integrity: sha512-+p271/hAsM5M1+RQTWW/02pbNkCHeGXwxGimIlL1tMIagyuko0NX2vOz2B8jxJnPKlF09Wj18BcXBNUm3nDcSg==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ classcat: 5.0.4+ d3-drag: 3.0.0+ d3-selection: 3.0.0+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ zustand: 4.4.3(@types/[email protected])([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false++ resolution: {integrity: sha512-TfcmpXHRBb2mUfzKGjburiU6FWqRME9pPFs1OwIC1z5e9BjupQhNDEKEk8XHi7PKL/mAiDfwuGXaM1BVVFuPqw==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ classcat: 5.0.4+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ zustand: 4.4.3(@types/[email protected])([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false+/@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected]):resolution: {integrity: sha512-wwhqhvL76FdRTdwfUWpKCbv0hkp2fvivfMosDVlL/popqOiNLtUhL02ThgHZH8mus/NkVr5Mj582lyFZqQrjOA==}peerDependencies:@@ -6082,6 +6193,185 @@ packages:'@types/node': 20.8.10dev: true+ /@types/[email protected]:+ resolution: {integrity: sha512-Y2Jn2idRrLzUfAKV2LyRImR+y4oa2AntrgID95SHJxuMUrkNXmanDSed71sRNZysveJVt1hLLemQZIady0FpEg==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-pYeijfZuBd87T0hGn0FO1vQ/cgLk6E1ALJjfkC0oJ8cbwkZl3TpgS8bVBLZN+2jjGgg38epgxb2zmoGtSfvgMw==}+ dependencies:+ '@types/d3-selection': 3.0.10+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-nH60IZNNxEcrh6L1ZSMNA28rj27ut/2ZmI3r96Zd+1jrZD++zD3LsMIjWlvg4AYrHn/Pqz4CF3veCxGjtbqt7A==}+ dependencies:+ '@types/d3-selection': 3.0.10+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-LFYWWd8nwfwEmTZG9PfQxd17HbNPksHBiJHaKuY1XeqscXacsS2tyoo6OdRsjf+NQYeB6XrNL3a25E3gH69lcg==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-BjzLgXGnCWjUSYGfH1cpdo41/hgdWETu4YxpezoztawmqsvCeep+8QGfiY6YbDvfgHz/DkjeIkkZVJavB4a3rg==}+ dependencies:+ '@types/d3-array': 3.2.1+ '@types/geojson': 7946.0.4+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-ZMaSKu4THYCU6sV64Lhg6qjf1orxBthaC161plr5KuPHo3CNm8DTHiLw/5Eq2b6TsNP0W0iJrUOFscY6Q450Hw==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-4fvZhzMeeuBJYZXRXrRIQnvUYfyXwYmLsdiN7XXmVNQKKw1cM8a5WdID0g1hVFZDqT9ZqZEY5pD44p24VS7iZQ==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-HE3jVKlzU9AaMazNufooRJ5ZpWmLIoc90A37WU2JMmeq28w1FQqCZswHZ3xR+SuxYftzHq6WU6KJHvqxKzTxxQ==}+ dependencies:+ '@types/d3-selection': 3.0.10+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-n6QBF9/+XASqcKK6waudgL0pf/S5XHPPI8APyMLLUHd8NqouBGLsU8MgtO7NINGtPBtk9Kko/W4ea0oAspwh9g==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-fTAfNmxSb9SOWNB9IoG5c8Hg6R+AzUHDRlsXsDZsNp6sxAEOP0tkP3gKkNSO/qmHPoBFTxNrjDprVHDQDvo5aA==}+ dependencies:+ '@types/d3-dsv': 3.0.7+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-IKtvyFdb4Q0LWna6ymywQsEYjK/94SGhPrMfEr1TIc5OBeziTi+1jcCvttts8e0UWZIxpasjnQk9MNk/3iS+kA==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-fALi2aI6shfg7vM5KiR1wNJnZ7r6UuggVqtDA+xiEdPZQwy/trcQaHnwShLuLdta2rTymCNpxYTiMZX/e09F4g==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-eDivwKKB4ELHw93QNxigleCxZczcyrFgtKyHK5HoCQoeUD0i5feT8i5tH6RxXvt5hPPhpruvKWDSwvfsW448zQ==}+ dependencies:+ '@types/geojson': 7946.0.4+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-qlmD/8aMk5xGorUvTUWHCiumvgaUXYldYjNVOWtYoTYY/L+WwIEAmJxUmTgr9LoGNG0PPAOmqMDJVDPc7DOpPw==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==}+ dependencies:+ '@types/d3-color': 3.1.3+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-WAIEVlOCdd/NKRYTsqCpOMHQHemKBEINf8YXMYOtXH0GA7SY0dqMB78P3Uhgfy+4X+/Mlw2wDtlETkN6kQUCMA==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-ZuWOtMaHCkN9xoeEMr1ubW2nGWsp4nIql+OPQRstu4ypeZ+zk3YKqQT0CXVe/PYqrKpZAi+J9mTs05TKwjXSRA==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-Cb1f3jyNBnvMMkf4KBZ7IgAQVWd9yzBwYcrxGqg3aPCUgWELAS+nyeB7r76aqu1e3+CGDjhk4BrWaFBekMwigg==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-Imagg1vJ3y76Y2ea0871wpabqp613+8/r0mCLEBfdtqC7xMSfj9idOnmBYyMoULfHePJyxMAw3nWhJxzc+LFwQ==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-kpKNZMDT3OAX6b5ct5nS/mv6LULagnUy4DmS6yyNjclje1qVe7vbjPwY3q1TGz6+Wr2IUkgFatCzqYUl54fHag==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-gkK1VVTr5iNiYJ7vWDI+yUFFlszhNMtVeneJ6lUTKPjprsvLLI9/tgEGiXJOnlINJA8FyA88gfnQsHbybVZrYQ==}+ dependencies:+ '@types/d3-time': 3.0.3+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-cuHoUgS/V3hLdjJOLTT691+G2QoqAjCVLmr4kJXR4ha56w1Zdu8UUQ5TxLRqudgNjwXeQxKMq4j+lyf9sWuslg==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-dfEWpZJ1Pdg8meLlICX1M3WBIpxnaH2eQV2eY43Y5ysRJOTAV9f3/R++lgJKFstfrEOE2zdJ0sv5qwr2Bkic6Q==}+ dependencies:+ '@types/d3-path': 3.0.2+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-5xg9rC+wWL8kdDj153qZcsJ0FWiFt0J5RB6LYUNZjwSnesfblqrI/bJ1wBdJ8OQfncgbJG5+2F+qfqnqyzYxyg==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-2p6olUZ4w3s+07q3Tm2dbiMZy5pCDfYwtLXXHUnVzXgQlZ/OyPtUz6OL382BkOuGlLXqfT+wqv8Fw2v8/0geBw==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==}+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-ew63aJfQ/ms7QQ4X7pk5NxQ9fZH/z+i24ZfJ6tJSfqxJMrYLiK01EAs2/Rtw/JreGUsS3pLPNV644qXFGnoZNQ==}+ dependencies:+ '@types/d3-selection': 3.0.10+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-iqMC4/YlFCSlO8+2Ii1GGGliCAY4XdeG748w5vQUbevlbDu0zSjH/+jojorQVBK/se0j6DUFNPBGSqD3YWYnDw==}+ dependencies:+ '@types/d3-interpolate': 3.0.4+ '@types/d3-selection': 3.0.10+ dev: false++ /@types/[email protected]:+ resolution: {integrity: sha512-lZXZ9ckh5R8uiFVt8ogUNf+pIrK4EsWrx2Np75WvF/eTpJ0FMHNhjXk8CKEx/+gpHbNQyJWehbFaTvqmHWB3ww==}+ dependencies:+ '@types/d3-array': 3.2.1+ '@types/d3-axis': 3.0.6+ '@types/d3-brush': 3.0.6+ '@types/d3-chord': 3.0.6+ '@types/d3-color': 3.1.3+ '@types/d3-contour': 3.0.6+ '@types/d3-delaunay': 6.0.4+ '@types/d3-dispatch': 3.0.6+ '@types/d3-drag': 3.0.7+ '@types/d3-dsv': 3.0.7+ '@types/d3-ease': 3.0.2+ '@types/d3-fetch': 3.0.7+ '@types/d3-force': 3.0.9+ '@types/d3-format': 3.0.4+ '@types/d3-geo': 3.0.8+ '@types/d3-hierarchy': 3.1.6+ '@types/d3-interpolate': 3.0.4+ '@types/d3-path': 3.0.2+ '@types/d3-polygon': 3.0.2+ '@types/d3-quadtree': 3.0.5+ '@types/d3-random': 3.0.3+ '@types/d3-scale': 4.0.8+ '@types/d3-scale-chromatic': 3.0.2+ '@types/d3-selection': 3.0.10+ '@types/d3-shape': 3.1.5+ '@types/d3-time': 3.0.3+ '@types/d3-time-format': 4.0.3+ '@types/d3-timer': 3.0.2+ '@types/d3-transition': 3.0.8+ '@types/d3-zoom': 3.0.8+ dev: false+/@types/[email protected]:resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==}dependencies:@@ -7671,6 +7961,10 @@ packages:clsx: 2.0.0dev: false+ resolution: {integrity: sha512-sbpkOw6z413p+HDGcBENe498WM9woqWHiJxCq7nvmxe9WmrUmqfAcxpIwAiMtM5Q3AhYkzXcNQHqsWq0mND51g==}+ dev: false+resolution: {integrity: sha512-GfisEZEJvzKrmGWkvfhgzcz/BllN1USeqD2V6tg14OAOgaCD2Z/PUEuxnAZ/nPvmaHRG7a8y77p1T/IRQ4D1Hw==}engines: {node: '>=4'}@@ -8279,6 +8573,14 @@ packages:engines: {node: '>=12'}dev: false+ resolution: {integrity: sha512-pWbUJLdETVA8lQNJecMxoXfH6x+mO2UQo8rSmZ+QqxcbyA3hfeprFgIT//HW2nlHChWeIIMwS2Fq+gEARkhTkg==}+ engines: {node: '>=12'}+ dependencies:+ d3-dispatch: 3.0.1+ d3-selection: 3.0.0+ dev: false+resolution: {integrity: sha512-UG6OvdI5afDIFP9w4G0mNq50dSOsXHJaRE8arAS5o9ApWnIElp8GZw1Dun8vP8OyHOZ/QJUKUJwxiiCCnUwm+Q==}engines: {node: '>=12'}@@ -8289,6 +8591,11 @@ packages:rw: 1.3.3dev: false+ resolution: {integrity: sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==}+ engines: {node: '>=12'}+ dev: false+resolution: {integrity: sha512-HHvehyaiUlVo5CxBJ0yF/xny4xoaxFxDnBXNvNcfW9adORGZfyNF1dj6DGLKyk4Yh3brP/1h3rnDzdIAwL08zg==}dependencies:@@ -8394,6 +8701,11 @@ packages:d3-time-format: 4.1.0dev: false+ resolution: {integrity: sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==}+ engines: {node: '>=12'}+ dev: false+resolution: {integrity: sha512-EUkvKjqPFUAZyOlhY5gzCxCeI0Aep04LwIRpsZ/mLFelJiUfnK56jo5JMDSE7yyP2kLSb6LtF+S5chMk7uqPqw==}dependencies:@@ -8440,6 +8752,31 @@ packages:engines: {node: '>=12'}dev: false+ resolution: {integrity: sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==}+ engines: {node: '>=12'}+ peerDependencies:+ d3-selection: 2 - 3+ dependencies:+ d3-color: 3.1.0+ d3-dispatch: 3.0.1+ d3-ease: 3.0.1+ d3-interpolate: 3.0.1+ d3-selection: 3.0.0+ d3-timer: 3.0.1+ dev: false++ resolution: {integrity: sha512-b8AmV3kfQaqWAuacbPuNbL6vahnOJflOhexLzMMNLga62+/nh0JzvJ0aO/5a5MVgUFGS7Hu1P9P03o3fJkDCyw==}+ engines: {node: '>=12'}+ dependencies:+ d3-dispatch: 3.0.1+ d3-drag: 3.0.0+ d3-interpolate: 3.0.1+ d3-selection: 3.0.0+ d3-transition: 3.0.1([email protected])+ dev: false+resolution: {integrity: sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==}dependencies:@@ -13397,6 +13734,25 @@ packages:dependencies:loose-envify: 1.4.0+ resolution: {integrity: sha512-IHAKBkJngNvU9y1vZ5Nw9rvA3Z+zc9geTgQQIi9qq9Y9knGLlDDr9KfsjbFMew9AycAAgVg8TvBEakF4IT5lqg==}+ peerDependencies:+ react: '>=17'+ react-dom: '>=17'+ dependencies:+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ transitivePeerDependencies:+ - '@types/react'+ - immer+ dev: false+resolution: {integrity: sha512-Owdv/Ft7IjOgm/i0xvNDZ1LrRANRfew4b2prF3OWMQLxLfu3bS8FVhCsrSCMK4lR56Y9ya+AThoTpDCTxCmpRA==}dependencies:diff --git a/frontend/src/components/dependency-graph/custom-node.tsx b/frontend/src/components/dependency-graph/custom-node.tsxnew file mode 100644index 0000000000..e1d6c09ae3--- /dev/null+++ b/frontend/src/components/dependency-graph/custom-node.tsx@@ -0,0 +1,74 @@+/* Copyright 2023 Marimo. All rights reserved. */+import { CellData } from "@/core/model/cells";+import { TinyCode } from "@/editor/cell/TinyCode";+import { cn } from "@/lib/utils";+import { Atom, useAtomValue } from "jotai";+import { memo } from "react";+import { Handle, Position, NodeProps, useStore } from "reactflow";++export function getHeight(linesOfCode: number) {+ const LINE_HEIGHT = 11; // matches TinyCode.css+ return Math.min(linesOfCode * LINE_HEIGHT + 35, 200);+}++function getWidth(canvasWidth: number) {+ const minWidth = 100;+ const maxWidth = 400;+ const padding = 50;+ return Math.min(Math.max(canvasWidth - padding * 2, minWidth), maxWidth);+}++export const CustomNode = memo((props: NodeProps<{ atom: Atom<CellData> }>) => {+ const { data, selected, id } = props;+ const cell = useAtomValue(data.atom);+ const nonSelectedColor = "var(--gray-3)";+ const selectedColor = "var(--gray-9)";+ const color = selected ? selectedColor : nonSelectedColor;+ const reactFlowWidth = useStore(({ width }) => width);++ const linesOfCode = cell.code.split("\n").length;+ return (+ <div>+ <Handle+ type="target"+ id="inputs"+ position={Position.Left}+ style={{ background: color }}+ />+ <Handle+ type="source"+ id="inputs"+ position={Position.Left}+ style={{ background: color }}+ />+ <div+ className={cn(+ "flex flex-col bg-card border border-input/50 rounded-md mx-[2px] overflow-hidden",+ selected && "border-primary"+ )}+ style={{+ height: getHeight(linesOfCode),+ width: getWidth(reactFlowWidth),+ }}+ >+ <div className="text-muted-foreground font-semibold text-xs py-1 px-2 bg-muted border-b">+ Cell {id}+ </div>+ <TinyCode code={cell.code} />+ </div>+ <Handle+ type="source"+ id="outputs"+ position={Position.Right}+ style={{ background: color }}+ />+ <Handle+ type="target"+ id="outputs"+ position={Position.Right}+ style={{ background: color }}+ />+ </div>+ );+});+CustomNode.displayName = "CustomNode";diff --git a/frontend/src/components/dependency-graph/dependency-graph.css b/frontend/src/components/dependency-graph/dependency-graph.cssnew file mode 100644index 0000000000..d2543f8930--- /dev/null+++ b/frontend/src/components/dependency-graph/dependency-graph.css@@ -0,0 +1,11 @@+.react-flow__pane.react-flow__pane {+ cursor: default;+}++.react-flow__node.react-flow__node {+ cursor: pointer;+}++.react-flow__handle.react-flow__handle {+ @apply border-background;+}diff --git a/frontend/src/components/dependency-graph/dependency-graph.tsx b/frontend/src/components/dependency-graph/dependency-graph.tsxnew file mode 100644index 0000000000..f4dbaaa98d--- /dev/null+++ b/frontend/src/components/dependency-graph/dependency-graph.tsx@@ -0,0 +1,224 @@+/* Copyright 2023 Marimo. All rights reserved. */+import ReactFlow, {+ Node,+ Edge,+ MarkerType,+ ReactFlowProvider,+ useEdgesState,+ useNodesState,+ PanOnScrollMode,+ useStore,+ useReactFlow,+ CoordinateExtent,+} from "reactflow";++import React, { useEffect, useMemo, useState } from "react";+import {+ CustomNode,+ getHeight,+} from "@/components/dependency-graph/custom-node";+import { Variables } from "@/core/variables/types";+import { CellId } from "@/core/model/ids";+import { CellData } from "@/core/model/cells";+import { Atom } from "jotai";+import { store } from "@/core/state/jotai";++import "reactflow/dist/style.css";+import "./dependency-graph.css";+import { useDebouncedCallback } from "@/hooks/useDebounce";++interface Props {+ cellIds: CellId[];+ variables: Variables;+ cellAtoms: Array<Atom<CellData>>;+}++const nodeTypes = {+ custom: CustomNode,+};++export const DependencyGraph: React.FC<Props> = (props) => {+ return (+ <ReactFlowProvider>+ <DependencyGraphInternal {...props} />+ </ReactFlowProvider>+ );+};++const DependencyGraphInternal: React.FC<Props> = ({+ cellIds,+ variables,+ cellAtoms,+}) => {+ const { nodes: initialNodes, edges: initialEdges } = createElements(+ cellIds,+ cellAtoms,+ variables+ );+ const [edges, setEdges] = useEdgesState([]);+ const [nodes, setNodes] = useNodesState(initialNodes);++ const [allEdges, setAllEdges] = useState<Edge[]>(initialEdges);+ const [selectedNodeId, setSelectedNodeId] = useState<string>();++ // If the cellIds change, update the nodes.+ useEffect(() => {+ const { nodes, edges } = createElements(cellIds, cellAtoms, variables);+ setNodes(nodes);+ setAllEdges(edges);+ }, [cellIds, setNodes, variables, cellAtoms, setAllEdges]);++ // If the selected node changes, update the edges.+ useEffect(() => {+ if (selectedNodeId) {+ const selectedEdges = allEdges.filter((edge) => {+ const { source, target, data } = edge;++ return (+ (source === selectedNodeId && data.direction === "outputs") ||+ (target === selectedNodeId && data.direction === "inputs")+ );+ });+ setEdges(selectedEdges);+ } else {+ setEdges([]);+ }+ }, [selectedNodeId, setEdges, allEdges]);++ const instance = useReactFlow();+ const [width, height] = useStore(({ width, height }) => [width, height]);++ const debounceFitView = useDebouncedCallback(() => {+ instance.fitView({ duration: 100 });+ }, 100);++ // When the window is resized, fit the view to the graph.+ useEffect(() => {+ debounceFitView();+ }, [width, height, debounceFitView]);++ const translateExtent = useTranslateExtent(nodes, height);++ return (+ <ReactFlow+ nodes={nodes}+ edges={edges}+ nodeTypes={nodeTypes}+ translateExtent={translateExtent}+ onNodeClick={(_event, node) => {+ const id = node.id;+ setSelectedNodeId(id);+ }}+ // On+ snapToGrid={true}+ fitView={true}+ elementsSelectable={true}+ // Off+ minZoom={1}+ maxZoom={1}+ draggable={false}+ panOnScrollMode={PanOnScrollMode.Vertical}+ zoomOnDoubleClick={false}+ nodesDraggable={false}+ nodesConnectable={false}+ nodesFocusable={false}+ edgesFocusable={false}+ selectNodesOnDrag={false}+ panOnDrag={false}+ preventScrolling={false}+ zoomOnPinch={false}+ panOnScroll={true}+ autoPanOnNodeDrag={false}+ autoPanOnConnect={false}+ />+ );+};++function createEdge(source: CellId, target: CellId, direction: string): Edge {+ return {+ type: "smoothstep",+ pathOptions: {+ offset: 20,+ borderRadius: 100,+ },+ data: {+ direction: direction,+ },+ // animated: true,+ markerEnd: {+ type: MarkerType.Arrow,+ },+ id: `${source}-${target}-${direction}`,+ source: source,+ sourceHandle: direction,+ targetHandle: direction,+ target: target,+ };+}++function createNode(id: string, atom: Atom<CellData>, prevY: number): Node {+ const linesOfCode = store.get(atom).code.trim().split("\n").length;+ const height = getHeight(linesOfCode);+ return {+ id: id,+ data: { atom },+ width: 250,+ type: "custom",+ height: height,+ position: { x: 0, y: prevY + 20 },+ };+}++function createElements(+ cellIds: CellId[],+ cellAtoms: Array<Atom<CellData>>,+ variables: Variables+) {+ let prevY = 0;+ const nodes: Node[] = [];+ const edges: Edge[] = [];+ let index = 0;+ for (const cellId of cellIds) {+ const node = createNode(cellId, cellAtoms[index], prevY);+ nodes.push(node);+ prevY = node.position.y + (node.height || 0);+ index++;+ }++ for (const variable of Object.values(variables)) {+ const { declaredBy, usedBy } = variable;+ for (const fromId of declaredBy) {+ for (const toId of usedBy) {+ edges.push(+ createEdge(fromId, toId, "inputs"),+ createEdge(fromId, toId, "outputs")+ );+ }+ }+ }+ return { nodes, edges };+}++// Limit the extent of the graph to just the visible nodes.+// The top node and bottom node can be scrolled to the middle of the graph.+function useTranslateExtent(nodes: Node[], height: number): CoordinateExtent {+ const PADDING_Y = 10;++ return useMemo<CoordinateExtent>(() => {+ const top = nodes.reduce(+ (top, { position }) => Math.min(top, position.y - height / 2 - PADDING_Y),+ Number.POSITIVE_INFINITY+ );++ const bottom = nodes.reduce(+ (bottom, { position }) =>+ Math.max(bottom, position.y + height / 2 + PADDING_Y),+ Number.NEGATIVE_INFINITY+ );++ return [+ [Number.NEGATIVE_INFINITY, top],+ [Number.POSITIVE_INFINITY, bottom],+ ];+ }, [nodes, height]);+}diff --git a/frontend/src/core/state/__tests__/cells.test.ts b/frontend/src/core/state/__tests__/cells.test.tsindex 4c43e42ac1..65f00bb28f 100644--- a/frontend/src/core/state/__tests__/cells.test.ts+++ b/frontend/src/core/state/__tests__/cells.test.ts@@ -8,7 +8,7 @@ import {} from "../cells";import { CellId } from "@/core/model/ids";-const { initialCellState, reducer, createActions } = exportedForTesting;+const { initialNotebookState, reducer, createActions } = exportedForTesting;function formatCells(notebook: NotebookState) {const cells = notebookCells(notebook);@@ -30,7 +30,7 @@ describe("cell reducer", () => {beforeEach(() => {CellId.reset();- state = initialCellState();+ state = initialNotebookState();actions.createNewCell({ cellId: undefined!, before: false });firstCellId = state.cellIds[0];});diff --git a/frontend/src/core/state/cells.ts b/frontend/src/core/state/cells.tsindex 157308debb..bb73bf14aa 100644--- a/frontend/src/core/state/cells.ts+++ b/frontend/src/core/state/cells.ts@@ -1,5 +1,5 @@/* Copyright 2023 Marimo. All rights reserved. */-import { atom, useAtomValue, useSetAtom } from "jotai";+import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";import { ReducerWithoutAction, createRef, useMemo } from "react";import { CellMessage } from "../kernel/messages";import {@@ -26,6 +26,7 @@ import { CellHandle } from "@/editor/Cell";import { Logger } from "@/utils/Logger";import { Objects } from "@/utils/objects";import { EditorView } from "@codemirror/view";+import { splitAtom, selectAtom } from "jotai/utils";import { isStaticNotebook, parseStaticState } from "../static/static-state";/**@@ -562,6 +563,13 @@ export const getNotebook = () => store.get(notebookAtom);*/export const getCells = () => store.get(notebookAtom).cellIds;+const cellDataAtoms = splitAtom(+ selectAtom(notebookAtom, (cells) =>+ cells.cellIds.map((id) => cells.cellData[id])+ )+);+export const useCellDataAtoms = () => useAtom(cellDataAtoms);+/*** Get the editor views for all cells.*/@@ -674,5 +682,5 @@ export type CellActions = ReturnType<typeof createActions>;export const exportedForTesting = {reducer,createActions,- initialCellState: initialNotebookState,+ initialNotebookState,};diff --git a/frontend/src/editor/cell/TinyCode.css b/frontend/src/editor/cell/TinyCode.cssnew file mode 100644index 0000000000..49c933f79b--- /dev/null+++ b/frontend/src/editor/cell/TinyCode.css@@ -0,0 +1,9 @@+.tiny-code .cm-editor {+ padding: 0;+ margin: 0;+ font-size: 8px;+}++.tiny-code .cm-editor .cm-scroller {+ line-height: 11px;+}diff --git a/frontend/src/editor/cell/TinyCode.tsx b/frontend/src/editor/cell/TinyCode.tsxindex 141bb0c087..939e93c655 100644--- a/frontend/src/editor/cell/TinyCode.tsx+++ b/frontend/src/editor/cell/TinyCode.tsx@@ -1,29 +1,41 @@/* Copyright 2023 Marimo. All rights reserved. */import React from "react";+import CodeMirror, { minimalSetup } from "@uiw/react-codemirror";+import { python } from "@codemirror/lang-python";++import "./TinyCode.css";+import { useTheme } from "@/theme/useTheme";interface Props {code: string;}export const TinyCode: React.FC<Props> = ({ code }) => {+ const { theme } = useTheme();+return (- <div- className="text-muted-foreground flex flex-col overflow-hidden"- style={{- fontSize: "8px",- lineHeight: "10px",- }}- >- {code- .trim()- .split("\n")- .map((line, idx) => {- return (- <code className="whitespace-pre min-h-[10px]" key={idx}>- {line}- </code>- );- })}+ <div className="text-muted-foreground flex flex-col overflow-hidden">+ <CodeMirror+ minHeight="10px"+ theme={theme === "dark" ? "dark" : "light"}+ height="100%"+ className="tiny-code"+ editable={false}+ basicSetup={false}+ extensions={[+ python(),+ minimalSetup({+ syntaxHighlighting: true,+ // Rest false+ highlightSpecialChars: false,+ history: false,+ drawSelection: false,+ defaultKeymap: false,+ historyKeymap: false,+ }),+ ]}+ value={code}+ /></div>);};diff --git a/frontend/src/editor/chrome/panels/dependency-graph-panel.tsx b/frontend/src/editor/chrome/panels/dependency-graph-panel.tsxnew file mode 100644index 0000000000..35324d61c3--- /dev/null+++ b/frontend/src/editor/chrome/panels/dependency-graph-panel.tsx@@ -0,0 +1,22 @@+/* Copyright 2023 Marimo. All rights reserved. */+import { useCellDataAtoms, useCellIds } from "@/core/state/cells";+import { useVariables } from "@/core/variables/state";+import React from "react";+import { DependencyGraph } from "../../../components/dependency-graph/dependency-graph";+import { cn } from "@/lib/utils";++export const DependencyGraphPanel: React.FC = () => {+ const variables = useVariables();+ const cellIds = useCellIds();+ const [cells] = useCellDataAtoms();++ return (+ <div className={cn("w-full h-full flex-1 mx-auto -mb-4 relative")}>+ <DependencyGraph+ cellAtoms={cells}+ variables={variables}+ cellIds={cellIds}+ />+ </div>+ );+};diff --git a/frontend/src/editor/chrome/panels/variable-panel.tsx b/frontend/src/editor/chrome/panels/variable-panel.tsxnew file mode 100644index 0000000000..5148711191--- /dev/null+++ b/frontend/src/editor/chrome/panels/variable-panel.tsx@@ -0,0 +1,14 @@+/* Copyright 2023 Marimo. All rights reserved. */+import { VariableTable } from "@/components/variables/variables-table";+import { useCellIds } from "@/core/state/cells";+import { useVariables } from "@/core/variables/state";+import React from "react";++export const VariablePanel: React.FC = () => {+ const variables = useVariables();+ const cellIds = useCellIds();++ return (+ <VariableTable className="flex-1" cellIds={cellIds} variables={variables} />+ );+};diff --git a/frontend/src/editor/chrome/types.ts b/frontend/src/editor/chrome/types.tsindex 96bf19ef99..89ad911f00 100644--- a/frontend/src/editor/chrome/types.ts+++ b/frontend/src/editor/chrome/types.ts@@ -1,2 +1,2 @@/* Copyright 2023 Marimo. All rights reserved. */-export type PanelType = "errors" | "variables" | "outline";+export type PanelType = "errors" | "variables" | "outline" | "dependencies";diff --git a/frontend/src/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/editor/chrome/wrapper/app-chrome.tsxindex 4adec8de30..7f30409acf 100644--- a/frontend/src/editor/chrome/wrapper/app-chrome.tsx+++ b/frontend/src/editor/chrome/wrapper/app-chrome.tsx@@ -11,20 +11,17 @@ import "./app-chrome.css";import { useChromeActions, useChromeState } from "../state";import { cn } from "@/lib/utils";import { createStorage } from "./storage";-import { VariableTable } from "@/components/variables/variables-table";-import { useVariables } from "@/core/variables/state";-import { useCellIds } from "@/core/state/cells";import { Button } from "@/components/ui/button";import { XIcon } from "lucide-react";import { ErrorsPanel } from "../panels/error-panel";import { OutlinePanel } from "../panels/outline-panel";+import { DependencyGraphPanel } from "@/editor/chrome/panels/dependency-graph-panel";+import { VariablePanel } from "../panels/variable-panel";export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {const { isOpen, selectedPanel, panelLocation } = useChromeState();const { setIsOpen } = useChromeActions();const sidebarRef = React.useRef<ImperativePanelHandle>(null);- const variables = useVariables();- const cellIds = useCellIds();// sync sidebaruseEffect(() => {@@ -65,7 +62,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {}}}className={cn(- "border-border no-print",+ "border-border no-print z-10",isOpen ? "resize-handle" : "resize-handle-collapsed",panelLocation === "left" ? "vertical" : "horizontal")}@@ -88,13 +85,8 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {</Button></div>{selectedPanel === "errors" && <ErrorsPanel />}- {selectedPanel === "variables" && (- <VariableTable- className="flex-1"- cellIds={cellIds}- variables={variables}- />- )}+ {selectedPanel === "variables" && <VariablePanel />}+ {selectedPanel === "dependencies" && <DependencyGraphPanel />}{selectedPanel === "outline" && <OutlinePanel />}</div>);diff --git a/frontend/src/editor/chrome/wrapper/footer.tsx b/frontend/src/editor/chrome/wrapper/footer.tsxindex f19fcfb94f..01c721d699 100644--- a/frontend/src/editor/chrome/wrapper/footer.tsx+++ b/frontend/src/editor/chrome/wrapper/footer.tsx@@ -6,6 +6,7 @@ import {CircleEqualIcon,XCircleIcon,ScrollTextIcon,+ NetworkIcon,} from "lucide-react";import { cn } from "@/lib/utils";import { useChromeActions, useChromeState } from "../state";@@ -46,6 +47,13 @@ export const Footer: React.FC = () => {><ScrollTextIcon className={cn("h-4 w-4")} /></FooterItem>+ <FooterItem+ tooltip="Explore dependencies"+ selected={selectedPanel === "dependencies"}+ onClick={() => openApplication("dependencies")}+ >+ <NetworkIcon className={cn("h-4 w-4")} />+ </FooterItem><div className="mx-auto" /><FooterItemtooltip="Move panel to the left"diff --git a/frontend/src/hooks/useDebounce.ts b/frontend/src/hooks/useDebounce.tsindex 436d6d49e4..7dd958c5b4 100644--- a/frontend/src/hooks/useDebounce.ts+++ b/frontend/src/hooks/useDebounce.ts@@ -1,5 +1,6 @@/* Copyright 2023 Marimo. All rights reserved. */-import { useEffect, useState } from "react";+import { debounce } from "lodash-es";+import { useEffect, useMemo, useState } from "react";import useEvent from "react-use-event-hook";export function useDebounce<T>(value: T, delay: number): T {@@ -75,3 +76,13 @@ export function useDebounceControlledState<T>(opts: {},};}++export function useDebouncedCallback<T extends (...args: unknown[]) => unknown>(+ callback: T,+ delay: number+) {+ const internalCallback = useEvent(callback);+ return useMemo(() => {+ return debounce(internalCallback, delay);+ }, [internalCallback, delay]);+}