@vope/utils 1.6.0-bate.7 → 1.6.0-bate.8
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/dist/index.js +1243 -81
- package/package.json +1 -2
- package/sub_storage/offline.js +18 -16
- package/dist/clamp.js +0 -31
- package/dist/classnames.js +0 -37
- package/dist/compare/version.js +0 -35
- package/dist/compare/weak-equal.js +0 -53
- package/dist/convert/json.js +0 -27
- package/dist/convert/object.js +0 -27
- package/dist/convert/strings.js +0 -27
- package/dist/desens.js +0 -71
- package/dist/encoding.js +0 -76
- package/dist/input-regex.js +0 -28
- package/dist/is/class.js +0 -42
- package/dist/is/empty.js +0 -25
- package/dist/is/key.js +0 -24
- package/dist/is/null.js +0 -24
- package/dist/load/image.js +0 -31
- package/dist/memory/basic.js +0 -187
- package/dist/memory/list.js +0 -32
- package/dist/memory/power.js +0 -33
- package/dist/memory/simple.js +0 -114
- package/dist/neo4j-anchors.js +0 -189
- package/dist/neo4j.js +0 -181
- package/dist/once.js +0 -28
- package/dist/parse/num.js +0 -51
- package/dist/power/decon.js +0 -42
- package/dist/rotate/angle.js +0 -25
- package/dist/rotate/rad.js +0 -31
- package/dist/serialize/url-params.js +0 -73
- package/dist/style/css.js +0 -45
- package/dist/subscriber.js +0 -84
- package/dist/table/flex.js +0 -116
- package/dist/union.js +0 -67
- package/dist/url/join.js +0 -29
- package/dist/url/params.js +0 -28
- package/dist/wait.js +0 -24
package/dist/memory/basic.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var basic_exports = {};
|
|
20
|
-
__export(basic_exports, {
|
|
21
|
-
MemoryBasic: () => MemoryBasic
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(basic_exports);
|
|
24
|
-
var import_strings = require("../convert/strings");
|
|
25
|
-
class MemoryBasic {
|
|
26
|
-
/**
|
|
27
|
-
* @param key 用于对数据进行分类的key
|
|
28
|
-
* @param config
|
|
29
|
-
*/
|
|
30
|
-
constructor(key, config) {
|
|
31
|
-
this.key = key;
|
|
32
|
-
this.#mount = config.mount;
|
|
33
|
-
this.#reflex = config.reflex;
|
|
34
|
-
}
|
|
35
|
-
#mount;
|
|
36
|
-
#reflex;
|
|
37
|
-
list = [];
|
|
38
|
-
memorys = /* @__PURE__ */ new Map();
|
|
39
|
-
/**
|
|
40
|
-
* 返回存储长度
|
|
41
|
-
*/
|
|
42
|
-
get size() {
|
|
43
|
-
return this.list.length;
|
|
44
|
-
}
|
|
45
|
-
getType(data) {
|
|
46
|
-
const { key } = this;
|
|
47
|
-
return typeof key === "function" ? key(data) : data[key];
|
|
48
|
-
}
|
|
49
|
-
push(...list) {
|
|
50
|
-
const { memorys } = this;
|
|
51
|
-
list.forEach((data) => {
|
|
52
|
-
const type = this.getType(data);
|
|
53
|
-
const memory = memorys.get(type);
|
|
54
|
-
const index = this.list.push(data) - 1;
|
|
55
|
-
const result = this.#mount(index, memory);
|
|
56
|
-
memory === result || memorys.set(type, result);
|
|
57
|
-
});
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 返回位于指定索引处的项
|
|
62
|
-
*/
|
|
63
|
-
at(index) {
|
|
64
|
-
const { list } = this;
|
|
65
|
-
if (index < 0) {
|
|
66
|
-
index += list.length;
|
|
67
|
-
}
|
|
68
|
-
return this.list.at(index);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* 遍历所有存储数据(按入栈顺序)
|
|
72
|
-
*/
|
|
73
|
-
forEach(callback) {
|
|
74
|
-
this.list.forEach(callback);
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 遍历所有存储类型
|
|
79
|
-
*/
|
|
80
|
-
forType(callback) {
|
|
81
|
-
const { memorys, list } = this;
|
|
82
|
-
for (const [type, memory] of memorys) {
|
|
83
|
-
const caches = this.#reflex(memory).map((index) => list[index]);
|
|
84
|
-
callback(caches, type);
|
|
85
|
-
}
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* some(按入栈顺序)
|
|
90
|
-
*/
|
|
91
|
-
some(callback) {
|
|
92
|
-
return this.list.some(callback);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* map(按入栈顺序)
|
|
96
|
-
*/
|
|
97
|
-
map(callback) {
|
|
98
|
-
return this.list.map(callback);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* reduce(按入栈顺序)
|
|
102
|
-
*/
|
|
103
|
-
reduce(callback, initialValue) {
|
|
104
|
-
return this.list.reduce(callback, initialValue);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 判断存储是否包含指定类型
|
|
108
|
-
*/
|
|
109
|
-
includes(type) {
|
|
110
|
-
return this.memorys.has(type);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* 获取指定类型存储数据
|
|
114
|
-
*/
|
|
115
|
-
get(type) {
|
|
116
|
-
const memory = this.memorys.get(type);
|
|
117
|
-
return memory === void 0 ? null : this.#reflex(memory).map((count) => this.list[count]);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 删除指定存储数据
|
|
121
|
-
*/
|
|
122
|
-
delete(data) {
|
|
123
|
-
const { memorys, list } = this;
|
|
124
|
-
let index = -1;
|
|
125
|
-
if (!list.some((value, i) => {
|
|
126
|
-
if (data === value) {
|
|
127
|
-
index = i;
|
|
128
|
-
list.splice(index, 1);
|
|
129
|
-
const type = this.getType(value);
|
|
130
|
-
const memory = this.#reflex(memorys.get(type));
|
|
131
|
-
if (memory.length === 1) {
|
|
132
|
-
memorys.delete(type);
|
|
133
|
-
} else {
|
|
134
|
-
memory.some((count, j) => {
|
|
135
|
-
if (count === i) {
|
|
136
|
-
memory.splice(j, 1);
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
})) return this;
|
|
144
|
-
for (const [type, target] of memorys) {
|
|
145
|
-
const memory = this.#reflex(target);
|
|
146
|
-
memory.forEach((value, i) => {
|
|
147
|
-
if (value >= index) {
|
|
148
|
-
memory[i] = value - 1;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
if (memory !== target) {
|
|
152
|
-
let reactor;
|
|
153
|
-
memory.forEach((count) => {
|
|
154
|
-
reactor = this.#mount(count, reactor);
|
|
155
|
-
});
|
|
156
|
-
memorys.set(type, reactor);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* 删除指定类型存储数据
|
|
163
|
-
*/
|
|
164
|
-
deleteType(type) {
|
|
165
|
-
const { memorys, list } = this;
|
|
166
|
-
if (!memorys.has(type)) return this;
|
|
167
|
-
const local = (0, import_strings.hash8strings)(this.#reflex(memorys.get(type)));
|
|
168
|
-
const Memory = this.constructor;
|
|
169
|
-
const imitator = new Memory(this.key, {
|
|
170
|
-
mount: this.#mount,
|
|
171
|
-
reflex: this.#reflex
|
|
172
|
-
});
|
|
173
|
-
list.forEach((data, index) => {
|
|
174
|
-
index in local || imitator.push(data);
|
|
175
|
-
});
|
|
176
|
-
this.list = imitator.list;
|
|
177
|
-
this.memorys = imitator.memorys;
|
|
178
|
-
return this;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* 清理存储
|
|
182
|
-
*/
|
|
183
|
-
clear() {
|
|
184
|
-
this.list = [];
|
|
185
|
-
this.memorys.clear();
|
|
186
|
-
}
|
|
187
|
-
}
|
package/dist/memory/list.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var list_exports = {};
|
|
20
|
-
__export(list_exports, {
|
|
21
|
-
MemoryList: () => MemoryList
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(list_exports);
|
|
24
|
-
var import_basic = require("./basic");
|
|
25
|
-
class MemoryList extends import_basic.MemoryBasic {
|
|
26
|
-
constructor(key) {
|
|
27
|
-
super(key, {
|
|
28
|
-
mount: (index, reactor) => reactor ? (reactor.push(index), reactor) : [index],
|
|
29
|
-
reflex: (reactor) => reactor
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
package/dist/memory/power.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var power_exports = {};
|
|
20
|
-
__export(power_exports, {
|
|
21
|
-
MemoryPower: () => MemoryPower
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(power_exports);
|
|
24
|
-
var import_decon = require("../power/decon");
|
|
25
|
-
var import_basic = require("./basic");
|
|
26
|
-
class MemoryPower extends import_basic.MemoryBasic {
|
|
27
|
-
constructor(key) {
|
|
28
|
-
super(key, {
|
|
29
|
-
mount: (index, reactor) => (reactor || 0) + 2 ** index,
|
|
30
|
-
reflex: (reactor) => (0, import_decon.deconPowersSum)(reactor, "asc")
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
package/dist/memory/simple.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var simple_exports = {};
|
|
20
|
-
__export(simple_exports, {
|
|
21
|
-
MemorySimple: () => MemorySimple
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(simple_exports);
|
|
24
|
-
var import_basic = require("./basic");
|
|
25
|
-
class MemorySimple {
|
|
26
|
-
#memory;
|
|
27
|
-
#key;
|
|
28
|
-
get size() {
|
|
29
|
-
return this.#memory.size;
|
|
30
|
-
}
|
|
31
|
-
constructor(key) {
|
|
32
|
-
this.#key = key;
|
|
33
|
-
this.#memory = new import_basic.MemoryBasic(key, {
|
|
34
|
-
mount: (index) => index,
|
|
35
|
-
reflex: (reactor) => [reactor]
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
#getType(data) {
|
|
39
|
-
const key = this.#key;
|
|
40
|
-
return typeof key === "function" ? key(data) : data[key];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* 返回位于指定索引处的项
|
|
44
|
-
*/
|
|
45
|
-
at(index) {
|
|
46
|
-
return this.#memory.at(index);
|
|
47
|
-
}
|
|
48
|
-
push(...list) {
|
|
49
|
-
const memory = this.#memory;
|
|
50
|
-
list.forEach((data) => {
|
|
51
|
-
memory.includes(this.#getType(data)) || memory.push(data);
|
|
52
|
-
});
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 获取指定类型存储数据
|
|
57
|
-
*/
|
|
58
|
-
get(type) {
|
|
59
|
-
const value = this.#memory.get(type);
|
|
60
|
-
if (value === null) return value;
|
|
61
|
-
return value.length ? value[0] : null;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* 遍历所有存储数据(按入栈顺序)
|
|
65
|
-
*/
|
|
66
|
-
forEach(callback) {
|
|
67
|
-
this.#memory.forEach(callback);
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* some(按入栈顺序)
|
|
72
|
-
*/
|
|
73
|
-
some(callback) {
|
|
74
|
-
return this.#memory.some(callback);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* map(按入栈顺序)
|
|
78
|
-
*/
|
|
79
|
-
map(callback) {
|
|
80
|
-
return this.#memory.map(callback);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* reduce(按入栈顺序)
|
|
84
|
-
*/
|
|
85
|
-
reduce(callback, initialValue) {
|
|
86
|
-
return this.#memory.reduce(callback, initialValue);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* 判断是否包含指定类型
|
|
90
|
-
*/
|
|
91
|
-
includes(type) {
|
|
92
|
-
return this.#memory.includes(type);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* 删除指定存储数据
|
|
96
|
-
*/
|
|
97
|
-
delete(data) {
|
|
98
|
-
this.#memory.delete(data);
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 删除指定类型存储数据
|
|
103
|
-
*/
|
|
104
|
-
deleteType(type) {
|
|
105
|
-
this.#memory.deleteType(type);
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 清理存储
|
|
110
|
-
*/
|
|
111
|
-
clear() {
|
|
112
|
-
this.#memory.clear();
|
|
113
|
-
}
|
|
114
|
-
}
|
package/dist/neo4j-anchors.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var neo4j_anchors_exports = {};
|
|
20
|
-
__export(neo4j_anchors_exports, {
|
|
21
|
-
default: () => Neo4jAhchors
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(neo4j_anchors_exports);
|
|
24
|
-
var import_rad = require("./rotate/rad");
|
|
25
|
-
class Neo4jAhchors {
|
|
26
|
-
constructor(neo4j, config) {
|
|
27
|
-
this.neo4j = neo4j;
|
|
28
|
-
this.config = Object.assign({}, config);
|
|
29
|
-
}
|
|
30
|
-
config;
|
|
31
|
-
#anchors = {};
|
|
32
|
-
getDir(start, end) {
|
|
33
|
-
const { neo4j } = this;
|
|
34
|
-
return neo4j.dirKey({
|
|
35
|
-
[neo4j.sourceField]: start,
|
|
36
|
-
[neo4j.targetField]: end
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 设置多边间隔弧长
|
|
41
|
-
*/
|
|
42
|
-
setRaidx(value) {
|
|
43
|
-
this.config.radOffsetRaidx = value;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 当图数据准备好后调用
|
|
47
|
-
*/
|
|
48
|
-
read() {
|
|
49
|
-
const { neo4j } = this;
|
|
50
|
-
const { nodeField, edgeField, sourceField, targetField } = neo4j;
|
|
51
|
-
const anchors = {};
|
|
52
|
-
neo4j.nodes.forEach((node) => {
|
|
53
|
-
const nodeId = node[nodeField];
|
|
54
|
-
let count = 0;
|
|
55
|
-
[
|
|
56
|
-
neo4j.sources.get(nodeId),
|
|
57
|
-
neo4j.targets.get(nodeId)
|
|
58
|
-
].forEach((list, i) => {
|
|
59
|
-
if (!list) return;
|
|
60
|
-
let diffCount = 0;
|
|
61
|
-
let sameCount = 0;
|
|
62
|
-
list.forEach((edge) => {
|
|
63
|
-
const edgeId = edge[edgeField];
|
|
64
|
-
if (edge[sourceField] !== edge[targetField]) {
|
|
65
|
-
const anchor = anchors[edgeId] || (anchors[edgeId] = {});
|
|
66
|
-
anchor[i ? "target" : "source"] = count + diffCount++;
|
|
67
|
-
} else if (edgeId in anchors === false) {
|
|
68
|
-
anchors[edgeId] = {
|
|
69
|
-
source: sameCount,
|
|
70
|
-
target: sameCount++
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
count += diffCount;
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
this.#anchors = anchors;
|
|
78
|
-
}
|
|
79
|
-
calcPoints(edge, index, total, type) {
|
|
80
|
-
const { neo4j, config: { getBox, radOffsetRaidx = 0.3125 } } = this;
|
|
81
|
-
const source = getBox(edge[neo4j.sourceField]);
|
|
82
|
-
const target = getBox(edge[neo4j.targetField]);
|
|
83
|
-
const rad = Math.atan2(
|
|
84
|
-
(source.centerY - target.centerY) * type,
|
|
85
|
-
(source.centerX - target.centerX) * type
|
|
86
|
-
);
|
|
87
|
-
let point = (0, import_rad.rotateRad)([0.5, 0], rad);
|
|
88
|
-
if (total !== 1) {
|
|
89
|
-
point = (0, import_rad.rotateRad)(point, radOffsetRaidx * (total / 2 - 0.5 - index));
|
|
90
|
-
}
|
|
91
|
-
const [x, y] = point;
|
|
92
|
-
return [x + 0.5, 0.5 - y];
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* 获取指定节点上出入边连接点的坐标
|
|
96
|
-
*/
|
|
97
|
-
getPoints(id) {
|
|
98
|
-
const { neo4j } = this;
|
|
99
|
-
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
100
|
-
const anchors = this.#anchors;
|
|
101
|
-
const points = [];
|
|
102
|
-
const caches = {};
|
|
103
|
-
neo4j.sources.get(id)?.forEach((edge) => {
|
|
104
|
-
const source = edge[sourceField];
|
|
105
|
-
const target = edge[targetField];
|
|
106
|
-
const direct = this.getDir(source, target);
|
|
107
|
-
const invert = this.getDir(target, source);
|
|
108
|
-
if (direct in caches) return;
|
|
109
|
-
const directs = dirs.get(direct) || [];
|
|
110
|
-
const inverts = dirs.get(invert) || [];
|
|
111
|
-
const directsLength = directs.length;
|
|
112
|
-
const invertsLength = inverts.length;
|
|
113
|
-
const total = directsLength + invertsLength;
|
|
114
|
-
directs.forEach((data, index) => {
|
|
115
|
-
points[anchors[data[edgeField]].source] = this.calcPoints(data, directsLength - 1 - index, total, -1);
|
|
116
|
-
});
|
|
117
|
-
caches[direct] = direct;
|
|
118
|
-
});
|
|
119
|
-
neo4j.targets.get(id)?.forEach((edge) => {
|
|
120
|
-
const source = edge[sourceField];
|
|
121
|
-
const target = edge[targetField];
|
|
122
|
-
const direct = this.getDir(source, target);
|
|
123
|
-
const invert = this.getDir(target, source);
|
|
124
|
-
if (direct in caches) return;
|
|
125
|
-
const directs = neo4j.dirs.get(direct) || [];
|
|
126
|
-
const inverts = neo4j.dirs.get(invert) || [];
|
|
127
|
-
const directsLength = directs.length;
|
|
128
|
-
const invertsLength = inverts.length;
|
|
129
|
-
const total = directsLength + invertsLength;
|
|
130
|
-
directs.forEach((data, index) => {
|
|
131
|
-
points[anchors[data[edgeField]].target] = this.calcPoints(data, invertsLength + index, total, 1);
|
|
132
|
-
});
|
|
133
|
-
caches[direct] = direct;
|
|
134
|
-
});
|
|
135
|
-
return points;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* 查找边连接点的位置
|
|
139
|
-
*/
|
|
140
|
-
findAnchor(id) {
|
|
141
|
-
const anchor = this.#anchors[id];
|
|
142
|
-
if (!anchor) return null;
|
|
143
|
-
return {
|
|
144
|
-
source: anchor.source || 0,
|
|
145
|
-
target: anchor.target || 0
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 获取指定边控制点距离两端点连线的距离(可理解为控制边的弯曲程度)
|
|
150
|
-
* @description 返回值是一个相对值,需要乘以一个基数值(基数值应为负值,如-30)
|
|
151
|
-
*/
|
|
152
|
-
getOffset(id) {
|
|
153
|
-
const { neo4j } = this;
|
|
154
|
-
const edge = neo4j.edges.get(id);
|
|
155
|
-
if (!edge) return -1;
|
|
156
|
-
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
157
|
-
const source = edge[sourceField];
|
|
158
|
-
const target = edge[targetField];
|
|
159
|
-
const directs = dirs.get(this.getDir(source, target)) || [];
|
|
160
|
-
const inverts = dirs.get(this.getDir(target, source)) || [];
|
|
161
|
-
let count = 0;
|
|
162
|
-
let index = 0;
|
|
163
|
-
[directs, inverts].some((list) => {
|
|
164
|
-
const result = list.some((data, i) => {
|
|
165
|
-
if (data[edgeField] === id) {
|
|
166
|
-
index = i + count;
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
count += list.length;
|
|
171
|
-
return result;
|
|
172
|
-
});
|
|
173
|
-
const directsSize = directs.length;
|
|
174
|
-
const invertsSize = inverts.length;
|
|
175
|
-
const total = directsSize + invertsSize;
|
|
176
|
-
if (total === 1) return -1;
|
|
177
|
-
if (directsSize === 0 || invertsSize === 0) {
|
|
178
|
-
return total / 2 - index - 0.5;
|
|
179
|
-
} else {
|
|
180
|
-
return Math.abs(directsSize - invertsSize) * (directsSize >= invertsSize ? 1 : -1) / 2 - index - 0.5;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* 清理数据
|
|
185
|
-
*/
|
|
186
|
-
clear() {
|
|
187
|
-
this.#anchors = {};
|
|
188
|
-
}
|
|
189
|
-
}
|