react-kggraph 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,13 +5,18 @@
5
5
  ## 特性
6
6
 
7
7
  - 🚀 基于 Cytoscape.js 强大的图可视化能力
8
- - 📊 支持多种布局算法(cose-bilkent、cise、fcose、storm
9
- - 🎨 支持节点、边的自定义样式
10
- - 🔍 支持节点搜索、高亮路径分析
11
- - 📦 支持知识图谱展开、节点详情查看
12
- - 📱 响应式设计,支持缩放、拖拽等交互
13
- - ⚙️ 支持 ActionBar 工具栏配置(位置、按钮列表)
14
- - 🖱️ 支持右键菜单(actionCircle)自定义
8
+ - 📊 支持多种布局算法(cose-bilkent、cise、fcose、cose、grid、circle、breadthfirst、concentric
9
+ - 🎨 支持节点、边的自定义样式,节点/边 Drawer 编辑
10
+ - 🔍 支持节点搜索、框选/点选模式、全选/反选
11
+ - 📦 支持知识图谱展开/收起(concentric 环形动画 + 淡入淡出,空白区域自适应)
12
+ - 📋 支持数据导出(JSON / Excel / PNG / JPG)
13
+ - 📱 响应式设计,支持画布缩放、节点缩放、拖拽等交互
14
+ - ⚙️ 支持 ActionBar 工具栏配置(位置、按钮列表、折叠展开)
15
+ - 🖱️ 支持右键径向菜单(actionCircle)自定义
16
+ - 🗺️ 路径分析:支持多节点间 A* 最短路径计算
17
+ - 🔗 连接分析:BFS 遍历 N 度关联节点
18
+ - 📊 查询统计面板:实体/关系类型分布及筛选
19
+ - 📝 知识卡片:节点详情抽屉展示
15
20
 
16
21
  ## 安装
17
22
 
@@ -110,14 +115,14 @@ const App = () => {
110
115
  knowledgeCardApi={knowledgeCardApi}
111
116
  // ActionBar 配置
112
117
  actionBar={{
113
- position: 'top-left',
118
+ position: 'left',
114
119
  actionList: actionList.filter(item => ['queryStatistics', 'layout'].includes(item.key)),
115
120
  }}
116
121
  // 右键菜单配置
117
122
  actionCircle={[
118
123
  { ids: 'contract', label: '展收实体' },
119
124
  { ids: 'expanded', label: '展收属性' },
120
- { ids: 'nodeInfo', label: '节点信息' },
125
+ { ids: 'nodeInfo', label: '节点样式' },
121
126
  { ids: 'customNew', label: '自定义菜单', onClick: (node) => console.log('自定义', node) },
122
127
  ]}
123
128
  />
@@ -128,98 +133,119 @@ const App = () => {
128
133
 
129
134
  ## Props
130
135
 
131
- | 属性 | 类型 | 必填 | 说明 |
132
- |------|------|------|------|
133
- | data | `GraphData \| any[]` | ❌ | 图谱数据 |
134
- | getAllGraphData | `(params?: any) => void` | ❌ | 获取完整图谱数据的回调函数 |
135
- | searchType | `SearchType` | ❌ | 搜索类型 |
136
- | highPathAnalysis | `string[]` | ❌ | 高亮路径分析的节点ID数组 |
137
- | graphInfo | `GraphInfo` | ❌ | 图谱配置信息 |
138
- | stepNextApi | `(params: any) => Promise<any>` | ❌ | 下一步API(用于知识图谱展开) |
139
- | knowledgeCardApi | `(params: any) => Promise<any>` | ❌ | 知识卡片API |
140
- | colors | `GraphColors` | ❌ | 颜色配置 |
141
- | actionBar | `ActionBarConfig` | ❌ | ActionBar 工具栏配置 |
142
- | actionCircle | `ActionCircleItem[]` | ❌ | 右键菜单配置 |
136
+ | 属性 | 类型 | 必填 | 默认值 | 说明 |
137
+ |------|------|------|--------|------|
138
+ | data | `GraphData \| any[]` | ❌ | — | 图谱数据 |
139
+ | getAllGraphData | `(params?: any) => Promise<any>` | ❌ | | 获取完整图谱数据的回调 |
140
+ | searchType | `SearchType` | ❌ | — | 搜索类型 |
141
+ | highPathAnalysis | `string[]` | ❌ | `[]` | 高亮路径分析的节点ID数组 |
142
+ | graphInfo | `GraphInfo` | ❌ | | 图谱配置信息(kgId + searchNodes) |
143
+ | stepNextApi | `(params: any) => Promise<any>` | ❌ | — | 节点展开/收起 API |
144
+ | knowledgeCardApi | `(params: any) => Promise<any>` | ❌ | — | 知识卡片 API |
145
+ | colors | `GraphColors` | ❌ | | 颜色配置(与默认值合并) |
146
+ | actionBar | `boolean \| ActionBarConfig` | ❌ | | 工具栏配置(true=默认,false=隐藏) |
147
+ | actionCircle | `ActionCircleItem[]` | ❌ | | 右键菜单配置(覆盖/追加默认项) |
148
+ | queryStatisticsConfig | `boolean \| {label, key}[]` | ❌ | `[{label:'实体',key:'entity'},{label:'关系',key:'relation'}]` | 统计面板配置 |
149
+ | noDataDesc | `string` | ❌ | `'暂无数据'` | 无数据时的描述文字 |
150
+ | className | `string` | ❌ | — | 外层容器自定义 class |
151
+
152
+ ### SearchType
153
+
154
+ ```typescript
155
+ enum SearchType {
156
+ KNOWLEDGE = 'knowledge', // 知识图谱
157
+ RELATION = 'relation', // 关系图谱
158
+ ATTRIBUTE = 'attribute', // 属性图谱
159
+ TIMELINE = 'timeline', // 时间线图谱
160
+ }
161
+ ```
143
162
 
144
163
  ## ActionBar 配置
145
164
 
146
- ActionBar 工具栏支持自定义位置和按钮列表。
165
+ ActionBar 工具栏支持自定义位置、按钮列表和折叠展开。
147
166
 
148
167
  ### ActionBarConfig
149
168
 
150
169
  ```typescript
151
170
  interface ActionBarConfig {
152
- /** 位置配置 */
153
- position?: ActionBarPosition;
154
- /** 按钮列表配置 */
171
+ /** 位置预设 */
172
+ position?: 'top' | 'bottom' | 'left' | 'right';
173
+ /** 位置微调偏移 */
174
+ positionDetail?: {
175
+ top?: string | number;
176
+ right?: string | number;
177
+ bottom?: string | number;
178
+ left?: string | number;
179
+ };
180
+ /** 按钮列表 */
155
181
  actionList?: ActionBarItem[];
182
+ /** 是否默认展开 */
183
+ isExpand?: boolean;
156
184
  }
157
-
158
- type ActionBarPosition = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | {
159
- top?: string | number;
160
- right?: string | number;
161
- bottom?: string | number;
162
- left?: string | number;
163
- };
164
185
  ```
165
186
 
166
187
  ### ActionBarItem
167
188
 
168
189
  ```typescript
169
190
  interface ActionBarItem {
170
- key: string; // 唯一标识
171
- title: string; // 显示文本
172
- icon?: React.ReactNode[]; // 图标(支持多个 antd icon)
173
- onClick?: (params?: any) => void; // 点击事件
191
+ key: string; // 唯一标识
192
+ title: string; // 显示文本
193
+ icon?: React.ReactNode[]; // 图标(支持多个 antd icon)
194
+ onClick?: (params?: any) => void; // 点击事件(覆盖默认行为)
174
195
  }
175
196
  ```
176
197
 
177
198
  ### 默认按钮列表
178
199
 
179
- 组件内置以下默认按钮:
180
-
181
200
  | key | title | 说明 |
182
201
  |-----|-------|------|
183
- | queryStatistics | 查询统计 | 统计面板 |
184
- | layout | 布局 | 布局切换 |
185
- | graphDisplaySettings | 图显示设置 | 图形显示配置 |
186
- | analysis | 分析 | 分析功能 |
187
- | select | 选择 | 选择功能 |
188
- | downloadData | 下载数据 | 导出数据 |
189
- | hideAttributes | 隐藏属性 | 隐藏节点属性 |
190
- | textPosition | 文字位置 | 文字位置调整 |
191
- | clearCanvas | 清空画布 | 清空画布 |
192
- | nodeZoom | 节点缩放 | 节点缩放控制 |
193
- | canvasZoom | 画布缩放 | 画布缩放控制 |
202
+ | queryStatistics | 查询统计 | 实体/关系统计面板,支持类型筛选 |
203
+ | layout | 布局 | 8 种布局切换(下拉菜单) |
204
+ | graphDisplaySettings | 图设置 | 节点/连线样式设置 Drawer |
205
+ | analysis | 分析 | 查询节点 / 连接分析 / 路径分析 |
206
+ | select | 选择 | 全选 / 反选 / 点选模式 / 框选模式 |
207
+ | downloadData | 下载数据 | JSON / Excel / JPG / PNG 导出 |
208
+ | hideAttributes | 隐藏属性 | 切换 typed-literal 节点显隐 |
209
+ | textPosition | 文字位置 | 居中 / 上 / 下 / 左 / 右 |
210
+ | clearCanvas | 清空画布 | 清除所有元素 |
211
+ | nodeZoom | 节点缩放 | 放大/缩小节点(0.1x - 5x) |
212
+ | canvasZoom | 画布缩放 | 放大/缩小画布(0.1x - 3x) |
213
+ | tablelist | 查看列表 | 节点/边数据表格列表 |
194
214
 
195
215
  ### ActionBar 示例
196
216
 
197
217
  ```tsx
198
- // 方式1:使用预定义 actionList
218
+ // 方式1:使用预定义 actionList 筛选
199
219
  import { actionList } from 'react-kggraph';
200
- import { MinusCircleOutlined } from '@ant-design/icons';
201
220
 
202
221
  <CytoscapeReact
203
222
  actionBar={{
204
- position: 'top-left',
205
- actionList: actionList.filter(item => ['queryStatistics', 'layout'].includes(item.key)),
223
+ position: 'left',
224
+ isExpand: true,
225
+ actionList: actionList.filter(item => ['queryStatistics', 'layout', 'analysis'].includes(item.key)),
206
226
  }}
207
227
  />
208
228
 
209
229
  // 方式2:自定义按钮
230
+ import { MinusCircleOutlined } from '@ant-design/icons';
231
+
210
232
  <CytoscapeReact
211
233
  actionBar={{
212
- position: 'bottom-right',
234
+ position: 'right',
235
+ positionDetail: { top: '20px' },
213
236
  actionList: [
214
- { key: 'customBtn', title: '自定义按钮', icon: [<MinusCircleOutlined key="icon" />], onClick: () => console.log('点击') },
237
+ { key: 'customBtn', title: '自定义', icon: [<MinusCircleOutlined key="icon" />], onClick: () => console.log('点击') },
215
238
  ],
216
239
  }}
217
240
  />
241
+
242
+ // 方式3:隐藏 ActionBar
243
+ <CytoscapeReact data={data} actionBar={false} />
218
244
  ```
219
245
 
220
246
  ## 右键菜单配置(actionCircle)
221
247
 
222
- 右键菜单支持过滤、追加自定义菜单项。
248
+ 右键径向菜单,传入的项会与默认项按 ids 合并(匹配则覆盖 onClick,不存在则追加)。
223
249
 
224
250
  ### ActionCircleItem
225
251
 
@@ -227,7 +253,7 @@ import { MinusCircleOutlined } from '@ant-design/icons';
227
253
  interface ActionCircleItem {
228
254
  ids: string; // 唯一标识
229
255
  label: string; // 显示文本
230
- onClick?: (node: any) => void; // 点击事件回调
256
+ onClick?: (node: any) => void; // 点击事件(覆盖默认行为)
231
257
  }
232
258
  ```
233
259
 
@@ -235,12 +261,12 @@ interface ActionCircleItem {
235
261
 
236
262
  | ids | label | 说明 |
237
263
  |-----|-------|------|
238
- | contract | 展收实体 | 收缩实体节点 |
239
- | expanded | 展收属性 | 展开节点属性 |
240
- | nodeInfo | 节点信息 | 查看节点详情 |
241
- | knowledgeCard | 知识卡片 | 查看知识卡片 |
242
- | selRelate | 选中关联 | 高亮关联节点 |
243
- | pathAnalysis | 路径分析 | 路径分析功能 |
264
+ | contract | 展收实体 | 展开/收起 URI 类型关联节点(调用 stepNextApi) |
265
+ | expanded | 展收属性 | 展开/收起 typed-literal 类型属性节点(调用 stepNextApi) |
266
+ | nodeInfo | 节点样式 | 打开节点样式编辑 Drawer(名称/形状/大小/边框/字体) |
267
+ | knowledgeCard | 知识卡片 | 调用 knowledgeCardApi 打开知识卡片 Drawer |
268
+ | selRelate | 选中关联 | 高亮直接关联的节点和边 |
269
+ | pathAnalysis | 路径分析 | 设置路径起点,打开路径分析面板 |
244
270
 
245
271
  ### actionCircle 示例
246
272
 
@@ -250,14 +276,14 @@ interface ActionCircleItem {
250
276
  actionCircle={[
251
277
  { ids: 'contract', label: '展收实体' },
252
278
  { ids: 'expanded', label: '展收属性' },
253
- { ids: 'nodeInfo', label: '节点信息' },
279
+ { ids: 'nodeInfo', label: '节点样式' },
254
280
  ]}
255
281
  />
256
282
 
257
- // 方式2:覆盖默认 action
283
+ // 方式2:覆盖默认 onClick
258
284
  <CytoscapeReact
259
285
  actionCircle={[
260
- { ids: 'nodeInfo', label: '节点信息', onClick: (node) => console.log('自定义', node) },
286
+ { ids: 'nodeInfo', label: '节点信息', onClick: (node) => console.log('自定义处理', node) },
261
287
  ]}
262
288
  />
263
289
 
@@ -265,7 +291,7 @@ interface ActionCircleItem {
265
291
  <CytoscapeReact
266
292
  actionCircle={[
267
293
  { ids: 'contract', label: '展收实体' },
268
- { ids: 'customNew', label: '自定义菜单', onClick: (node) => console.log('新增功能', node) },
294
+ { ids: 'customNew', label: '自定义菜单', onClick: (node) => alert(node.id()) },
269
295
  ]}
270
296
  />
271
297
  ```
@@ -305,39 +331,26 @@ interface GraphEdge {
305
331
 
306
332
  ```typescript
307
333
  interface GraphInfo {
308
- kgId: number | string;
309
- searchNodes?: string[];
334
+ kgId: number | string; // 图谱 ID(展开/卡片 API 必需)
335
+ searchNodes?: string[]; // 搜索节点名,用于左右固定布局
310
336
  }
311
337
  ```
312
338
 
313
339
  ### GraphColors(颜色配置)
314
340
 
315
- ```typescript
316
- interface GraphColors {
317
- /** 节点标签文字颜色,默认 #000 */
318
- nodeLabelColor?: string;
319
- /** 节点标签文字大小,默认 18 */
320
- nodeLabelFontSize?: number;
321
- /** 边标签文字颜色,默认 #666 */
322
- edgeLabelColor?: string;
323
- /** 边标签文字大小,默认 18 */
324
- edgeLabelFontSize?: number;
325
- /** URI类型节点背景色,默认 #f7de63 */
326
- uriNodeColor?: string;
327
- /** 普通节点背景色,默认 #1890FF */
328
- normalNodeColor?: string;
329
- /** 节点边框悬停颜色,默认 #0d6ac2 */
330
- nodeBorderHoverColor?: string;
331
- /** 边默认颜色,默认 #a29e9e */
332
- edgeDefaultColor?: string;
333
- /** 边悬停颜色,默认 #1890ff */
334
- edgeHoverColor?: string;
335
- /** 路径高亮颜色,默认 #145AFD */
336
- pathHighlightColor?: string;
337
- /** 路径节点颜色,默认 #145AFD */
338
- pathNodeColor?: string;
339
- }
340
- ```
341
+ | 属性 | 类型 | 默认值 | 说明 |
342
+ |------|------|--------|------|
343
+ | nodeLabelColor | `string` | `#000` | 节点标签文字颜色 |
344
+ | nodeLabelFontSize | `number` | `16` | 节点标签字体大小 |
345
+ | edgeLabelColor | `string` | `#666` | 边标签文字颜色 |
346
+ | edgeLabelFontSize | `number` | `16` | 边标签字体大小 |
347
+ | uriNodeColor | `string` | `#f7de63` | URI 类型节点背景色 |
348
+ | normalNodeColor | `string` | `#1890FF` | 普通节点背景色 |
349
+ | nodeBorderHoverColor | `string` | `#0d6ac2` | 节点边框悬停颜色 |
350
+ | edgeDefaultColor | `string` | `#a29e9e` | 边默认颜色 |
351
+ | edgeHoverColor | `string` | `#145AFD` | 边悬停颜色 |
352
+ | pathHighlightColor | `string` | `#145AFD` | 路径高亮颜色 |
353
+ | pathNodeColor | `string` | `#145AFD` | 路径节点颜色 |
341
354
 
342
355
  ### 颜色配置示例
343
356
 
@@ -346,6 +359,7 @@ interface GraphColors {
346
359
  data={data}
347
360
  colors={{
348
361
  nodeLabelColor: '#333',
362
+ nodeLabelFontSize: 18,
349
363
  edgeLabelColor: '#999',
350
364
  normalNodeColor: '#52c41a',
351
365
  uriNodeColor: '#faad14',
@@ -357,14 +371,31 @@ interface GraphColors {
357
371
 
358
372
  ## 图谱布局
359
373
 
360
- 组件支持多种布局算法:
374
+ 组件支持 8 种布局算法,可通过 ActionBar 布局按钮切换:
375
+
376
+ | 布局名称 | 说明 | 适用场景 |
377
+ |---------|------|---------|
378
+ | cose-bilkent | 力导向布局(默认) | 通用,适合大型图 |
379
+ | fcose | 快速力导向布局 | 平衡速度与视觉效果 |
380
+ | cose | 力导向布局 | 中大型图 |
381
+ | cise | 圆形弹簧嵌入布局 | 聚类分组图 |
382
+ | grid | 网格布局 | 规整排列 |
383
+ | circle | 圆环布局 | 环状结构 |
384
+ | breadthfirst | 层级布局 | 树形/层级结构 |
385
+ | concentric | 同心圆布局 | 辐射状关系 |
386
+
387
+ > 节点展开时内部使用 concentric 环形动画布局,子节点围绕当前节点分布,并自动寻找画布空白区域避免重叠。
388
+
389
+ ## 数据导出
390
+
391
+ 支持 4 种格式导出:
361
392
 
362
- | 布局名称 | 说明 |
363
- |---------|------|
364
- | cose-bilkent | 力导向布局(默认) |
365
- | cise | 聚类布局 |
366
- | fcose | 快速力导向布局 |
367
- | storm | 风暴布局 |
393
+ | 格式 | 说明 |
394
+ |------|------|
395
+ | JSON | 完整图谱数据导出 |
396
+ | Excel | 节点/边数据表格导出 |
397
+ | PNG | 画布截图(白色背景) |
398
+ | JPG | 画布截图 |
368
399
 
369
400
  ## License
370
401