ICEN UI 知识图谱
Docs ⌘K
Beta · 演进中

知识图谱

`renderGraph`:GraphRAG 实体关系力导向 node-link 图,支持簇着色与节点拖拽。

Preview
图表 chart-graph

悬停看实体 · 点击节点回实体卡数据(detail.datum.meta)· 拖拽节点局部松弛 · 点图例隐藏整簇(边随端点淡化)

html
<div class="icen-chart" id="chart-graph-demo"></div><p class="demo-label" id="chart-graph-log" style="margin-top:8px">悬停看实体 · 点击节点回实体卡数据(detail.datum.meta)· 拖拽节点局部松弛 · 点图例隐藏整簇(边随端点淡化)</p>

特性

layoutGraph 为可单测纯函数。

接口

导出
renderGraphlayoutGraph 共享行为模块,清单含族内导出
事件
icen:chart-legend-toggleicen:chart-legend-visibilityicen:chart-zoom detail 契约见 IcenEventMap;共享行为模块,清单含族内事件
类型
dist/behaviors/charts.d.mts(随 npm 包发布,含全部 JSDoc 约束)

安装

bun add @icen.ai/ui

一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):

js
import '@icen.ai/ui/kit/chart-graph';

也可以用脚手架直接打印引入行:

bash
bunx --bun @icen.ai/ui add chart-graph

Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/chart-graph.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。

用法

js
import { renderGraph, layoutGraph } from '@icen.ai/ui/kit/chart-graph';const h = renderGraph(el, {  type: 'graph',  nodes: [    { id: 'co-1', label: '冰岩科技', cluster: 'company', weight: 9, meta: { desc: '集团母公司' } },    { id: 'pr-1', label: 'ICEN UI', cluster: 'product' },   // weight 缺省用度中心性定尺寸  ],  edges: [{ source: 'co-1', target: 'pr-1', weight: 9 }],   // weight → 线宽 0.6–2.5px  clusterLabels: { company: '公司', product: '产品', person: '人物' },  // directed: true 时边带箭头});h.on('click', (d) => openEntityCard(d.datum));   // { id, label, cluster?, meta? }(meta 原样回传)h.update(nextSpec);                              // 原地重渲(重新布局;确定性:同数据同布局)layoutGraph(nodes, edges, { seed: 8 });          // 纯函数:id → { x, y }(可单测)