graph-viewer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGraph Viewer
图形查看器
Use This When
适用场景
The user wants to embed an interactive graph of a CDF data model — nodes, direct relations, edges, and reverse relations — inside a Dune app.
Do not use this skill for static diagrams, pure dataflow visualizations, or non-CDF graphs.
用户希望在Dune应用中嵌入CDF数据模型的交互式图形——包含节点、直接关联、边和反向关联。
请勿将此技能用于静态图表、纯数据流可视化或非CDF图形。
Prerequisites
前置条件
- The app is wrapped in 's
@cognite/duneso<DuneProvider>returns an authenticated SDK.useDune() - The target data model exists in CDF and you know its ,
space, andexternalId.version - The app uses React 18+ and TypeScript.
- 应用已被的
@cognite/dune包裹,确保<DuneProvider>能返回已认证的SDK。useDune() - 目标数据模型已存在于CDF中,且你知晓其、
space和externalId。version - 应用使用React 18+和TypeScript。
Integration Workflow
集成流程
Follow these steps in order. Adapt to the target repo's conventions instead of inventing new ones.
-
Inspect the target app. Readand look at the existing folder structure (e.g.
package.json,src/features/*, path aliases likesrc/components/*).@/* -
Install missing dependencies with the app's package manager (,
npm,pnpm, …). See the Dependencies table below for purposes and suggested versions. Reuse the React version already pinned by the app rather than upgrading it, and prefer any versions the repo already pins over the suggestions here.yarn -
Copy the bundle into the app. Copy every file frominto an app-local feature folder, for example:
skills/graph-viewer/code/textsrc/features/graph-viewer/If the repo already has a different feature/components layout or alias, mirror it. -
Import from the local folder, never from. With a typical
@skills/...alias:@/*tsximport { useGraphViewer } from "@/features/graph-viewer"; -
Renderinside a container with explicit dimensions (height is required — see the minimal example below).
GraphCanvas -
Run typecheck and build (,
tsc --noEmit, etc.) and fix any path or type issues introduced by the copy.npm run build
按以下顺序执行步骤,需适配目标仓库的约定,而非自行创建新规则。
-
检查目标应用:阅读并查看现有文件夹结构(如
package.json、src/features/*、src/components/*这类路径别名)。@/* -
安装缺失依赖:使用应用的包管理器(、
npm、pnpm等)安装。下方依赖表格列出了用途和建议版本。优先复用应用已锁定的React版本,而非升级;若仓库已锁定其他依赖版本,优先使用仓库版本而非此处建议版本。yarn -
复制代码包到应用:将下的所有文件复制到应用本地的功能文件夹中,例如:
skills/graph-viewer/code/textsrc/features/graph-viewer/若仓库已有不同的功能/组件布局或别名,请保持一致。 -
从本地文件夹导入,切勿从导入。使用典型的
@skills/...别名示例:@/*tsximport { useGraphViewer } from "@/features/graph-viewer"; -
在具有明确尺寸的容器内渲染(高度为必填项——见下方最简示例)。
GraphCanvas -
运行类型检查和构建(、
tsc --noEmit等),修复复制过程中引入的路径或类型问题。npm run build
Minimal Example
最简示例
tsx
import { useGraphViewer } from "@/features/graph-viewer";
export function GraphPanel() {
const { GraphCanvas, isLoading, error } = useGraphViewer({
dataModel: { space: "my-space", externalId: "my-data-model", version: "1" },
instance: { space: "my-instance-space", externalId: "pump-001" },
});
if (isLoading) return <div>Loading graph…</div>;
if (error) return <div>Error: {error}</div>;
return <GraphCanvas className="h-[600px] w-full" />;
}tsx
import { useGraphViewer } from "@/features/graph-viewer";
export function GraphPanel() {
const { GraphCanvas, isLoading, error } = useGraphViewer({
dataModel: { space: "my-space", externalId: "my-data-model", version: "1" },
instance: { space: "my-instance-space", externalId: "pump-001" },
});
if (isLoading) return <div>加载图形中…</div>;
if (error) return <div>错误:{error}</div>;
return <GraphCanvas className="h-[600px] w-full" />;
}Dependencies
依赖
Suggested versions reflect the latest published majors at the time of writing. They are starting points — if the target app already pins different versions, defer to the app.
| Package | Suggested version | Purpose |
|---|---|---|
| | UI framework (peer; reuse the app's version) |
| | CDF API client (instances, data models) |
| | Provides the authenticated SDK via |
| | WebGL graph rendering engine |
| | Icon set used by the node-type legend |
Example install (npm; adapt to the app's package manager):
bash
npm install @cognite/sdk@^10.10.0 @cognite/dune@^2.1.0 reagraph@^4.30.8 lucide-react@^1.14.0建议版本为撰写本文时最新的主版本,仅作为起点——若目标应用已锁定不同版本,请以应用版本为准。
| 包名 | 建议版本 | 用途 |
|---|---|---|
| | UI框架(对等依赖;复用应用已有的版本) |
| | CDF API客户端(实例、数据模型) |
| | 通过 |
| | WebGL图形渲染引擎 |
| | 节点类型图例使用的图标集 |
安装示例(npm;请适配应用的包管理器):
bash
npm install @cognite/sdk@^10.10.0 @cognite/dune@^2.1.0 reagraph@^4.30.8 lucide-react@^1.14.0CDF Cost & Performance
CDF成本与性能
Graph expansion can issue many CDF requests, especially with reverse relations. For large or unfamiliar data models, be conservative:
- Set to the few properties the app actually needs to traverse.
whitelistedRelationProps - Lower (it is a hard maximum of connections fetched per expansion).
initialConnectionLimit - Lower to bound the in-memory LRU buffer.
maxNodes - Only declare for relations the app must surface; each entry adds an extra query per expansion.
coreReverseQueries
Tuples in are version-aware:
.
coreReverseQueries[space, viewExternalId, viewVersion, propertyName, isList]图形展开可能会发起大量CDF请求,尤其是包含反向关联时。对于大型或不熟悉的数据模型,请谨慎配置:
- 将设置为应用实际需要遍历的少量属性。
whitelistedRelationProps - 降低(这是每次展开时获取连接的硬上限)。
initialConnectionLimit - 降低以限制内存中的LRU缓冲区。
maxNodes - 仅为应用必须展示的关联声明;每个条目会在每次展开时增加额外查询。
coreReverseQueries
coreReverseQueries[space, viewExternalId, viewVersion, propertyName, isList]Advanced Reference
高级参考
For full configuration tables, return-value docs, layouts, theming, and richer examples, read .
code/README.mdFor implementation details, inspect the source files under .
code/如需完整的配置表、返回值文档、布局、主题设置及更丰富的示例,请阅读。
code/README.md如需了解实现细节,请查看下的源文件。
code/Verification Checklist
验证清单
- The app is wrapped in .
<DuneProvider> - All files from were copied into an app-local folder.
skills/graph-viewer/code/ - Imports point to the app-local folder (e.g. ), not
@/features/graph-viewer.@skills/... - ,
@cognite/dune,@cognite/sdk, andreagraphare present inlucide-react.package.json - The container that renders has an explicit height.
<GraphCanvas> - and the app's build both pass.
tsc --noEmit - No references to were introduced.
dune-industrial-components
- 应用已用包裹。
<DuneProvider> - 下的所有文件已复制到应用本地文件夹。
skills/graph-viewer/code/ - 导入指向应用本地文件夹(如),而非
@/features/graph-viewer。@skills/... - 中已包含
package.json、@cognite/dune、@cognite/sdk和reagraph。lucide-react - 渲染的容器具有明确高度。
<GraphCanvas> - 和应用构建均通过。
tsc --noEmit - 未引入任何相关引用。
dune-industrial-components