diff --git a/package-lock.json b/package-lock.json index abec13b907..03bae6c98b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5121,6 +5121,12 @@ "dev": true, "license": "ISC" }, + "node_modules/@viz-js/viz": { + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/@viz-js/viz/-/viz-3.11.0.tgz", + "integrity": "sha512-3zoKLQUqShIhTPvBAIIgJUf5wO9aY0q+Ftzw1u26KkJX1OJjT7Z5VUqgML2GIzXJYFgjqS6a2VREMwrgChuubA==", + "license": "MIT" + }, "node_modules/@vue/compiler-core": { "version": "3.5.11", "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.11.tgz", @@ -19319,13 +19325,6 @@ "node": ">= 0.8" } }, - "node_modules/viz.js": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/viz.js/-/viz.js-1.8.1.tgz", - "integrity": "sha512-KrSNgnIxec+JCAqDPliO6xYA69ToH2WTYB2Kbt8Bp/XRUvm23rTyfffFi4rvQLFkIRNUz/xCnnqhh/gChhsgGA==", - "deprecated": "2.x is no longer supported, 3.x published as @viz-js/viz", - "license": "MIT" - }, "node_modules/w3c-xmlserializer": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", @@ -20456,11 +20455,11 @@ "version": "0.2.0", "license": "Apache-2.0", "dependencies": { + "@viz-js/viz": "^3.11.0", "d3-selection": "^3.0.0", "d3-zoom": "^3.0.0", "memoize-one": "6.0.0", - "react-icons": "^5.0.1", - "viz.js": "1.8.1" + "react-icons": "^5.0.1" }, "devDependencies": { "@babel/cli": "7.26.4", diff --git a/packages/plexus/package.json b/packages/plexus/package.json index dfc1a61736..39d8985caf 100644 --- a/packages/plexus/package.json +++ b/packages/plexus/package.json @@ -49,11 +49,11 @@ "react-dom": "^18.x" }, "dependencies": { + "@viz-js/viz": "^3.11.0", "d3-selection": "^3.0.0", "d3-zoom": "^3.0.0", "memoize-one": "6.0.0", - "react-icons": "^5.0.1", - "viz.js": "1.8.1" + "react-icons": "^5.0.1" }, "scripts": { "_tasks/build/lib/js": "babel src --extensions '.tsx,.js' --out-dir lib", diff --git a/packages/plexus/src/LayoutManager/getLayout.tsx b/packages/plexus/src/LayoutManager/getLayout.tsx index 916c99f484..f83679b5f0 100644 --- a/packages/plexus/src/LayoutManager/getLayout.tsx +++ b/packages/plexus/src/LayoutManager/getLayout.tsx @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import viz from 'viz.js/viz.js'; +import { instance } from '@viz-js/viz'; import convPlain from './dot/convPlain'; import toDot from './dot/toDot'; @@ -98,7 +98,7 @@ function getVerticesValidity( return warn; } -export default function getLayout( +export default async function getLayout( phase: EWorkerPhase, inEdges: TEdge[], inVertices: TSizeVertex[] | TLayoutVertex[], @@ -107,7 +107,10 @@ export default function getLayout( const dot = toDot(inEdges, inVertices, layoutOptions); const { totalMemory = undefined } = layoutOptions || {}; const options = { totalMemory, engine: phase === EWorkerPhase.Edges ? 'neato' : 'dot', format: 'plain' }; - const plainOut = viz(dot, options); + + const viz = await instance(); + const plainOut = viz.renderString(dot, options); + const { edges, graph, vertices } = convPlain(plainOut, phase !== EWorkerPhase.Positions); const result = getVerticesValidity(inVertices, vertices); if (result.validity === EValidity.Error) { diff --git a/packages/plexus/src/LayoutManager/layout.worker.tsx b/packages/plexus/src/LayoutManager/layout.worker.tsx index 0c2966ca14..ff0934ca7e 100644 --- a/packages/plexus/src/LayoutManager/layout.worker.tsx +++ b/packages/plexus/src/LayoutManager/layout.worker.tsx @@ -32,10 +32,10 @@ const ctx: Worker & TMessageErrorTarget = self as any; let currentMeta: TLayoutWorkerMeta | null; -function handleMessage(event: MessageEvent) { +async function handleMessage(event: MessageEvent) { const { edges, meta, options, vertices } = event.data as TWorkerInputMessage; currentMeta = meta; - const { layoutError, ...result } = getLayout(meta.phase, edges, vertices, options); + const { layoutError, ...result } = await getLayout(meta.phase, edges, vertices, options); const type = layoutError ? EWorkerErrorType.LayoutError : meta.phase; const message: TWorkerOutputMessage = { meta, type, ...result }; ctx.postMessage(message); diff --git a/packages/plexus/typings/custom.d.ts b/packages/plexus/typings/custom.d.ts deleted file mode 100644 index 768bf24d1b..0000000000 --- a/packages/plexus/typings/custom.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2019 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Note: These type defs cannot be in the typings/index.d.ts file (due to -// TypeScript automagic?). - -// Type def for the viz.js module, which doesn't ship with usable TypeScript -// types. -declare module "viz.js/viz.js" { - export default function viz(dot: string, options?: {}): string; -} diff --git a/packages/plexus/typings/index.d.ts b/packages/plexus/typings/index.d.ts deleted file mode 100644 index acad0a02e0..0000000000 --- a/packages/plexus/typings/index.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2019 Uber Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -///