vue3-network-graph 0.1.8 → 0.2.1

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 CHANGED
@@ -35,8 +35,10 @@ A lightweight network topology component implemented with pure SVG, providing th
35
35
  - **Smart Multi-line Handling**: Multiple connections between the same pair of nodes automatically prevent overlap, staying parallel in any mode
36
36
  - **Upright Connection Text**: `fromText` / `centerText` / `toText` rotate along the path tangentially, automatically flipping when exceeding ±90° to maintain readability
37
37
  - **Rich Node Types**: 8 icon nodes + text nodes + border-only nodes
38
+ - **Image Nodes**: photo / avatar / bitmap nodes, fitted at their real aspect ratio (fully contained or cover-cropped, never stretched)
38
39
  - **2D/3D Views**: Supports both 2D plane and 2.5D card styles
39
40
  - **Flow Animations**: Dashed流光 + particle effects, with per-connection animation control
41
+ - **Edges never get swallowed**: nodes are painted in two passes (plate below, icon / label above), so a line crossing a node — or two overlapping nodes — stays visible; the selected path is promoted to the very top
40
42
 
41
43
  ### Interaction Capabilities
42
44
 
@@ -363,6 +365,11 @@ const handleMethods = () => {
363
365
  | `fxGlowMaxEdges` | `Number` | `500` | Edge count above which edge glow auto-disables |
364
366
  | `fxBreatheMaxNodes` | `Number` | `300` | Node count above which breathing rings auto-disable |
365
367
  | `enableZOrder` | `Boolean` | `false` | **Enable Z-axis layer sorting**: After enabling, nodes render according to `zIndex` property, supporting layer operation API, right-click menu and keyboard shortcuts |
368
+ | `enableDeleteKey` | `Boolean` | `true` | Delete / Backspace removes the current selection (requires `editable`); when the parent listens to `delete-request` the component only emits the event |
369
+ | `imageFit` | `"contain" \| "cover"` | `"contain"` | How image nodes fill their box: `contain` keeps the whole picture inside the box (centred, letterboxed, never cropped); `cover` fills the box and crops the overflow. Both scale uniformly — the picture is never stretched |
370
+ | `imageNodeBySource` | `Boolean` | `false` | **Global image-node rule**: when `true`, any node carrying a picture source is rendered as an image node (its `nodeType` is ignored); text and border-only nodes are unaffected |
371
+ | `edgeLayer` | `"split" \| "below"` | `"split"` | Paint order of nodes vs edges: `split` paints each node in two passes — plate + border below, icon / image / label above, with edges in between (a line crossing a node stays visible); `below` is the classic "all edges under all nodes" |
372
+ | `highlightEdgeOnTop` | `Boolean` | `true` | Selected edges are re-painted above the node layer so the highlighted path is never hidden by a node plate or icon (decoration only — it never captures clicks) |
366
373
 
367
374
  ### radialGradient Configuration
368
375
 
@@ -395,6 +402,7 @@ radialGradient: {
395
402
  | `id` | `String` | ✅ | - | Unique node identifier |
396
403
  | `label` | `String \| null` | ❌ | `null` | Node display text (supports `\n` newline), border-only and text nodes can be empty |
397
404
  | `nodeType` | `String` | ❌ | `"server"` | Node type (see types list below) |
405
+ | `image` | `String` | ❌ | - | Picture URL; aliases `src` / `img` / `imageUrl` (see "Image Nodes" below) |
398
406
  | `state` | `String` | ❌ | `"none"` | Node status (see status list below) |
399
407
  | `x` | `Number` | ✅ | - | Node X coordinate (SVG coordinate system) |
400
408
  | `y` | `Number` | ✅ | - | Node Y coordinate (SVG coordinate system) |
@@ -406,7 +414,7 @@ radialGradient: {
406
414
  | `fontWeight` | `Number \| String` | ❌ | `500` | Font weight (100–900) |
407
415
  | `borderColor` | `String` | ❌ | `"#94a3b8"` | Border color |
408
416
  | `borderWidth` | `Number` | ❌ | `0` | Border width (0 means no border) |
409
- | `borderStyle` | `"dashed" \| ""` | ❌ | `""` | Border style: `"dashed"` dashed, `""` solid |
417
+ | `borderStyle` | `"full" \| "dashed" \| "none"` | ❌ | `"full"` | Border style: `"full"` solid, `"dashed"` dashed, `"none"` no border |
410
418
  | `background` | `String` | ❌ | `"#0f1729"` | Background color |
411
419
  | `borderRadius` | `Number` | ❌ | `6` | Corner radius (px) |
412
420
  | `labelPosition` | `"top" \| "center" \| "bottom"` | ❌ | `"bottom"` | Label position |
@@ -427,6 +435,54 @@ radialGradient: {
427
435
  | `"text"` | Text lines | Pure text node |
428
436
  | `"border-only"` | Hollow rectangle | Border-only node (only border outline displayed) |
429
437
 
438
+ ### Image Nodes
439
+
440
+ A node can be rendered with a picture (photo / avatar / bitmap icon). The component always scales it uniformly — it is never stretched.
441
+
442
+ **Detection rules** (any one makes it an image node):
443
+
444
+ | Condition | Example |
445
+ | --------- | ------- |
446
+ | `nodeType` is `"image"` / `"img"` / `"picture"` (case-insensitive) | `{ nodeType: "image", image: "/a.png" }` |
447
+ | No `nodeType` at all, and a picture source is present | `{ image: "/a.png" }` |
448
+ | `config.imageNodeBySource` is on and a picture source is present (`nodeType` ignored) | `{ nodeType: "server", image: "/a.png" }` |
449
+
450
+ - The source is taken from the first non-empty field of **`image` → `src` → `img` → `imageUrl`**; it must be a non-empty (trimmed) string.
451
+ - Text (`"text"`) and border-only (`"border-only"`) nodes always keep their own rendering.
452
+ - A node with a `nodeType` is **not** an image node by default (its icon follows `nodeType`). For a fully photo-based graph, switch `imageNodeBySource: true`.
453
+
454
+ **Filling**: `config.imageFit`
455
+
456
+ | Value | Effect |
457
+ | ----- | ------ |
458
+ | `"contain"` (default) | The whole picture fits inside the node box, centred and letterboxed — never cropped |
459
+ | `"cover"` | Fills the box along its shortest edge; the overflow on the long edge is cropped |
460
+
461
+ **Slot props**: `#node-icon` receives
462
+
463
+ | prop | Description |
464
+ | ---- | ----------- |
465
+ | `isImage` | Whether this node is treated as an image node |
466
+ | `image` | Picture source (may be an empty string) |
467
+ | `fit` | `"contain"` / `"cover"` |
468
+ | `imageWidth` / `imageHeight` | Aspect-correct draw size for the picture (centre it on the node box) |
469
+ | `width` / `height` | Node box size |
470
+
471
+ ```vue
472
+ <Topology :nodes="nodes" :edges="edges" :config="{ imageFit: 'contain' }">
473
+ <template #node-icon="{ isImage, image, imageWidth, imageHeight }">
474
+ <image
475
+ v-if="isImage"
476
+ :href="image"
477
+ :x="-imageWidth / 2"
478
+ :y="-imageHeight / 2"
479
+ :width="imageWidth"
480
+ :height="imageHeight"
481
+ />
482
+ </template>
483
+ </Topology>
484
+ ```
485
+
430
486
  ### Node Status (state)
431
487
 
432
488
  | Status | Color | Description |
@@ -619,6 +675,8 @@ const methods = () => {
619
675
  ### Interaction Priority Notes
620
676
 
621
677
  - **Node and connection overlap**: Click/drag acts on **node**; connections normally clickable where not occluded—nodes always selectable and draggable in dense graphics
678
+ - **Border-only node exception**: such a node is an empty frame — only its **border stroke** and **label text** are clickable, so the empty interior passes clicks through to the connections / canvas underneath (a line running through the frame stays selectable). Drag it by its border or label
679
+ - **The promoted-edge layer never captures clicks**: `highlightEdgeOnTop` re-paints selected edges above the nodes for visual clarity only; it does not steal clicks from nodes or anything else
622
680
  - **Click vs drag distinction**: Left-click on blank distinguishes by small threshold (pan 4px / box select 3px / node drag 3px): below threshold treated as click (clear or toggle selection), above threshold enters drag mode
623
681
 
624
682
  ---
@@ -631,6 +689,18 @@ const methods = () => {
631
689
 
632
690
  When loading a complete new dataset, first update your `nodes` / `edges`, then call `setData()` to clean up component internal residual state.
633
691
 
692
+ ### Node / Edge Paint Order
693
+
694
+ With the default `config.edgeLayer: "split"` the paint order is:
695
+
696
+ ```
697
+ group boxes → node plate (background + border) → edges (base / glow / particles / text) → node content (icon / image / label / status dot)
698
+ ```
699
+
700
+ An edge crossing a node — or a node overlapping another node — therefore keeps running **across the node plate**, and is only partly covered by the icon itself instead of disappearing. Set `edgeLayer: "below"` for the classic "all edges under all nodes" order.
701
+
702
+ With `config.highlightEdgeOnTop` (default `true`) selected edges are additionally painted above the node content, so the path under inspection is never hidden.
703
+
634
704
  ### TypeScript Support
635
705
 
636
706
  ```typescript
package/README.md CHANGED
@@ -35,8 +35,10 @@
35
35
  - **智能多线处理**:同一对节点的多条连线自动防重叠,任何模式下都保持平行
36
36
  - **连线文字直立**:`fromText` / `centerText` / `toText` 沿路径切向旋转,超过±90° 自动翻转保持可读
37
37
  - **丰富的节点类型**:8 种图标节点 + 文本节点 + 纯边框节点
38
+ - **图片节点**:照片 / 头像 / 位图节点,按真实比例等比适配(整图完整显示或铺满裁剪,永不拉伸)
38
39
  - **2D/3D 视图**:支持 2D 平面和 2.5D 卡片风格
39
40
  - **流向动画**:虚线流光 + 粒子效果,可单独控制每条连线的动画开关
41
+ - **连线不被节点吃掉**:节点分层绘制(底板在下、图标/标签在上),连线穿过节点或节点重叠时依然连续可见;选中链路自动提升到最上层
40
42
 
41
43
  ### 交互能力
42
44
 
@@ -363,6 +365,11 @@ const handleMethods = () => {
363
365
  | `fxGlowMaxEdges` | `Number` | `500` | 连线发光自动关闭的连线数阈值 |
364
366
  | `fxBreatheMaxNodes` | `Number` | `300` | 呼吸灯自动关闭的节点数阈值 |
365
367
  | `enableZOrder` | `Boolean` | `false` | **启用 Z 轴层级排序**:启用后节点按 `zIndex` 属性渲染,支持图层操作 API、右键菜单和快捷键 |
368
+ | `enableDeleteKey` | `Boolean` | `true` | Delete / Backspace 删除当前选中(需 `editable`);父级监听 `delete-request` 时只抛事件、不直接删除 |
369
+ | `imageFit` | `"contain" \| "cover"` | `"contain"` | 图片节点填充方式:`contain` 整图完整显示在节点框内(居中留白、不裁剪);`cover` 铺满节点框并裁掉溢出。两者都等比缩放,不会拉伸变形 |
370
+ | `imageNodeBySource` | `Boolean` | `false` | **图片节点全局判定**:`true` 时节点只要带图片地址就按图片节点渲染(忽略 `nodeType`);文本节点、纯边框节点不受影响 |
371
+ | `edgeLayer` | `"split" \| "below"` | `"split"` | 节点与连线的绘制顺序:`split` 把节点拆两层——底板+边框在下、图标/图片/标签在上,连线夹在中间(线穿过节点不再被整块盖住);`below` 为传统的「所有连线在所有节点之下」 |
372
+ | `highlightEdgeOnTop` | `Boolean` | `true` | 选中的连线额外绘制在节点层之上,避免高亮链路被节点底板或图标遮挡(纯装饰层,不参与点击命中) |
366
373
 
367
374
  ### radialGradient 配置
368
375
 
@@ -395,6 +402,7 @@ radialGradient: {
395
402
  | `id` | `String` | ✅ | - | 节点唯一标识 |
396
403
  | `label` | `String \| null` | ❌ | `null` | 节点显示文本(支持 `\n` 换行),纯边框节点和文本节点可设为空 |
397
404
  | `nodeType` | `String` | ❌ | `"server"` | 节点类型(见下方类型列表) |
405
+ | `image` | `String` | ❌ | - | 图片地址,也可用别名 `src` / `img` / `imageUrl`(见下方「图片节点」) |
398
406
  | `state` | `String` | ❌ | `"none"` | 节点状态(见下方状态列表) |
399
407
  | `x` | `Number` | ✅ | - | 节点 X 坐标(SVG 坐标系) |
400
408
  | `y` | `Number` | ✅ | - | 节点 Y 坐标(SVG 坐标系) |
@@ -427,6 +435,54 @@ radialGradient: {
427
435
  | `"text"` | 文本行 | 纯文本节点 |
428
436
  | `"border-only"` | 空心矩形 | 纯边框节点(仅显示边框轮廓) |
429
437
 
438
+ ### 图片节点
439
+
440
+ 节点可以用图片(照片 / 头像 / 位图图标)渲染,组件会**等比缩放**它,不会出现拉伸变形。
441
+
442
+ **判定规则**(满足任一即为图片节点):
443
+
444
+ | 条件 | 示例 |
445
+ | ---- | ---- |
446
+ | `nodeType` 为 `"image"` / `"img"` / `"picture"`(大小写不敏感) | `{ nodeType: "image", image: "/a.png" }` |
447
+ | 没有 `nodeType`,且带图片地址 | `{ image: "/a.png" }` |
448
+ | 开启 `config.imageNodeBySource`,且带图片地址(忽略 `nodeType`) | `{ nodeType: "server", image: "/a.png" }` |
449
+
450
+ - 图片地址按 **`image` → `src` → `img` → `imageUrl`** 顺序取第一个有值的字段;必须是 trim 后非空的字符串。
451
+ - 文本节点(`nodeType: "text"`)与纯边框节点(`"border-only"`)始终按各自类型渲染,不会被转成图片。
452
+ - 带 `nodeType` 的节点**默认不会**变成图片节点(图标按 `nodeType` 渲染);整个图都是照片时,用 `imageNodeBySource: true` 一次性放开。
453
+
454
+ **填充方式**:`config.imageFit`
455
+
456
+ | 值 | 效果 |
457
+ | -- | ---- |
458
+ | `"contain"`(默认) | 整张图完整落在节点框内,居中留白(letterbox),**不裁剪** |
459
+ | `"cover"` | 按最短边铺满节点框,长边超出的部分被裁掉 |
460
+
461
+ **自定义插槽**:`#node-icon` 会收到以下 props,可自行决定画什么——
462
+
463
+ | prop | 说明 |
464
+ | ---- | ---- |
465
+ | `isImage` | 当前节点是否被判为图片节点 |
466
+ | `image` | 图片地址(可能为空串) |
467
+ | `fit` | `"contain"` / `"cover"` |
468
+ | `imageWidth` / `imageHeight` | 已按图片真实比例算好的绘制尺寸(图片节点才有,衬在节点框中心即可) |
469
+ | `width` / `height` | 节点框尺寸 |
470
+
471
+ ```vue
472
+ <Topology :nodes="nodes" :edges="edges" :config="{ imageFit: 'contain' }">
473
+ <template #node-icon="{ isImage, image, imageWidth, imageHeight }">
474
+ <image
475
+ v-if="isImage"
476
+ :href="image"
477
+ :x="-imageWidth / 2"
478
+ :y="-imageHeight / 2"
479
+ :width="imageWidth"
480
+ :height="imageHeight"
481
+ />
482
+ </template>
483
+ </Topology>
484
+ ```
485
+
430
486
  ### 节点状态(state)
431
487
 
432
488
  | 状态 | 颜色 | 说明 |
@@ -619,6 +675,8 @@ const methods = () => {
619
675
  ### 交互优先级说明
620
676
 
621
677
  - **节点与连线重叠处**:点击/拖动作用于**节点**;连线在未被遮挡处正常点击——密集图形下节点始终可选中、可拖动
678
+ - **纯边框节点例外**:这类节点内部是空的,只有**框线**和**标签文字**响应点击(内部空白会让位给下面的连线与画布)——所以从框中穿过的连线依然可以单击选中;拖动纯边框节点请按住框线或标签
679
+ - **选中连线的提升层不参与命中**:`highlightEdgeOnTop` 把选中线画在节点之上纯属视觉,不会抢走节点或其它元素的点击
622
680
  - **点击与拖动区分**:左键在空白处的「点击」与「拖动」按小阈值区分(平移 4px / 框选 3px / 节点拖动 3px):小于阈值仍视为点击(清空或切换选中),超过阈值才进入拖动
623
681
 
624
682
  ---
@@ -631,6 +689,18 @@ const methods = () => {
631
689
 
632
690
  加载一整套新数据时,先更新你的 `nodes` / `edges`,再调用 `setData()` 清理组件内残留状态。
633
691
 
692
+ ### 连线与节点的图层顺序
693
+
694
+ 默认 `config.edgeLayer: "split"`,绘制顺序为:
695
+
696
+ ```
697
+ 分组框 → 节点底板(背景 + 边框) → 连线(基色/光效/粒子/文字) → 节点内容(图标/图片/标签/状态点)
698
+ ```
699
+
700
+ 这样连线穿过节点——或节点互相重叠时——会**压在节点底板上继续可见**,只被图标本体局部遮挡,不会整段消失。若需要传统的「所有连线都在所有节点之下」,设 `edgeLayer: "below"`。
701
+
702
+ 配合 `config.highlightEdgeOnTop`(默认 `true`),被选中的连线还会在节点内容之上再画一遍,保证正在查看的链路永远不会被节点挡住。
703
+
634
704
  ### TypeScript 支持
635
705
 
636
706
  ```typescript
package/dist/index.d.ts CHANGED
@@ -44,16 +44,41 @@ export interface TopologyNode {
44
44
 
45
45
  export type TopologyEdgeLabel =
46
46
  | string
47
- | { text?: string; rotation?: number; fontSize?: number; color?: string };
47
+ | {
48
+ text?: string;
49
+ rotation?: number;
50
+ fontSize?: number;
51
+ color?: string;
52
+ /** Show the background plate for this label (overrides config.showEdgeTextBg) */
53
+ showBg?: boolean;
54
+ /** Background plate color (overrides config.edgeTextBgColor) */
55
+ bgColor?: string;
56
+ /** Background plate opacity 0-1 (overrides config.edgeTextBgOpacity) */
57
+ bgOpacity?: number;
58
+ /** Border style of the plate: solid (default) / dashed / none */
59
+ borderStyle?: "solid" | "dashed" | "none";
60
+ /** Border color (default: the text color at 35% opacity); an explicit color draws at full opacity */
61
+ borderColor?: string;
62
+ };
48
63
 
49
64
  export interface TopologyEdge {
50
65
  id: string;
51
66
  from: string;
52
67
  to: string;
68
+ /** Line color of this edge (animation layers). Takes priority over config.edgeColor and the legacy edge.centerText.color fallback. */
69
+ color?: string;
70
+ /** Static line color of this edge (the solid line visible when animations are off). Priority over config.edgeBaseColor; falls back to edge.color / config.edgeColor when explicitly configured, else legacy "#1a2744". */
71
+ baseColor?: string;
72
+ /** Opacity of this edge's solid base line while the edge animation mode is active (overrides config.edgeBaseDimOpacity — an explicitly set value always applies, even on edges with animation switched off). */
73
+ baseDimOpacity?: number;
53
74
  /** flow speed multiplier */
54
75
  speed?: number;
55
76
  /** Per-edge animation switch: `false` stops this edge's flow + particle layers (works even when the global fx config is on); `true` / unset follow the global config */
56
77
  animated?: boolean;
78
+ /** Ants-marching dashed flow for this edge (overrides config.edgeDashFlow when set) */
79
+ dashFlow?: boolean;
80
+ /** Stroke width of this edge's dashed flow line (default 2) */
81
+ dashFlowWidth?: number;
57
82
  fromAnchor?: "center" | "edge";
58
83
  toAnchor?: "center" | "edge";
59
84
  fromText?: TopologyEdgeLabel;
@@ -125,6 +150,30 @@ export interface TopologyConfig {
125
150
  showCenterPoint?: boolean;
126
151
  showEdgeTextBg?: boolean;
127
152
  edgeTextBgColor?: string;
153
+ /** Edge label plate opacity 0-1 (default 0.92) */
154
+ edgeTextBgOpacity?: number;
155
+ /** Global default line color for edges (animation layers AND, when set, the static line). Per-edge `edge.color` wins. Legacy fallback edge.centerText.color still applies to animation layers when unset. */
156
+ edgeColor?: string;
157
+ /** Alias for `edgeColor` */
158
+ defaultEdgeColor?: string;
159
+ /** Global static line color (the solid line visible when animations are off) — default legacy "#1a2744". Per-edge `edge.baseColor` wins. */
160
+ edgeBaseColor?: string;
161
+ /**
162
+ * Opacity (0-1) of the solid base line of edges while the edge animation
163
+ * mode is NOT "none" (flow / particle / all), so the moving layer stands
164
+ * out. Default 0.45; 1 disables dimming; mode "none" restores full
165
+ * opacity. Per-edge `edge.baseDimOpacity` overrides (explicit values
166
+ * always apply, even on edges with animation switched off).
167
+ */
168
+ edgeBaseDimOpacity?: number;
169
+ /** Global default color for edge CENTER text (per-edge centerText.color / edge.fontColor win); from/to texts fall back to "#000000" */
170
+ edgeCenterTextColor?: string;
171
+ /** Ants-marching dashed flow on edges (per-edge `edge.dashFlow` overrides). Independent of motionFx flow/particle layers. */
172
+ edgeDashFlow?: boolean;
173
+ /** Dash pattern of the dashed flow line — e.g. "10 8" or [10, 8] (default "10 8") */
174
+ edgeDashPattern?: string | number[];
175
+ /** Stroke width of the dashed flow line (default 2, per-edge edge.dashFlowWidth overrides) */
176
+ edgeDashFlowWidth?: number;
128
177
  showNodeHandles?: boolean;
129
178
  /** Status dot at each node's top-right corner (shown by default) */
130
179
  showStatusDot?: boolean;
@@ -138,6 +187,15 @@ export interface TopologyConfig {
138
187
  * deforms the picture.
139
188
  */
140
189
  imageFit?: "cover" | "contain";
190
+ /**
191
+ * Global image-node switch. When true, ANY node carrying a picture source
192
+ * (`image` / `src` / `img` / `imageUrl`, non-empty string) is rendered as an
193
+ * image node — its `nodeType` is ignored, so a whole photo/avatar graph does
194
+ * not need explicit `nodeType: "image"`. Text and border-only nodes keep
195
+ * their own rendering. Default false (opt-in), which keeps the original rule:
196
+ * image node = `nodeType` image/img/picture, or no `nodeType` + picture.
197
+ */
198
+ imageNodeBySource?: boolean;
141
199
  /**
142
200
  * Node / edge paint order.
143
201
  * - "split" (default): every node is painted in two passes — background
@@ -152,8 +210,6 @@ export interface TopologyConfig {
152
210
  * never hidden by a node plate or icon. Default true.
153
211
  */
154
212
  highlightEdgeOnTop?: boolean;
155
- /** Casing color drawn under a promoted (selected) edge — default "#0a0e1a". */
156
- edgeCasingColor?: string;
157
213
  /**
158
214
  * Delete the current selection when Delete / Backspace is pressed
159
215
  * (only while editable and something is selected; form fields are never