irr-gh 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +144 -1
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -44,6 +44,8 @@ bun add irr-gh
44
44
 
45
45
  ## 快速开始
46
46
 
47
+ ### 组件导入方式
48
+
47
49
  ```vue
48
50
  <script setup lang="ts">
49
51
  import { ref } from 'vue'
@@ -82,6 +84,63 @@ function handleReady(graph: unknown) {
82
84
  </template>
83
85
  ```
84
86
 
87
+ ### 全局注册方式
88
+
89
+ 您也可以在 main.js/main.ts 中全局注册组件:
90
+
91
+ ```javascript
92
+ // main.js
93
+ import { createApp } from 'vue'
94
+ import App from './App.vue'
95
+ import IrrGh from 'irr-gh'
96
+ import 'irr-gh/style.css'
97
+
98
+ const app = createApp(App)
99
+
100
+ // 全局注册组件
101
+ app.use(IrrGh)
102
+
103
+ app.mount('#app')
104
+ ```
105
+
106
+ 之后就可以在任何组件中直接使用 `<IrrigationGraph>` 组件,无需单独导入:
107
+
108
+ ```vue
109
+ <script setup lang="ts">
110
+ import { ref } from 'vue'
111
+ import type { IrrigationData } from 'irr-gh'
112
+
113
+ const graphRef = ref()
114
+
115
+ // 示例数据
116
+ const data: IrrigationData = {
117
+ canals: [
118
+ { id: 'main', name: '主干渠', type: 'canal', level: 1 },
119
+ { id: 'branch-1', name: '支渠1', type: 'canal', parentId: 'main', bankSide: 'left' }
120
+ ],
121
+ points: [
122
+ { id: 'sluice-1', name: '闸门1', type: 'sluice', canalId: 'main', chainage: 0 },
123
+ { id: 'sluice-2', name: '闸门2', type: 'sluice', canalId: 'main', chainage: 100 }
124
+ ]
125
+ }
126
+
127
+ function handleReady(graph: unknown) {
128
+ console.log('图渲染完成', graph)
129
+ }
130
+ </script>
131
+
132
+ <template>
133
+ <IrrigationGraph
134
+ ref="graphRef"
135
+ :data="data"
136
+ :enable-minimap="true"
137
+ :fit-view="true"
138
+ :show-toolbar="true"
139
+ @ready="handleReady"
140
+ />
141
+ </template>
142
+ ```
143
+
85
144
  ---
86
145
 
87
146
  ## 布局系统
@@ -340,6 +399,90 @@ interface PointEntity {
340
399
  chainage: number // 桩号位置
341
400
  bankSide?: 'left' | 'right' | 'center' // 岸别
342
401
  properties?: Record<string, unknown> // 扩展属性
402
+ /** 节点显示配置(可选,用于自定义节点的G6渲染样式) */
403
+ nodeConfig?: PointNodeConfig
404
+ }
405
+ ```
406
+
407
+ #### 节点显示配置 (PointNodeConfig)
408
+
409
+ 您可以使用 `nodeConfig` 属性来自定义节点的显示样式:
410
+
411
+ ```typescript
412
+ interface PointNodeConfig {
413
+ /** 节点形状: rect(矩形), circle(圆形), diamond(菱形), image(图片) */
414
+ shape?: 'rect' | 'circle' | 'diamond' | 'ellipse' | 'image'
415
+ /** 图片地址(shape为image时使用) */
416
+ img?: string
417
+ /** 节点宽度 */
418
+ width?: number
419
+ /** 节点高度 */
420
+ height?: number
421
+ /** 填充色 */
422
+ fill?: string
423
+ /** 边框色 */
424
+ stroke?: string
425
+ /** 边框宽度 */
426
+ lineWidth?: number
427
+ /** 圆角半径 */
428
+ radius?: number
429
+ }
430
+ ```
431
+
432
+ **使用示例:**
433
+
434
+ ```typescript
435
+ // 使用图片节点
436
+ const sluiceWithImage: SluiceEntity = {
437
+ id: 'slu-1',
438
+ name: '进水闸1',
439
+ type: 'sluice',
440
+ canalId: 'canal-A',
441
+ chainage: 0,
442
+ sluiceType: 'inlet',
443
+ designFlow: 50,
444
+ nodeConfig: {
445
+ shape: 'image',
446
+ img: '/head.png',
447
+ width: 48,
448
+ height: 48
449
+ }
450
+ }
451
+
452
+ // 使用矩形节点并自定义样式
453
+ const pumpWithCustomStyle: PumpStationEntity = {
454
+ id: 'pump-1',
455
+ name: '提水泵站1',
456
+ type: 'pumpStation',
457
+ canalId: 'canal-B',
458
+ chainage: 100,
459
+ capacity: 500,
460
+ pumpType: 'lift',
461
+ nodeConfig: {
462
+ shape: 'rect',
463
+ width: 60,
464
+ height: 40,
465
+ fill: '#ffccc7',
466
+ stroke: '#ff4d4f',
467
+ radius: 8
468
+ }
469
+ }
470
+
471
+ // 使用圆形节点
472
+ const reservoirWithCircle: ReservoirEntity = {
473
+ id: 'reservoir-1',
474
+ name: '调节水库1',
475
+ type: 'reservoir',
476
+ canalId: 'canal-C',
477
+ chainage: 500,
478
+ storageCapacity: 10000,
479
+ normalLevel: 85,
480
+ nodeConfig: {
481
+ shape: 'circle',
482
+ r: 24, // 圆形使用 r 属性表示半径
483
+ fill: '#e6f7ff',
484
+ stroke: '#1890ff'
485
+ }
343
486
  }
344
487
  ```
345
488
 
@@ -468,7 +611,7 @@ export const CANAL_COLOR = '#1890ff'
468
611
 
469
612
  ### 图片类型节点
470
613
 
471
- 点位节点支持使用图片,通过 `styleConfig.img` 配置:
614
+ 点位节点支持使用图片,通过业务数据中的 `nodeConfig` 配置(推荐方式),或通过 G6 图数据中的 `styleConfig.img` 配置:
472
615
 
473
616
  ```typescript
474
617
  // 业务数据中的节点配置(推荐方式)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "irr-gh",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "灌溉系统概化图组件",
5
5
  "type": "module",
6
6
  "main": "./dist/irr-gh.umd.cjs",
@@ -12,7 +12,7 @@
12
12
  "import": "./dist/irr-gh.js",
13
13
  "require": "./dist/irr-gh.umd.cjs"
14
14
  },
15
- "./style.css": "./dist/style.css"
15
+ "./style.css": "./dist/irr-gh.css"
16
16
  },
17
17
  "files": [
18
18
  "dist"
@@ -51,7 +51,7 @@
51
51
  "灌溉",
52
52
  "概化图"
53
53
  ],
54
- "author": "Your Name <your.email@example.com>",
54
+ "author": "eRiver",
55
55
  "license": "MIT",
56
56
  "repository": {
57
57
  "type": "git",