vue3-network-graph 0.2.3 → 0.2.4
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.en.md +10 -2
- package/README.md +86 -77
- package/dist/index.mjs +785 -750
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -354,6 +354,12 @@ const handleMethods = () => {
|
|
|
354
354
|
| `showEdgeTextBg` | `Boolean` | `false` | Connection text background |
|
|
355
355
|
| `edgeTextBgColor` | `String` | `#0a0e1a` | Connection text background color |
|
|
356
356
|
| `edgeCenterTextFollowLine` | `Boolean` | `true` | Whether the center label rotates along the line: `true` follows the line tangent (current), `false` always stays horizontal |
|
|
357
|
+
| `edgeTextPosition` | `"above" \| "center" \| "below"` | `"center"` | Common default position for all three edge label slots (from / center / to): `above` the line / `center` on the line (default) / `below` the line |
|
|
358
|
+
| `edgeFromTextPosition` | `"above" \| "center" \| "below"` | Follow all | Position override for the start label (`fromText`) |
|
|
359
|
+
| `edgeCenterTextPosition` | `"above" \| "center" \| "below"` | Follow all | Position override for the center label (`centerText`; merged count badge follows this slot) |
|
|
360
|
+
| `edgeToTextPosition` | `"above" \| "center" \| "below"` | Follow all | Position override for the end label (`toText`) |
|
|
361
|
+
| `edgeTextGap` | `Number` | `2` | Gap (px) between the label plate and the line in above / below mode |
|
|
362
|
+
| `nodeLabelPosition` | `"top" \| "center" \| "bottom"` | `"bottom"` | Global default node label position: top / center / bottom; per-node override via `node.labelPosition` |
|
|
357
363
|
| `showNodeHandles` | `Boolean` | `false` | Node handles (four small circles appear at top/bottom/left/right of nodes, auto-connect when dragged to another node) |
|
|
358
364
|
| `showStatusDot` | `Boolean` | `true` | Status dot at top-right corner of each node |
|
|
359
365
|
| `labelGap` | `Number` | `18` | Fixed gap between node box edge and its label (px at 1x zoom) |
|
|
@@ -423,7 +429,7 @@ radialGradient: {
|
|
|
423
429
|
| `borderStyle` | `"full" \| "dashed" \| "none"` | ❌ | `"full"` | Border style: `"full"` solid, `"dashed"` dashed, `"none"` no border |
|
|
424
430
|
| `background` | `String` | ❌ | `"#0f1729"` | Background color |
|
|
425
431
|
| `borderRadius` | `Number` | ❌ | `6` | Corner radius (px) |
|
|
426
|
-
| `labelPosition` | `"top" \| "center" \| "bottom"` | ❌ |
|
|
432
|
+
| `labelPosition` | `"top" \| "center" \| "bottom"` | ❌ | Follow all | Label position (falls back to `config.nodeLabelPosition` when unset) |
|
|
427
433
|
| `zIndex` | `Number` | ❌ | `0` | Z-axis layer index (requires `enableZOrder`) |
|
|
428
434
|
|
|
429
435
|
### Node Types (nodeType)
|
|
@@ -539,7 +545,9 @@ fromText: {
|
|
|
539
545
|
text: "Start Text", // Text content
|
|
540
546
|
rotation: 0, // Additional rotation angle (degrees)
|
|
541
547
|
fontSize: 10, // Font size
|
|
542
|
-
color: "#ffffff"
|
|
548
|
+
color: "#ffffff", // Color
|
|
549
|
+
position: "above" // above the line / center on the line / below the
|
|
550
|
+
// line (highest priority, overrides config)
|
|
543
551
|
}
|
|
544
552
|
```
|
|
545
553
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# vue3-network-graph 使用说明
|
|
2
2
|
|
|
3
3
|
基于 **Vue 3 + SVG** 的轻量级网络拓扑图组件,无第三方图表库依赖。支持节点拖拽、画布无限平移、滚轮缩放、连线流向动画、三种连线模式、同节点对多连线防重叠、连线文字沿线直立等能力。
|
|
4
|
+
欢迎提bug和个人项目需要,我会整理并完善组件供大家免费使用,后续我会提供demo实例。邮箱:YY996618@qq.com
|
|
4
5
|
|
|
5
6
|
---
|
|
6
7
|
|
|
@@ -334,47 +335,53 @@ const handleMethods = () => {
|
|
|
334
335
|
|
|
335
336
|
## 全局配置属性说明
|
|
336
337
|
|
|
337
|
-
| 配置项
|
|
338
|
-
|
|
|
339
|
-
| `selectedBorderColor`
|
|
340
|
-
| `selectedLineColor`
|
|
341
|
-
| `nodeDraggable`
|
|
342
|
-
| `nodeResizable`
|
|
343
|
-
| `enableZoom`
|
|
344
|
-
| `enablePan`
|
|
345
|
-
| `enableMarquee`
|
|
346
|
-
| `maxSelectNodes`
|
|
347
|
-
| `maxSelectEdges`
|
|
348
|
-
| `showGrid`
|
|
349
|
-
| `gridColor`
|
|
350
|
-
| `gridStep`
|
|
351
|
-
| `gridOpacity`
|
|
352
|
-
| `radialGradient`
|
|
353
|
-
| `showCenterPoint`
|
|
354
|
-
| `showEdgeTextBg`
|
|
355
|
-
| `edgeTextBgColor`
|
|
356
|
-
| `edgeCenterTextFollowLine` | `Boolean`
|
|
357
|
-
| `
|
|
358
|
-
| `
|
|
359
|
-
| `
|
|
360
|
-
| `
|
|
361
|
-
| `
|
|
362
|
-
| `
|
|
363
|
-
| `
|
|
364
|
-
| `
|
|
365
|
-
| `
|
|
366
|
-
| `
|
|
367
|
-
| `
|
|
368
|
-
| `
|
|
369
|
-
| `
|
|
370
|
-
| `
|
|
371
|
-
| `
|
|
372
|
-
| `
|
|
373
|
-
| `
|
|
374
|
-
| `
|
|
375
|
-
| `
|
|
376
|
-
| `
|
|
377
|
-
| `
|
|
338
|
+
| 配置项 | 类型 | 默认值 | 说明 |
|
|
339
|
+
| -------------------------- | ----------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
340
|
+
| `selectedBorderColor` | `String` | `#fbbf24` | 选中节点的描边颜色 |
|
|
341
|
+
| `selectedLineColor` | `String` | `#fbbf24` | 选中连线的颜色 |
|
|
342
|
+
| `nodeDraggable` | `Boolean` | `true` | 节点拖拽开关(需 `editable`) |
|
|
343
|
+
| `nodeResizable` | `Boolean` | `true` | 节点尺寸调整开关(需 `editable`) |
|
|
344
|
+
| `enableZoom` | `Boolean` | `true` | 滚轮缩放开关 |
|
|
345
|
+
| `enablePan` | `Boolean` | `true` | 画布拖拽平移开关 |
|
|
346
|
+
| `enableMarquee` | `Boolean` | `true` | Ctrl + 左键框选开关 |
|
|
347
|
+
| `maxSelectNodes` | `Number \| "unlimited"` | 不限制 | 最多选中节点数:`0`(禁止)/ `1` / `2` 或任意非负整数;不设或 `"unlimited"` 不限制 |
|
|
348
|
+
| `maxSelectEdges` | `Number \| "unlimited"` | 不限制 | 最多选中连线数(合并线按整组内全部连线计数) |
|
|
349
|
+
| `showGrid` | `Boolean` | `true` | 网格背景(设 `false` 关闭) |
|
|
350
|
+
| `gridColor` | `String` | `#1a2240` | 网格线颜色 |
|
|
351
|
+
| `gridStep` | `Number` | `40` | 网格间距(1x 缩放下的 px,随缩放联动) |
|
|
352
|
+
| `gridOpacity` | `Number` | `0.5` | 网格叠层透明度(0–1) |
|
|
353
|
+
| `radialGradient` | `Object` | 见说明 | 画布背景径向渐变 |
|
|
354
|
+
| `showCenterPoint` | `Boolean` | `false` | 画布中心十字标记 |
|
|
355
|
+
| `showEdgeTextBg` | `Boolean` | `false` | 连线文字底牌 |
|
|
356
|
+
| `edgeTextBgColor` | `String` | `#0a0e1a` | 连线文字底牌颜色 |
|
|
357
|
+
| `edgeCenterTextFollowLine` | `Boolean` | `true` | 中心文字是否跟随线方向旋转:`true` 随线倾斜(现状),`false` 始终保持水平 |
|
|
358
|
+
| `edgeTextPosition` | `"above" \| "center" \| "below"` | `"center"` | 连线三个文字槽位(起点 / 中心 / 终点)的公共默认位置:`above` 线上面 / `center` 线中心(默认)/ `below` 线下面 |
|
|
359
|
+
| `edgeFromTextPosition` | `"above" \| "center" \| "below"` | 跟随全部 | 起点文字(`fromText`)单独覆盖位置 |
|
|
360
|
+
| `edgeCenterTextPosition` | `"above" \| "center" \| "below"` | 跟随全部 | 中心文字(`centerText`)单独覆盖位置(合并计数徽标跟随此槽位) |
|
|
361
|
+
| `edgeToTextPosition` | `"above" \| "center" \| "below"` | 跟随全部 | 终点文字(`toText`)单独覆盖位置 |
|
|
362
|
+
| `edgeTextGap` | `Number` | `2` | 线上 / 线下模式下文字底板与线的间隙(px) |
|
|
363
|
+
| `nodeLabelPosition` | `"top" \| "center" \| "bottom"` | `"bottom"` | 节点文字全局默认位置:上方 / 中心 / 下方;单节点可用 `node.labelPosition` 覆盖 |
|
|
364
|
+
| `showNodeHandles` | `Boolean` | `false` | 节点手柄(开启后节点上下左右出现四个小圆圈,拖到另一节点松开自动连线) |
|
|
365
|
+
| `showStatusDot` | `Boolean` | `true` | 节点右上角状态圆点开关 |
|
|
366
|
+
| `labelGap` | `Number` | `18` | 节点标签与节点盒边缘的固定间距(1x 缩放下 px) |
|
|
367
|
+
| `watchDataChanges` | `Boolean` | `false` | 组件内数据变动检测(防抖 300ms 后触发 `data-change`) |
|
|
368
|
+
| `fx` | `Boolean` | 自动 | 装饰动效总开关:`false` 全关 / `true` 全开 / 不设 = 自动 |
|
|
369
|
+
| `motionFx` | `Boolean` | 自动 | 连接线动画(流光 + 粒子)单项覆盖 |
|
|
370
|
+
| `glowFx` | `Boolean` | 自动 | 连线发光单项覆盖 |
|
|
371
|
+
| `breatheFx` | `Boolean` | 自动 | 告警呼吸环单项覆盖:`false` 关闭告警动画,`true` 强制开启(忽略规模门控) |
|
|
372
|
+
| `alertStates` | `String[]` | 见说明 | 触发呼吸环的告警态白名单,默认 `["warning","error","master"]`;其余 state 只改配色不动画 |
|
|
373
|
+
| `alertStyle` | `"ring" \| "fill" \| "ripple" \| "blink"` | `"ring"` | 告警动画样式:ring 描边环外扩(error/master 叠错相位外环)/ fill 实心呼吸圈 / ripple 三道水波扩散 / blink 硬闪;单节点可用 `node.alertStyle` 覆盖 |
|
|
374
|
+
| `alertGlow` | `Boolean` | `true` | `fill` 实心呼吸圈的边缘渐变发光(贴边亮环 + 向外柔和衰减);设为 `false` 退回纯实心圈 |
|
|
375
|
+
| `fxMotionMaxEdges` | `Number` | `200` | 流光 + 粒子动画自动关闭的连线数阈值 |
|
|
376
|
+
| `fxGlowMaxEdges` | `Number` | `500` | 连线发光自动关闭的连线数阈值 |
|
|
377
|
+
| `fxAlertMaxNodes` | `Number` | `300` | 告警节点数超过该值时自动关闭呼吸环(按告警节点数计,不再因全图规模被整体关掉) |
|
|
378
|
+
| `fxBreatheMaxNodes` | `Number` | `300` | 旧版呼吸灯节点数阈值(已由 `fxAlertMaxNodes` 取代,保留兼容) |
|
|
379
|
+
| `enableZOrder` | `Boolean` | `false` | **启用 Z 轴层级排序**:启用后节点按 `zIndex` 属性渲染,支持图层操作 API、右键菜单和快捷键 |
|
|
380
|
+
| `enableDeleteKey` | `Boolean` | `true` | Delete / Backspace 删除当前选中(需 `editable`);父级监听 `delete-request` 时只抛事件、不直接删除 |
|
|
381
|
+
| `imageFit` | `"contain" \| "cover"` | `"contain"` | 图片节点填充方式:`contain` 整图完整显示在节点框内(居中留白、不裁剪);`cover` 铺满节点框并裁掉溢出。两者都等比缩放,不会拉伸变形 |
|
|
382
|
+
| `imageNodeBySource` | `Boolean` | `false` | **图片节点全局判定**:`true` 时节点只要带图片地址就按图片节点渲染(忽略 `nodeType`);文本节点、纯边框节点不受影响 |
|
|
383
|
+
| `edgeLayer` | `"split" \| "below"` | `"split"` | 节点与连线的绘制顺序:`split` 把节点拆两层——底板+边框在下、图标/图片/标签在上,连线夹在中间(线穿过节点不再被整块盖住);`below` 为传统的「所有连线在所有节点之下」 |
|
|
384
|
+
| `highlightEdgeOnTop` | `Boolean` | `true` | 选中的连线额外绘制在节点层之上,避免高亮链路被节点底板或图标遮挡(纯装饰层,不参与点击命中) |
|
|
378
385
|
|
|
379
386
|
### radialGradient 配置
|
|
380
387
|
|
|
@@ -402,29 +409,29 @@ radialGradient: {
|
|
|
402
409
|
|
|
403
410
|
## 节点属性说明
|
|
404
411
|
|
|
405
|
-
| 属性 | 类型 | 必填 | 默认值 | 说明
|
|
406
|
-
| --------------- | ------------------------------- | ---- | ----------- |
|
|
407
|
-
| `id` | `String` | ✅ | - | 节点唯一标识
|
|
408
|
-
| `label` | `String \| null` | ❌ | `null` | 节点显示文本(支持 `\n` 换行),纯边框节点和文本节点可设为空
|
|
409
|
-
| `nodeType` | `String` | ❌ | `"server"` | 节点类型(见下方类型列表)
|
|
410
|
-
| `image` | `String` | ❌ | - | 图片地址,也可用别名 `src` / `img` / `imageUrl`(见下方「图片节点」)
|
|
411
|
-
| `state` | `String` | ❌ | `"none"` | 节点状态(见下方状态列表)
|
|
412
|
+
| 属性 | 类型 | 必填 | 默认值 | 说明 |
|
|
413
|
+
| --------------- | ------------------------------- | ---- | ----------- | ---------------------------------------------------------------------------------- |
|
|
414
|
+
| `id` | `String` | ✅ | - | 节点唯一标识 |
|
|
415
|
+
| `label` | `String \| null` | ❌ | `null` | 节点显示文本(支持 `\n` 换行),纯边框节点和文本节点可设为空 |
|
|
416
|
+
| `nodeType` | `String` | ❌ | `"server"` | 节点类型(见下方类型列表) |
|
|
417
|
+
| `image` | `String` | ❌ | - | 图片地址,也可用别名 `src` / `img` / `imageUrl`(见下方「图片节点」) |
|
|
418
|
+
| `state` | `String` | ❌ | `"none"` | 节点状态(见下方状态列表) |
|
|
412
419
|
| `alertStyle` | `String` | ❌ | - | 节点级告警样式覆盖(`ring` / `fill` / `ripple` / `blink`,见 `config.alertStyle`) |
|
|
413
|
-
| `x` | `Number` | ✅ | - | 节点 X 坐标(SVG 坐标系)
|
|
414
|
-
| `y` | `Number` | ✅ | - | 节点 Y 坐标(SVG 坐标系)
|
|
415
|
-
| `width` | `Number` | ❌ | `60` | 节点宽度(纯边框节点必需)
|
|
416
|
-
| `height` | `Number` | ❌ | `60` | 节点高度(纯边框节点必需)
|
|
417
|
-
| `rotation` | `Number` | ❌ | `0` | 节点旋转角度(度)
|
|
418
|
-
| `fontColor` | `String` | ❌ | `"#ffffff"` | 文字颜色
|
|
419
|
-
| `fontSize` | `Number` | ❌ | `11` | 文字大小
|
|
420
|
-
| `fontWeight` | `Number \| String` | ❌ | `500` | 字重(100–900)
|
|
421
|
-
| `borderColor` | `String` | ❌ | `"#94a3b8"` | 边框颜色
|
|
422
|
-
| `borderWidth` | `Number` | ❌ | `0` | 边框宽度(0 为无边框)
|
|
423
|
-
| `borderStyle` | `"full" \| "dashed" \| "none"` | ❌ | `"full"` | 边框样式:`"full"` 实线,`"dashed"` 虚线,`"none"` 无边框
|
|
424
|
-
| `background` | `String` | ❌ | `"#0f1729"` | 背景颜色
|
|
425
|
-
| `borderRadius` | `Number` | ❌ | `6` | 圆角半径(px)
|
|
426
|
-
| `labelPosition` | `"top" \| "center" \| "bottom"` | ❌ |
|
|
427
|
-
| `zIndex` | `Number` | ❌ | `0` | Z 轴层级索引(需启用 `enableZOrder`)
|
|
420
|
+
| `x` | `Number` | ✅ | - | 节点 X 坐标(SVG 坐标系) |
|
|
421
|
+
| `y` | `Number` | ✅ | - | 节点 Y 坐标(SVG 坐标系) |
|
|
422
|
+
| `width` | `Number` | ❌ | `60` | 节点宽度(纯边框节点必需) |
|
|
423
|
+
| `height` | `Number` | ❌ | `60` | 节点高度(纯边框节点必需) |
|
|
424
|
+
| `rotation` | `Number` | ❌ | `0` | 节点旋转角度(度) |
|
|
425
|
+
| `fontColor` | `String` | ❌ | `"#ffffff"` | 文字颜色 |
|
|
426
|
+
| `fontSize` | `Number` | ❌ | `11` | 文字大小 |
|
|
427
|
+
| `fontWeight` | `Number \| String` | ❌ | `500` | 字重(100–900) |
|
|
428
|
+
| `borderColor` | `String` | ❌ | `"#94a3b8"` | 边框颜色 |
|
|
429
|
+
| `borderWidth` | `Number` | ❌ | `0` | 边框宽度(0 为无边框) |
|
|
430
|
+
| `borderStyle` | `"full" \| "dashed" \| "none"` | ❌ | `"full"` | 边框样式:`"full"` 实线,`"dashed"` 虚线,`"none"` 无边框 |
|
|
431
|
+
| `background` | `String` | ❌ | `"#0f1729"` | 背景颜色 |
|
|
432
|
+
| `borderRadius` | `Number` | ❌ | `6` | 圆角半径(px) |
|
|
433
|
+
| `labelPosition` | `"top" \| "center" \| "bottom"` | ❌ | 跟随全局 | 标签位置(未设置时用 `config.nodeLabelPosition`) |
|
|
434
|
+
| `zIndex` | `Number` | ❌ | `0` | Z 轴层级索引(需启用 `enableZOrder`) |
|
|
428
435
|
|
|
429
436
|
### 节点类型(nodeType)
|
|
430
437
|
|
|
@@ -447,10 +454,10 @@ radialGradient: {
|
|
|
447
454
|
|
|
448
455
|
**判定规则**(满足任一即为图片节点):
|
|
449
456
|
|
|
450
|
-
| 条件
|
|
451
|
-
|
|
|
452
|
-
| `nodeType` 为 `"image"` / `"img"` / `"picture"`(大小写不敏感)
|
|
453
|
-
| 没有 `nodeType`,且带图片地址
|
|
457
|
+
| 条件 | 示例 |
|
|
458
|
+
| ---------------------------------------------------------------- | ----------------------------------------- |
|
|
459
|
+
| `nodeType` 为 `"image"` / `"img"` / `"picture"`(大小写不敏感) | `{ nodeType: "image", image: "/a.png" }` |
|
|
460
|
+
| 没有 `nodeType`,且带图片地址 | `{ image: "/a.png" }` |
|
|
454
461
|
| 开启 `config.imageNodeBySource`,且带图片地址(忽略 `nodeType`) | `{ nodeType: "server", image: "/a.png" }` |
|
|
455
462
|
|
|
456
463
|
- 图片地址按 **`image` → `src` → `img` → `imageUrl`** 顺序取第一个有值的字段;必须是 trim 后非空的字符串。
|
|
@@ -459,20 +466,20 @@ radialGradient: {
|
|
|
459
466
|
|
|
460
467
|
**填充方式**:`config.imageFit`
|
|
461
468
|
|
|
462
|
-
| 值
|
|
463
|
-
|
|
|
469
|
+
| 值 | 效果 |
|
|
470
|
+
| ------------------- | --------------------------------------------------------- |
|
|
464
471
|
| `"contain"`(默认) | 整张图完整落在节点框内,居中留白(letterbox),**不裁剪** |
|
|
465
|
-
| `"cover"`
|
|
472
|
+
| `"cover"` | 按最短边铺满节点框,长边超出的部分被裁掉 |
|
|
466
473
|
|
|
467
474
|
**自定义插槽**:`#node-icon` 会收到以下 props,可自行决定画什么——
|
|
468
475
|
|
|
469
|
-
| prop
|
|
470
|
-
|
|
|
471
|
-
| `isImage`
|
|
472
|
-
| `image`
|
|
473
|
-
| `fit`
|
|
476
|
+
| prop | 说明 |
|
|
477
|
+
| ---------------------------- | ------------------------------------------------------------------ |
|
|
478
|
+
| `isImage` | 当前节点是否被判为图片节点 |
|
|
479
|
+
| `image` | 图片地址(可能为空串) |
|
|
480
|
+
| `fit` | `"contain"` / `"cover"` |
|
|
474
481
|
| `imageWidth` / `imageHeight` | 已按图片真实比例算好的绘制尺寸(图片节点才有,衬在节点框中心即可) |
|
|
475
|
-
| `width` / `height`
|
|
482
|
+
| `width` / `height` | 节点框尺寸 |
|
|
476
483
|
|
|
477
484
|
```vue
|
|
478
485
|
<Topology :nodes="nodes" :edges="edges" :config="{ imageFit: 'contain' }">
|
|
@@ -539,7 +546,9 @@ fromText: {
|
|
|
539
546
|
text: "起点文字", // 文字内容
|
|
540
547
|
rotation: 0, // 额外旋转角(度)
|
|
541
548
|
fontSize: 10, // 字号
|
|
542
|
-
color: "#ffffff"
|
|
549
|
+
color: "#ffffff", // 颜色
|
|
550
|
+
position: "above" // 位置:above 线上面 / center 线中心 / below 线下面
|
|
551
|
+
//(优先级最高,覆盖 config 的槽位 / 全局配置)
|
|
543
552
|
}
|
|
544
553
|
```
|
|
545
554
|
|