irr-gh 0.1.0

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.
@@ -0,0 +1,25 @@
1
+ import type { Component } from 'vue';
2
+
3
+ interface IrrigationGraphProps {
4
+ data?: any;
5
+ config?: any;
6
+ readonly?: boolean;
7
+ showToolbar?: boolean;
8
+ toolbarConfig?: any;
9
+ }
10
+
11
+ interface IrrigationGraphEmits {
12
+ (event: 'nodeClick', params: any): void;
13
+ (event: 'nodeDblclick', params: any): void;
14
+ (event: 'nodeContextmenu', params: any): void;
15
+ (event: 'edgeClick', params: any): void;
16
+ (event: 'edgeDblclick', params: any): void;
17
+ (event: 'edgeContextmenu', params: any): void;
18
+ (event: 'canvasClick', params: any): void;
19
+ (event: 'graphReady', graph: any): void;
20
+ (event: 'dataChange', data: any): void;
21
+ }
22
+
23
+ declare const IrrigationGraph: Component<IrrigationGraphProps>;
24
+
25
+ export default IrrigationGraph;
@@ -0,0 +1,95 @@
1
+ // 核心模块类型定义
2
+
3
+ // 图管理器类型
4
+ export interface IrrigationGraphManager {
5
+ render(container: HTMLElement, data: any): void;
6
+ updateData(data: any): void;
7
+ destroy(): void;
8
+ on(event: string, callback: Function): void;
9
+ off(event: string, callback: Function): void;
10
+ emit(event: string, params?: any): void;
11
+ }
12
+
13
+ export function createGraphManager(options?: any): IrrigationGraphManager;
14
+
15
+ // 数据转换器类型
16
+ export interface TransformConfig {
17
+ spacing?: Partial<LayoutSpacing>;
18
+ autoGenerateAuxiliary?: boolean;
19
+ autoGenerateEdges?: boolean;
20
+ startPosition?: { x: number; y: number };
21
+ }
22
+
23
+ export interface LayoutSpacing {
24
+ horizontal: number;
25
+ vertical: number;
26
+ branchOffset: number;
27
+ }
28
+
29
+ export interface DataTransformer {
30
+ transform(data: any): any;
31
+ setSpacing(spacing: Partial<LayoutSpacing>): void;
32
+ getConfig(): TransformConfig;
33
+ }
34
+
35
+ export function createTransformer(config?: TransformConfig): DataTransformer;
36
+ export function transformData(data: any, config?: TransformConfig): any;
37
+
38
+ // 节点和边样式类型
39
+ export interface NodeStyleConfig {
40
+ fill?: string;
41
+ stroke?: string;
42
+ lineWidth?: number;
43
+ radius?: number;
44
+ width?: number;
45
+ height?: number;
46
+ size?: number | [number, number];
47
+ }
48
+
49
+ export interface EdgeStyleConfig {
50
+ stroke?: string;
51
+ lineWidth?: number;
52
+ lineDash?: number[];
53
+ endArrow?: boolean;
54
+ router?: {
55
+ type: string;
56
+ offset: number;
57
+ };
58
+ }
59
+
60
+ // 工具函数类型
61
+ export function serializeGraphData(data: any): string;
62
+ export function deserializeGraphData(json: string): any;
63
+ export function downloadJSON(data: any, filename: string): void;
64
+ export function readJSONFile(file: File): Promise<any>;
65
+ export function copyToClipboard(text: string): Promise<void>;
66
+ export function generateId(prefix?: string): string;
67
+ export function deepClone<T>(obj: T): T;
68
+ export function debounce<T extends (...args: any[]) => any>(func: T, wait: number): T;
69
+ export function throttle<T extends (...args: any[]) => any>(func: T, wait: number): T;
70
+ export function distance(p1: { x: number; y: number }, p2: { x: number; y: number }): number;
71
+ export function pointToSegmentDistance(
72
+ point: { x: number; y: number },
73
+ segStart: { x: number; y: number },
74
+ segEnd: { x: number; y: number }
75
+ ): number;
76
+ export function validateGraphData(data: any): boolean;
77
+
78
+ // 布局工具函数类型
79
+ export type AlignType = 'horizontal' | 'vertical';
80
+ export type DistributeType = 'horizontal' | 'vertical';
81
+
82
+ export function getNodePosition(node: any): { x: number; y: number };
83
+ export function setNodePosition(node: any, x: number, y: number): void;
84
+ export function alignNodesHorizontally(nodes: any[], alignment: 'top' | 'middle' | 'bottom'): void;
85
+ export function alignNodesVertically(nodes: any[], alignment: 'left' | 'center' | 'right'): void;
86
+ export function distributeNodesHorizontally(nodes: any[], spacing: number): void;
87
+ export function distributeNodesVertically(nodes: any[], spacing: number): void;
88
+ export function moveNodes(nodes: any[], deltaX: number, deltaY: number): void;
89
+ export function getNodesBoundingBox(nodes: any[]): { minX: number; minY: number; maxX: number; maxY: number };
90
+ export function centerNodesToPosition(nodes: any[], centerX: number, centerY: number): void;
91
+ export function getNodesByCanalId(nodes: any[], canalId: string): any[];
92
+ export function getConnectedNodes(nodeId: string, edges: any[]): string[];
93
+ export function autoAdjustSpacing(nodes: any[], edges: any[], initialSpacing?: { horizontal: number; vertical: number }): { horizontal: number; vertical: number };
94
+ export function flipNodes(nodes: any[], direction: 'horizontal' | 'vertical', centerX?: number, centerY?: number): void;
95
+ export function rotateNodes90(nodes: any[], centerX?: number, centerY?: number, clockwise?: boolean): void;
@@ -0,0 +1,19 @@
1
+ // Hooks 类型定义
2
+
3
+ export interface UseIrrigationGraphOptions {
4
+ containerId: string;
5
+ data?: any;
6
+ config?: any;
7
+ }
8
+
9
+ export interface UseIrrigationGraphReturn {
10
+ graph: any;
11
+ data: any;
12
+ loading: boolean;
13
+ error: Error | null;
14
+ updateData: (newData: any) => void;
15
+ refresh: () => void;
16
+ destroy: () => void;
17
+ }
18
+
19
+ export function useIrrigationGraph(options: UseIrrigationGraphOptions): UseIrrigationGraphReturn;
@@ -0,0 +1,19 @@
1
+ import type { App, Plugin } from 'vue';
2
+ import IrrigationGraph from './components/IrrigationGraph.vue';
3
+
4
+ // 导出组件
5
+ export { IrrigationGraph };
6
+
7
+ // 导出类型
8
+ export * from './types';
9
+
10
+ // 导出核心模块
11
+ export * from './core';
12
+
13
+ // 导出 Hooks
14
+ export * from './hooks';
15
+
16
+ // 插件类型定义
17
+ declare const IrrGh: Plugin;
18
+
19
+ export default IrrGh;
@@ -0,0 +1,139 @@
1
+ // 业务数据类型定义
2
+ export interface BaseEntity {
3
+ id: string;
4
+ name: string;
5
+ type: string;
6
+ properties?: Record<string, unknown>;
7
+ }
8
+
9
+ export interface CanalEntity extends BaseEntity {
10
+ type: 'canal';
11
+ parentId?: string;
12
+ forkChainage?: number;
13
+ bankSide?: 'left' | 'right' | 'center';
14
+ startChainage?: number;
15
+ endChainage?: number;
16
+ level?: number;
17
+ }
18
+
19
+ export interface PointEntity extends BaseEntity {
20
+ canalId: string;
21
+ chainage: number;
22
+ }
23
+
24
+ export interface SluiceEntity extends PointEntity {
25
+ type: 'sluice';
26
+ sluiceType?: 'intake' | 'diversion' | 'control' | 'regulation';
27
+ designFlow?: number;
28
+ gateWidth?: number;
29
+ gateHeight?: number;
30
+ }
31
+
32
+ export interface PumpStationEntity extends PointEntity {
33
+ type: 'pumpStation';
34
+ capacity: number;
35
+ pumpType?: 'lift' | 'pressure' | 'mixed';
36
+ power?: number;
37
+ }
38
+
39
+ export interface ReservoirEntity extends PointEntity {
40
+ type: 'reservoir';
41
+ storageCapacity: number;
42
+ normalLevel?: number;
43
+ deadStorage?: number;
44
+ }
45
+
46
+ export interface DispatchUnitEntity extends PointEntity {
47
+ type: 'dispatchUnit';
48
+ unitType?: 'management' | 'control' | 'monitoring';
49
+ area?: number;
50
+ }
51
+
52
+ export interface DispatchNodeEntity extends PointEntity {
53
+ type: 'dispatchNode';
54
+ nodeType?: 'terminal' | 'relay' | 'gateway';
55
+ }
56
+
57
+ export interface AuxiliaryNodeEntity extends PointEntity {
58
+ type: 'auxiliary';
59
+ auxiliaryType: 'fork' | 'end' | 'junction';
60
+ branchCanalId?: string;
61
+ autoGenerated?: boolean;
62
+ }
63
+
64
+ export type PointEntityUnion =
65
+ | PumpStationEntity
66
+ | ReservoirEntity
67
+ | SluiceEntity
68
+ | DispatchUnitEntity
69
+ | DispatchNodeEntity
70
+ | AuxiliaryNodeEntity;
71
+
72
+ export type IrrigationEntity = CanalEntity | PointEntityUnion;
73
+
74
+ export interface IrrigationData {
75
+ canals: CanalEntity[];
76
+ points: PointEntityUnion[];
77
+ connections?: ConnectionData[];
78
+ }
79
+
80
+ export interface ConnectionData {
81
+ id: string;
82
+ sourceId: string;
83
+ targetId: string;
84
+ connectionType?: 'flow' | 'control' | 'supply';
85
+ properties?: Record<string, unknown>;
86
+ }
87
+
88
+ // 图形数据类型定义
89
+ export interface IrrigationNodeData {
90
+ id: string;
91
+ data: { label: string };
92
+ entityType: string;
93
+ businessData: IrrigationEntity;
94
+ nodeShape?: string;
95
+ styleConfig?: Record<string, unknown>;
96
+ style?: Record<string, unknown>;
97
+ }
98
+
99
+ export interface IrrigationEdgeData {
100
+ id: string;
101
+ source: string;
102
+ target: string;
103
+ data: { label: string };
104
+ edgeShape?: string;
105
+ connectionType?: string;
106
+ styleConfig?: Record<string, unknown>;
107
+ }
108
+
109
+ export interface IrrigationComboData {
110
+ id: string;
111
+ data: { label: string };
112
+ comboShape?: string;
113
+ styleConfig?: Record<string, unknown>;
114
+ }
115
+
116
+ export interface IrrigationGraphData {
117
+ nodes: IrrigationNodeData[];
118
+ edges: IrrigationEdgeData[];
119
+ combos?: IrrigationComboData[];
120
+ }
121
+
122
+ // 布局配置
123
+ export interface LayoutConfig {
124
+ type: 'force' | 'grid' | 'radial' | 'dagre' | 'custom';
125
+ options?: Record<string, unknown>;
126
+ }
127
+
128
+ // 交互事件类型
129
+ export type InteractionEventType =
130
+ | 'node:click'
131
+ | 'node:dblclick'
132
+ | 'node:contextmenu'
133
+ | 'edge:click'
134
+ | 'edge:dblclick'
135
+ | 'edge:contextmenu'
136
+ | 'combo:click'
137
+ | 'canvas:click'
138
+ | 'canvas:drag'
139
+ | 'canvas:zoom';
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "irr-gh",
3
+ "version": "0.1.0",
4
+ "description": "灌溉系统概化图组件",
5
+ "type": "module",
6
+ "main": "./dist/irr-gh.umd.cjs",
7
+ "module": "./dist/irr-gh.js",
8
+ "types": "./dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/irr-gh.js",
13
+ "require": "./dist/irr-gh.umd.cjs"
14
+ },
15
+ "./style.css": "./dist/style.css"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "engines": {
21
+ "node": "^20.19.0 || >=22.12.0"
22
+ },
23
+ "scripts": {
24
+ "dev": "vite",
25
+ "build": "run-p type-check build-only",
26
+ "build:lib": "vue-tsc --declaration --emitDeclarationOnly --project tsconfig.types.json && vite build",
27
+ "preview": "vite preview",
28
+ "build-only": "vite build",
29
+ "type-check": "vue-tsc --build"
30
+ },
31
+ "peerDependencies": {
32
+ "vue": "^3.3.0"
33
+ },
34
+ "devDependencies": {
35
+ "@tsconfig/node24": "^24.0.3",
36
+ "@types/node": "^24.10.4",
37
+ "@vitejs/plugin-vue": "^6.0.3",
38
+ "@vue/tsconfig": "^0.8.1",
39
+ "npm-run-all2": "^8.0.4",
40
+ "typescript": "~5.9.3",
41
+ "vite": "^7.3.0",
42
+ "vite-plugin-vue-devtools": "^8.0.5",
43
+ "vue": "^3.5.26",
44
+ "vue-tsc": "^3.2.2"
45
+ },
46
+ "keywords": [
47
+ "vue",
48
+ "vue3",
49
+ "irrigation",
50
+ "graph",
51
+ "灌溉",
52
+ "概化图"
53
+ ],
54
+ "author": "Your Name <your.email@example.com>",
55
+ "license": "MIT",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/your-username/irr-gh.git"
59
+ },
60
+ "bugs": {
61
+ "url": "https://github.com/your-username/irr-gh/issues"
62
+ },
63
+ "homepage": "https://github.com/your-username/irr-gh#readme",
64
+ "dependencies": {
65
+ "@antv/g6": "^5.0.51"
66
+ }
67
+ }