From 7bde2ee9ee992206aed6e3d4bbeb40c429b8d05f Mon Sep 17 00:00:00 2001 From: wuyulong17 <2284273586@qq.com> Date: Mon, 4 Aug 2025 11:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=90=E5=9B=BE=E5=88=86=E5=89=B2=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ModelVis/Cargo.lock | 260 +++--------------- .../ModelVis/app/src/App.tsx | 14 +- .../app/src/ModelStructure/Fsg/index.tsx | 5 +- .../src/ModelStructure/Properties/index.tsx | 2 +- .../ModelVis/app/src/ModelStructure/index.tsx | 45 ++- .../ModelVis/app/src/hooks/useCleanup.ts | 10 +- .../app/src/hooks/useNewPathForLayout.ts | 20 +- .../ModelVis/app/src/libs/get-subgraph.ts | 27 ++ .../ModelVis/app/src/libs/index.ts | 1 + .../ModelVis/app/src/src-worker/render.ts | 11 +- .../ModelVis/app/src/stores/app-context.ts | 10 +- .../ModelVis/app/src/styles/index.css | 11 + .../ModelVis/app/src/types/model.d.ts | 13 +- .../ModelVis/app/src/useWorkerMessage.ts | 34 ++- 14 files changed, 199 insertions(+), 264 deletions(-) create mode 100644 plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/get-subgraph.ts diff --git a/plugins/mindstudio-insight-plugins/ModelVis/Cargo.lock b/plugins/mindstudio-insight-plugins/ModelVis/Cargo.lock index 1b241206ea..7d68e7eaae 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/Cargo.lock +++ b/plugins/mindstudio-insight-plugins/ModelVis/Cargo.lock @@ -76,15 +76,6 @@ version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" -[[package]] -name = "ash" -version = "0.38.0+1.3.281" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" -dependencies = [ - "libloading 0.8.7", -] - [[package]] name = "ashpd" version = "0.11.0" @@ -513,25 +504,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -860,13 +832,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "error" -version = "0.1.0" -dependencies = [ - "serde", -] - [[package]] name = "event-listener" version = "5.4.0" @@ -913,14 +878,6 @@ dependencies = [ "rustc_version", ] -[[package]] -name = "file-ext" -version = "0.1.0" -dependencies = [ - "libc", - "windows 0.61.1", -] - [[package]] name = "fixedbitset" version = "0.5.7" @@ -979,6 +936,18 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fsg" +version = "0.1.0" +dependencies = [ + "anyhow", + "parser", + "rustc-hash", + "serde", + "serde_json", + "smartstring", +] + [[package]] name = "futf" version = "0.1.5" @@ -1515,7 +1484,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core 0.61.1", + "windows-core", ] [[package]] @@ -1835,7 +1804,6 @@ dependencies = [ "ahash", "anyhow", "mimalloc", - "perf", "smallvec 2.0.0-alpha.11", ] @@ -1865,7 +1833,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e9ec52138abedcc58dc17a7c6c0c00a2bdb4f3427c7f63fa97fd0d859155caf" dependencies = [ "gtk-sys", - "libloading 0.7.4", + "libloading", "once_cell", ] @@ -1885,16 +1853,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "libloading" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c" -dependencies = [ - "cfg-if", - "windows-targets 0.53.0", -] - [[package]] name = "libmimalloc-sys" version = "0.1.42" @@ -2102,15 +2060,6 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" -[[package]] -name = "ntapi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" -dependencies = [ - "winapi", -] - [[package]] name = "num-conv" version = "0.1.0" @@ -2480,7 +2429,7 @@ dependencies = [ "protobuf", "ryu", "serde", - "smartstring 1.0.1", + "smartstring", "thiserror 2.0.12", ] @@ -2496,14 +2445,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "perf" -version = "0.0.1" -dependencies = [ - "quote", - "syn 2.0.101", -] - [[package]] name = "petgraph" version = "0.7.1" @@ -3011,26 +2952,6 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_syscall" version = "0.5.12" @@ -3486,13 +3407,6 @@ dependencies = [ "serde", ] -[[package]] -name = "smartstring" -version = "1.0.0" -dependencies = [ - "serde", -] - [[package]] name = "smartstring" version = "1.0.1" @@ -3606,18 +3520,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "subgraph" -version = "0.1.0" -dependencies = [ - "anyhow", - "parser", - "rustc-hash", - "serde", - "serde_json", - "smartstring 1.0.1", -] - [[package]] name = "swift-rs" version = "1.0.7" @@ -3671,28 +3573,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "sys-info" -version = "0.1.0" -dependencies = [ - "ash", - "sysinfo", -] - -[[package]] -name = "sysinfo" -version = "0.33.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc858248ea01b66f19d8e8a6d55f41deaf91e9d495246fd01368d99935c6c01" -dependencies = [ - "core-foundation-sys", - "libc", - "memchr", - "ntapi", - "rayon", - "windows 0.57.0", -] - [[package]] name = "system-deps" version = "6.2.2" @@ -3739,8 +3619,8 @@ dependencies = [ "tao-macros", "unicode-segmentation", "url", - "windows 0.61.1", - "windows-core 0.61.1", + "windows", + "windows-core", "windows-version", "x11-dl", ] @@ -3810,7 +3690,7 @@ dependencies = [ "webkit2gtk", "webview2-com", "window-vibrancy", - "windows 0.61.1", + "windows", ] [[package]] @@ -3974,7 +3854,7 @@ dependencies = [ "tauri-utils", "thiserror 2.0.12", "url", - "windows 0.61.1", + "windows", ] [[package]] @@ -4000,7 +3880,7 @@ dependencies = [ "url", "webkit2gtk", "webview2-com", - "windows 0.61.1", + "windows", "wry", ] @@ -4077,17 +3957,6 @@ dependencies = [ "utf-8", ] -[[package]] -name = "test-layout" -version = "0.0.1" -dependencies = [ - "layout", - "parser", - "serde", - "serde_json", - "smartstring 1.0.1", -] - [[package]] name = "thin-slice" version = "0.1.1" @@ -4494,12 +4363,12 @@ version = "0.1.0" dependencies = [ "ahash", "anyhow", + "fsg", "layout", "parser", "serde", "serde_json", - "smartstring 1.0.1", - "subgraph", + "smartstring", "tauri", "tauri-build", "tauri-plugin-dialog", @@ -4712,10 +4581,10 @@ checksum = "b542b5cfbd9618c46c2784e4d41ba218c336ac70d44c55e47b251033e7d85601" dependencies = [ "webview2-com-macros", "webview2-com-sys", - "windows 0.61.1", - "windows-core 0.61.1", - "windows-implement 0.60.0", - "windows-interface 0.59.1", + "windows", + "windows-core", + "windows-implement", + "windows-interface", ] [[package]] @@ -4736,8 +4605,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ae2d11c4a686e4409659d7891791254cf9286d3cfe0eef54df1523533d22295" dependencies = [ "thiserror 2.0.12", - "windows 0.61.1", - "windows-core 0.61.1", + "windows", + "windows-core", ] [[package]] @@ -4786,16 +4655,6 @@ dependencies = [ "windows-version", ] -[[package]] -name = "windows" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" -dependencies = [ - "windows-core 0.57.0", - "windows-targets 0.52.6", -] - [[package]] name = "windows" version = "0.61.1" @@ -4803,7 +4662,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419" dependencies = [ "windows-collections", - "windows-core 0.61.1", + "windows-core", "windows-future", "windows-link", "windows-numerics", @@ -4815,19 +4674,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" dependencies = [ - "windows-core 0.61.1", -] - -[[package]] -name = "windows-core" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" -dependencies = [ - "windows-implement 0.57.0", - "windows-interface 0.57.0", - "windows-result 0.1.2", - "windows-targets 0.52.6", + "windows-core", ] [[package]] @@ -4836,10 +4683,10 @@ version = "0.61.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46ec44dc15085cea82cf9c78f85a9114c463a369786585ad2882d1ff0b0acf40" dependencies = [ - "windows-implement 0.60.0", - "windows-interface 0.59.1", + "windows-implement", + "windows-interface", "windows-link", - "windows-result 0.3.3", + "windows-result", "windows-strings 0.4.1", ] @@ -4849,22 +4696,11 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" dependencies = [ - "windows-core 0.61.1", + "windows-core", "windows-link", "windows-threading", ] -[[package]] -name = "windows-implement" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.101", -] - [[package]] name = "windows-implement" version = "0.60.0" @@ -4876,17 +4712,6 @@ dependencies = [ "syn 2.0.101", ] -[[package]] -name = "windows-interface" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.101", -] - [[package]] name = "windows-interface" version = "0.59.1" @@ -4910,7 +4735,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" dependencies = [ - "windows-core 0.61.1", + "windows-core", "windows-link", ] @@ -4920,20 +4745,11 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ - "windows-result 0.3.3", + "windows-result", "windows-strings 0.3.1", "windows-targets 0.53.0", ] -[[package]] -name = "windows-result" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-result" version = "0.3.3" @@ -5338,8 +5154,8 @@ dependencies = [ "webkit2gtk", "webkit2gtk-sys", "webview2-com", - "windows 0.61.1", - "windows-core 0.61.1", + "windows", + "windows-core", "windows-version", "x11-dl", ] diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/App.tsx b/plugins/mindstudio-insight-plugins/ModelVis/app/src/App.tsx index 372979fb76..a30014afc3 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/App.tsx +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/App.tsx @@ -31,13 +31,13 @@ const App = () => { {modelPath - ? <> - -
- -
- - : + ? <> + +
+ +
+ + : } } diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Fsg/index.tsx b/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Fsg/index.tsx index d28daa6100..5982afb404 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Fsg/index.tsx +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Fsg/index.tsx @@ -21,7 +21,7 @@ import { loadingAtom, modelPathAtom, fsgPanelVisibleAtom, - fsgVisibleAtom, themeAtom + fsgVisibleAtom, themeAtom, currentGraphAtom } from '../../stores' import { useAtom, useSetAtom } from 'jotai/index' import { invoke } from '@tauri-apps/api/core' @@ -104,6 +104,7 @@ const Fsg = () => { const path = useAtomValue(modelPathAtom) const [fsgData, setFsgData] = useState([]) const [selectedRow, setSelectedRow] = useState() + const currentGraph = useAtomValue(currentGraphAtom) const columns = getColumns(t) const globalTheme = useAtomValue(themeAtom) @@ -112,7 +113,7 @@ const Fsg = () => { setLoading(true) const res = await invoke( 'mine_fsg', - { path, minSup: repeat, min, max } + { path, minSup: repeat, min, max, name: currentGraph.name } ) const fsgs = dedup(sortedFsgs(res)) setFsgData(fsgs) diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Properties/index.tsx b/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Properties/index.tsx index 357decbc19..d322f8132a 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Properties/index.tsx +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/Properties/index.tsx @@ -31,7 +31,7 @@ const Properties = () => { const t = useI18n() - if (!current) return null + if (!current || !model) return null const isNode = typeof current === "string" const { nodes, parameters } = model diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/index.tsx b/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/index.tsx index dc4e51a6eb..8fec5c4df6 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/index.tsx +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/ModelStructure/index.tsx @@ -15,7 +15,7 @@ import { Grid, Responsive, SearchModal, type WindowSize } from "features" import { useAtom, useAtomValue } from "jotai" -import { clsx, debounce } from "libs" +import { clsx, debounce, getSubgraph, joinCls } from "libs" import { type MouseEvent, type WheelEvent, @@ -24,7 +24,15 @@ import { useRef, useState } from "react" -import { nodesEdgesAtom, fsgVisibleAtom, themeAtom, translateAtom, useZoom } from "stores" +import { + nodesEdgesAtom, + fsgVisibleAtom, + themeAtom, + translateAtom, + useZoom, + currentGraphAtom, + allGraphAtom +} from "stores" import { workerHitTest, workerInit, @@ -163,12 +171,45 @@ const ModelStructureComp = ({ width, height }: WindowSize) => { } +const GraphPath = () => { + const [currentGraph, setCurrentGraph] = useAtom(currentGraphAtom) + const [translate, setTranslate] = useAtom(translateAtom) + const allGraphs = useAtomValue(allGraphAtom) + if (!currentGraph || !allGraphs || currentGraph.paths.length < 1) return null + + const onClickPath = (graphName: string) => { + const targetGraph = getSubgraph(allGraphs, graphName) + if (targetGraph) { + setCurrentGraph(targetGraph) + if (translate.x !== 0 || translate.y !== 0) { + setTranslate({ x: 0, y: 0 }) + } + } + } + + return
+ {currentGraph.paths.map(((item, index) => + index === currentGraph.paths.length - 1 ? + {item} : + <> + onClickPath(item)}>{item} + / + ))} +
+} + const ModelStructure = () => {props => ( <> + diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useCleanup.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useCleanup.ts index af8b9b804f..fc2eb3f4ea 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useCleanup.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useCleanup.ts @@ -26,11 +26,11 @@ import { workerCleanUp } from "worker-apis" export const useCleanup = (): VoidFunction => { const history = useSelectionHistory() const setModelPath = useSetAtom(modelPathAtom) - const setModelData = useSetAtom(modelDataAtom as any) - const setNodesEdges = useSetAtom(nodesEdgesAtom as any) - const setDynamicNodes = useSetAtom(dynamicNodesAtom as any) + const setModelData = useSetAtom(modelDataAtom) + const setNodesEdges = useSetAtom(nodesEdgesAtom) + const setDynamicNodes = useSetAtom(dynamicNodesAtom) const setDynamicVisible = useSetAtom(dynamicVisibleAtom) - const setFsgs = useSetAtom(fsgAtom as any) + const setFsgs = useSetAtom(fsgAtom) const setFsgsVisible = useSetAtom(fsgVisibleAtom) return () => { @@ -42,7 +42,7 @@ export const useCleanup = (): VoidFunction => { setModelPath(null) setDynamicNodes(null) setDynamicVisible(false) - setFsgs(null) + setFsgs([]) setFsgsVisible(false) } } diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useNewPathForLayout.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useNewPathForLayout.ts index 95a95f2a85..6f92ee6e4a 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useNewPathForLayout.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/hooks/useNewPathForLayout.ts @@ -19,12 +19,10 @@ import { toast } from "sonner" import { dynamicVisibleAtom, loadingAtom, - modelDataAtom, modelPathAtom, - nodesEdgesAtom, recentProjCache, fsgVisibleAtom, - translateAtom, useSelectionHistory, useZoom + translateAtom, useSelectionHistory, useZoom, currentGraphAtom, allGraphAtom } from "stores" type LayoutNewPath = (path: string | null) => Promise @@ -32,8 +30,8 @@ type LayoutNewPath = (path: string | null) => Promise export const useNewPathForLayout = (): LayoutNewPath => { const [modelPath, setModelPath] = useAtom(modelPathAtom) const history = useSelectionHistory() - const setModelData = useSetAtom(modelDataAtom) - const setLayoutRet = useSetAtom(nodesEdgesAtom) + const setCurrentGraphAtom = useSetAtom(currentGraphAtom) + const setAllGraphAtom = useSetAtom(allGraphAtom) const setDynamicVisible = useSetAtom(dynamicVisibleAtom) const setFsgsVisible = useSetAtom(fsgVisibleAtom) const [translate, setTranslate] = useAtom(translateAtom) @@ -47,11 +45,7 @@ export const useNewPathForLayout = (): LayoutNewPath => { const start = performance.now() setLoading(true) - const { - model, - nodes, - edges - } = await invoke("layout_bin", {path}) + const res = await invoke("layout_bin", {path}) setLoading(false) toast.success(`parse + transfer cost ${Math.round(performance.now() - start)}ms`, { @@ -59,10 +53,10 @@ export const useNewPathForLayout = (): LayoutNewPath => { closeButton: true }) - if (model) { + if (res) { history.clear() - setModelData(model) - setLayoutRet({nodes, edges}) + setCurrentGraphAtom(res) + setAllGraphAtom(res) setDynamicVisible(false) setFsgsVisible(false) if (translate.x !== 0 || translate.y !== 0) setTranslate({ diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/get-subgraph.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/get-subgraph.ts new file mode 100644 index 0000000000..bbc7a7988d --- /dev/null +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/get-subgraph.ts @@ -0,0 +1,27 @@ +// Copyright (c) 2025, Huawei Technologies Co., Ltd. +// All rights reserved. +// +// 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. + +export const getSubgraph = (graph: LayoutRet, name: string): LayoutRet | null => { + if (graph.name === name) { + return graph + } + for (const subgraph of graph.children) { + const res = getSubgraph(subgraph, name) + if (res) { + return res + } + } + return null +} \ No newline at end of file diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/index.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/index.ts index 9a5d64d64d..04ddab67b6 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/index.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/libs/index.ts @@ -20,3 +20,4 @@ export * from "./throttle" export * from "./ring" export * from "./file-dialog" export * from "./join-cls" +export * from './get-subgraph' diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/src-worker/render.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/src-worker/render.ts index 3ce24e1bf4..884ca9ded9 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/src-worker/render.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/src-worker/render.ts @@ -153,22 +153,23 @@ const renderNodes = ( const visibleNodes = [] for (const node of nodes) { - const { opType, x, y, width, height, dynamic } = node + const { id, opType, x, y, width, height, dynamic } = node if (!intersects(node, sx, sy, ex, ey)) continue - + visibleNodes.push(node) if (opType === "subgraph") { Ctx.save() + Ctx.fillText(id.length <= 20 ? id : `${id.substring(0, 16)}...`, x + width / 2, y + height / 2) Ctx.strokeStyle = "#00E5FF" Ctx.strokeRect(x, y, width, height) + Ctx.fillStyle = node.completed ? 'rgba(0, 255, 0, 0.5)' : 'rgba(255, 0, 0, 0.5)' + Ctx.fillRect(x, y, width, height) Ctx.restore() continue } - visibleNodes.push(node) - Ctx.save() - Ctx.strokeStyle = getColor(node.opType) + Ctx.strokeStyle = getColor(opType) if (MarkDynOp && (dynamic || opType === "Concat")) renderNodeWithDynMark(node) else Ctx.fillText(opType, x + width / 2, y + height / 2) diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/stores/app-context.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/stores/app-context.ts index 48115a43e1..6398cf4e1e 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/stores/app-context.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/stores/app-context.ts @@ -3,9 +3,13 @@ import { atom } from "jotai" export const gridVisibleAtom = atom(true) export const fsgVisibleAtom = atom(false) export const fsgPanelVisibleAtom = atom(false) -export const fsgAtom = atom(null!) +export const fsgAtom = atom([]) export const dynamicVisibleAtom = atom(false) export const dynamicNodesAtom = atom(null) export const modelPathAtom = atom(null) -export const modelDataAtom = atom(null!) -export const nodesEdgesAtom = atom(null!) +export const modelDataAtom = atom(null) +export const nodesEdgesAtom = atom(null) +export const allGraphAtom = atom(null!) +export const currentGraphAtom = atom({children: [], name: '', paths: []}) +export const subgraphesAtom = atom({}) +export const updateSubgraphAtom = atom(null, (get, set, newValue: Subgraphs) => set(subgraphesAtom, newValue)) diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/styles/index.css b/plugins/mindstudio-insight-plugins/ModelVis/app/src/styles/index.css index 75062ab84f..dd9d86b374 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/styles/index.css +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/styles/index.css @@ -81,3 +81,14 @@ image { .dark .glass-effect { background: rgba(30, 41, 59, 0.7); } + +.path-name { + cursor: pointer; + &:hover { + color: #4096FF; + } +} + +.current-path-name { + color: #1677FF; +} diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/types/model.d.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/types/model.d.ts index 4ab092b53b..0f4f27d3de 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/types/model.d.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/types/model.d.ts @@ -72,6 +72,7 @@ type RenderNode = BoundingRect & { id: string opType: string dynamic: boolean + completed?: boolean } type RenderEdge = BoundingRect & { @@ -82,11 +83,21 @@ type RenderEdge = BoundingRect & { } type LayoutRet = { - model: ModelData, + children: LayoutRet[] + name: string + paths: string[] +} + +type GraphData = { + model: ModelData nodes: RenderNode[] edges: RenderEdge[] } +type Subgraphs = { + [name: string]: GraphData +} + type NodesEdges = { nodes: RenderNode[] edges: RenderEdge[] diff --git a/plugins/mindstudio-insight-plugins/ModelVis/app/src/useWorkerMessage.ts b/plugins/mindstudio-insight-plugins/ModelVis/app/src/useWorkerMessage.ts index db647bb602..e050f658d7 100644 --- a/plugins/mindstudio-insight-plugins/ModelVis/app/src/useWorkerMessage.ts +++ b/plugins/mindstudio-insight-plugins/ModelVis/app/src/useWorkerMessage.ts @@ -13,16 +13,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { useSetAtom } from "jotai" +import { useAtomValue, useSetAtom } from "jotai" import { + allGraphAtom, currentGraphAtom, dynamicNodesAtom, - searchResultAtom, useSelectionHistory, + searchResultAtom, subgraphesAtom, translateAtom, useSelectionHistory, } from "./stores" import WebWorker from "./worker" +import { getSubgraph } from "./libs"; +import { useAtom } from "jotai/index"; +import { listen } from "@tauri-apps/api/event"; + +const PARSE_GRAPH_EVENT = "parse_graph_success" const useWorkerMessage = () => { const setSearchResult = useSetAtom(searchResultAtom) const setDynamicNodes = useSetAtom(dynamicNodesAtom) + const allGraphs = useAtomValue(allGraphAtom) + const setCurrentGraph = useSetAtom(currentGraphAtom) + const [translate, setTranslate] = useAtom(translateAtom) + const [subgraphs, setSubGraphs] = useAtom(subgraphesAtom) const { update, clear } = useSelectionHistory() WebWorker.onmessage = ({ data: payload }) => { @@ -33,7 +43,17 @@ const useWorkerMessage = () => { case "hit-test/ret": { const ret = payload?.data - if (ret?.id) update(ret.id) + if (ret?.id) { + const currentGraph = getSubgraph(allGraphs, ret.id) + if (currentGraph) { + setCurrentGraph(currentGraph) + if (translate.x !== 0 || translate.y !== 0) { + setTranslate({ x: 0, y: 0 }) + } + } else { + update(ret.id) + } + } else if (ret?.source) update({ source: ret?.source, target: ret?.target }) @@ -46,6 +66,14 @@ const useWorkerMessage = () => { break } } + + listen(PARSE_GRAPH_EVENT, (event: any) => { + const { model } = event.payload + if (model?.name) { + subgraphs[model.name] = event.payload + setSubGraphs({ ...subgraphs }) + } + }) } export default useWorkerMessage -- Gitee