@vope/utils 1.4.20 → 1.4.22
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/cjs/index.js +201 -16
- package/lib/index.js +6 -4
- package/lib/neo4j-anchors.js +169 -0
- package/lib/neo4j.js +23 -6
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/neo4j-anchors.d.ts +45 -0
- package/types/neo4j.d.ts +26 -6
package/cjs/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
MemoryPower: () => MemoryPower,
|
|
27
27
|
MemorySimple: () => MemorySimple,
|
|
28
28
|
Neo4j: () => Neo4j,
|
|
29
|
+
Neo4jAhchors: () => Neo4jAhchors,
|
|
29
30
|
Subscriber: () => Subscriber,
|
|
30
31
|
Union: () => Union,
|
|
31
32
|
clamp: () => clamp,
|
|
@@ -591,16 +592,210 @@ var MemorySimple = class {
|
|
|
591
592
|
}
|
|
592
593
|
};
|
|
593
594
|
|
|
595
|
+
// src/rotate/rad.ts
|
|
596
|
+
var rotateRad = (from, rad, visit = [0, 0]) => {
|
|
597
|
+
const x = from[0] - visit[0];
|
|
598
|
+
const y = from[1] - visit[1];
|
|
599
|
+
return [
|
|
600
|
+
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
601
|
+
y * Math.cos(rad) - x * Math.sin(rad) + visit[1]
|
|
602
|
+
];
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// src/neo4j-anchors.ts
|
|
606
|
+
var Neo4jAhchors = class {
|
|
607
|
+
constructor(neo4j, config) {
|
|
608
|
+
this.neo4j = neo4j;
|
|
609
|
+
this.config = Object.assign({}, config);
|
|
610
|
+
}
|
|
611
|
+
config;
|
|
612
|
+
#anchors = {};
|
|
613
|
+
getDir(start, end) {
|
|
614
|
+
const { neo4j } = this;
|
|
615
|
+
return neo4j.dirKey({
|
|
616
|
+
[neo4j.sourceField]: start,
|
|
617
|
+
[neo4j.targetField]: end
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* 当图数据准备好后调用
|
|
622
|
+
*/
|
|
623
|
+
read() {
|
|
624
|
+
const { neo4j } = this;
|
|
625
|
+
const { nodeField, edgeField, sourceField, targetField } = neo4j;
|
|
626
|
+
const anchors = {};
|
|
627
|
+
neo4j.nodes.forEach((node) => {
|
|
628
|
+
const nodeId = node[nodeField];
|
|
629
|
+
let count = 0;
|
|
630
|
+
[
|
|
631
|
+
neo4j.sources.get(nodeId),
|
|
632
|
+
neo4j.targets.get(nodeId)
|
|
633
|
+
].forEach((list, i) => {
|
|
634
|
+
if (!list)
|
|
635
|
+
return;
|
|
636
|
+
let diffCount = 0;
|
|
637
|
+
let sameCount = 0;
|
|
638
|
+
list.forEach((edge) => {
|
|
639
|
+
const edgeId = edge[edgeField];
|
|
640
|
+
if (edge[sourceField] !== edge[targetField]) {
|
|
641
|
+
const anchor = anchors[edgeId] || (anchors[edgeId] = {});
|
|
642
|
+
anchor[i ? "target" : "source"] = count + diffCount++;
|
|
643
|
+
} else if (edgeId in anchors === false) {
|
|
644
|
+
anchors[edgeId] = {
|
|
645
|
+
source: sameCount,
|
|
646
|
+
target: sameCount++
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
count += diffCount;
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
this.#anchors = anchors;
|
|
654
|
+
}
|
|
655
|
+
calcPoints(edge, index, total, type) {
|
|
656
|
+
const { neo4j, config: { getBox, radOffsetRaidx = 0.3125 } } = this;
|
|
657
|
+
const source = getBox(edge[neo4j.sourceField]);
|
|
658
|
+
const target = getBox(edge[neo4j.targetField]);
|
|
659
|
+
const rad = Math.atan2(
|
|
660
|
+
(source.centerY - target.centerY) * type,
|
|
661
|
+
(source.centerX - target.centerX) * type
|
|
662
|
+
);
|
|
663
|
+
let point = rotateRad([0.5, 0], rad);
|
|
664
|
+
if (total !== 1) {
|
|
665
|
+
point = rotateRad(point, radOffsetRaidx * (total / 2 - 0.5 - index));
|
|
666
|
+
}
|
|
667
|
+
const [x, y] = point;
|
|
668
|
+
return [x + 0.5, 0.5 - y];
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* 获取指定节点上出入边连接点的坐标
|
|
672
|
+
*/
|
|
673
|
+
getPoints(id) {
|
|
674
|
+
const { neo4j } = this;
|
|
675
|
+
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
676
|
+
const anchors = this.#anchors;
|
|
677
|
+
const points = [];
|
|
678
|
+
const caches = {};
|
|
679
|
+
neo4j.sources.get(id)?.forEach((edge) => {
|
|
680
|
+
const source = edge[sourceField];
|
|
681
|
+
const target = edge[targetField];
|
|
682
|
+
const direct = this.getDir(source, target);
|
|
683
|
+
const invert = this.getDir(target, source);
|
|
684
|
+
if (direct in caches)
|
|
685
|
+
return;
|
|
686
|
+
const directs = dirs.get(direct) || [];
|
|
687
|
+
const inverts = dirs.get(invert) || [];
|
|
688
|
+
const directsLength = directs.length;
|
|
689
|
+
const invertsLength = inverts.length;
|
|
690
|
+
const total = directsLength + invertsLength;
|
|
691
|
+
directs.forEach((data, index) => {
|
|
692
|
+
points[anchors[data[edgeField]].source] = this.calcPoints(data, directsLength - 1 - index, total, -1);
|
|
693
|
+
});
|
|
694
|
+
caches[direct] = direct;
|
|
695
|
+
});
|
|
696
|
+
neo4j.targets.get(id)?.forEach((edge) => {
|
|
697
|
+
const source = edge[sourceField];
|
|
698
|
+
const target = edge[targetField];
|
|
699
|
+
const direct = this.getDir(source, target);
|
|
700
|
+
const invert = this.getDir(target, source);
|
|
701
|
+
if (direct in caches)
|
|
702
|
+
return;
|
|
703
|
+
const directs = neo4j.dirs.get(direct) || [];
|
|
704
|
+
const inverts = neo4j.dirs.get(invert) || [];
|
|
705
|
+
const directsLength = directs.length;
|
|
706
|
+
const invertsLength = inverts.length;
|
|
707
|
+
const total = directsLength + invertsLength;
|
|
708
|
+
directs.forEach((data, index) => {
|
|
709
|
+
points[anchors[data[edgeField]].target] = this.calcPoints(data, invertsLength + index, total, 1);
|
|
710
|
+
});
|
|
711
|
+
caches[direct] = direct;
|
|
712
|
+
});
|
|
713
|
+
return points;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* 查找边连接点的位置
|
|
717
|
+
*/
|
|
718
|
+
findAnchor(id) {
|
|
719
|
+
const anchor = this.#anchors[id];
|
|
720
|
+
if (!anchor)
|
|
721
|
+
return null;
|
|
722
|
+
return {
|
|
723
|
+
source: anchor.source || 0,
|
|
724
|
+
target: anchor.target || 0
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* 获取指定边控制点距离两端点连线的距离(可理解为控制边的弯曲程度)
|
|
729
|
+
* @description 返回值是一个相对值,需要乘以一个基数值(基数值应为负值,如-30)
|
|
730
|
+
*/
|
|
731
|
+
getOffset(id) {
|
|
732
|
+
const { neo4j } = this;
|
|
733
|
+
const edge = neo4j.edges.get(id);
|
|
734
|
+
if (!edge)
|
|
735
|
+
return -1;
|
|
736
|
+
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
737
|
+
const source = edge[sourceField];
|
|
738
|
+
const target = edge[targetField];
|
|
739
|
+
const directs = dirs.get(this.getDir(source, target)) || [];
|
|
740
|
+
const inverts = dirs.get(this.getDir(target, source)) || [];
|
|
741
|
+
let count = 0;
|
|
742
|
+
let index = 0;
|
|
743
|
+
[directs, inverts].some((list) => {
|
|
744
|
+
const result = list.some((data, i) => {
|
|
745
|
+
if (data[edgeField] === id) {
|
|
746
|
+
index = i + count;
|
|
747
|
+
return true;
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
count += list.length;
|
|
751
|
+
return result;
|
|
752
|
+
});
|
|
753
|
+
const directsSize = directs.length;
|
|
754
|
+
const invertsSize = inverts.length;
|
|
755
|
+
const total = directsSize + invertsSize;
|
|
756
|
+
if (total === 1)
|
|
757
|
+
return -1;
|
|
758
|
+
if (directsSize === 0 || invertsSize === 0) {
|
|
759
|
+
return total / 2 - index - 0.5;
|
|
760
|
+
} else {
|
|
761
|
+
return Math.abs(directsSize - invertsSize) * (directsSize >= invertsSize ? 1 : -1) / 2 - index - 0.5;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* 清理数据
|
|
766
|
+
*/
|
|
767
|
+
clear() {
|
|
768
|
+
this.#anchors = {};
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
594
772
|
// src/neo4j.ts
|
|
595
773
|
var Neo4j = class {
|
|
596
|
-
#
|
|
774
|
+
#nPrimaryKey;
|
|
775
|
+
#ePrimaryKey;
|
|
597
776
|
#sourceKey;
|
|
598
777
|
#targetKey;
|
|
778
|
+
#dirKey;
|
|
599
779
|
#nodes;
|
|
600
780
|
#edges;
|
|
601
781
|
#sources;
|
|
602
782
|
#targets;
|
|
603
783
|
#dirs;
|
|
784
|
+
get nodeField() {
|
|
785
|
+
return this.#nPrimaryKey;
|
|
786
|
+
}
|
|
787
|
+
get edgeField() {
|
|
788
|
+
return this.#ePrimaryKey;
|
|
789
|
+
}
|
|
790
|
+
get sourceField() {
|
|
791
|
+
return this.#sourceKey;
|
|
792
|
+
}
|
|
793
|
+
get targetField() {
|
|
794
|
+
return this.#targetKey;
|
|
795
|
+
}
|
|
796
|
+
get dirKey() {
|
|
797
|
+
return this.#dirKey;
|
|
798
|
+
}
|
|
604
799
|
/**
|
|
605
800
|
* 点视图
|
|
606
801
|
*/
|
|
@@ -626,13 +821,13 @@ var Neo4j = class {
|
|
|
626
821
|
eid,
|
|
627
822
|
sourceKey,
|
|
628
823
|
targetKey,
|
|
629
|
-
dir
|
|
824
|
+
dir = (edge) => edge[sourceKey] + "|" + edge[targetKey]
|
|
630
825
|
}) {
|
|
631
|
-
shield(this, "nodes", this.#nodes = new MemorySimple(this.#
|
|
632
|
-
shield(this, "edges", this.#edges = new MemorySimple(eid));
|
|
826
|
+
shield(this, "nodes", this.#nodes = new MemorySimple(this.#nPrimaryKey = nid));
|
|
827
|
+
shield(this, "edges", this.#edges = new MemorySimple(this.#ePrimaryKey = eid));
|
|
633
828
|
shield(this, "sources", this.#sources = new MemoryList(this.#sourceKey = sourceKey));
|
|
634
829
|
shield(this, "targets", this.#targets = new MemoryList(this.#targetKey = targetKey));
|
|
635
|
-
shield(this, "dirs", this.#dirs = new MemoryList(dir));
|
|
830
|
+
shield(this, "dirs", this.#dirs = new MemoryList(this.#dirKey = dir));
|
|
636
831
|
nodeList.forEach((node) => this.node("add", node));
|
|
637
832
|
edgeList.forEach((edge) => this.edge("add", edge));
|
|
638
833
|
}
|
|
@@ -645,7 +840,7 @@ var Neo4j = class {
|
|
|
645
840
|
if (!node)
|
|
646
841
|
return [];
|
|
647
842
|
nodes.delete(node);
|
|
648
|
-
const id = node[this.#
|
|
843
|
+
const id = node[this.#nPrimaryKey];
|
|
649
844
|
const sourceKey = this.#sourceKey;
|
|
650
845
|
const targetKey = this.#targetKey;
|
|
651
846
|
const edges = this.#edges;
|
|
@@ -775,16 +970,6 @@ var parseNum = (num) => {
|
|
|
775
970
|
}
|
|
776
971
|
};
|
|
777
972
|
|
|
778
|
-
// src/rotate/rad.ts
|
|
779
|
-
var rotateRad = (from, rad, visit = [0, 0]) => {
|
|
780
|
-
const x = from[0] - visit[0];
|
|
781
|
-
const y = from[1] - visit[1];
|
|
782
|
-
return [
|
|
783
|
-
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
784
|
-
y * Math.cos(rad) - x * Math.sin(rad) + visit[1]
|
|
785
|
-
];
|
|
786
|
-
};
|
|
787
|
-
|
|
788
973
|
// src/rotate/angle.ts
|
|
789
974
|
var rotateAngle = (from, angle, visit) => rotateRad(from, angle / 180 * Math.PI, visit);
|
|
790
975
|
|
package/lib/index.js
CHANGED
|
@@ -17,14 +17,15 @@ import { MemoryBasic } from "./memory/basic";
|
|
|
17
17
|
import { MemoryList } from "./memory/list";
|
|
18
18
|
import { MemoryPower } from "./memory/power";
|
|
19
19
|
import { MemorySimple } from "./memory/simple";
|
|
20
|
-
import { default as default2 } from "./neo4j";
|
|
20
|
+
import { default as default2 } from "./neo4j-anchors";
|
|
21
|
+
import { default as default3 } from "./neo4j";
|
|
21
22
|
import { once } from "./once";
|
|
22
23
|
import { parseNum } from "./parse/num";
|
|
23
24
|
import { deconPowersSum } from "./power/decon";
|
|
24
25
|
import { rotateAngle } from "./rotate/angle";
|
|
25
26
|
import { rotateRad } from "./rotate/rad";
|
|
26
27
|
import { css } from "./style/css";
|
|
27
|
-
import { default as
|
|
28
|
+
import { default as default4 } from "./subscriber";
|
|
28
29
|
import { FlexTable } from "./table/flex";
|
|
29
30
|
import { Union } from "./union";
|
|
30
31
|
import { joinPaths } from "./url/join";
|
|
@@ -36,8 +37,9 @@ export {
|
|
|
36
37
|
MemoryList,
|
|
37
38
|
MemoryPower,
|
|
38
39
|
MemorySimple,
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
default3 as Neo4j,
|
|
41
|
+
default2 as Neo4jAhchors,
|
|
42
|
+
default4 as Subscriber,
|
|
41
43
|
Union,
|
|
42
44
|
clamp,
|
|
43
45
|
classnames,
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { rotateRad } from "./rotate/rad";
|
|
2
|
+
class Neo4jAhchors {
|
|
3
|
+
constructor(neo4j, config) {
|
|
4
|
+
this.neo4j = neo4j;
|
|
5
|
+
this.config = Object.assign({}, config);
|
|
6
|
+
}
|
|
7
|
+
config;
|
|
8
|
+
#anchors = {};
|
|
9
|
+
getDir(start, end) {
|
|
10
|
+
const { neo4j } = this;
|
|
11
|
+
return neo4j.dirKey({
|
|
12
|
+
[neo4j.sourceField]: start,
|
|
13
|
+
[neo4j.targetField]: end
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 当图数据准备好后调用
|
|
18
|
+
*/
|
|
19
|
+
read() {
|
|
20
|
+
const { neo4j } = this;
|
|
21
|
+
const { nodeField, edgeField, sourceField, targetField } = neo4j;
|
|
22
|
+
const anchors = {};
|
|
23
|
+
neo4j.nodes.forEach((node) => {
|
|
24
|
+
const nodeId = node[nodeField];
|
|
25
|
+
let count = 0;
|
|
26
|
+
[
|
|
27
|
+
neo4j.sources.get(nodeId),
|
|
28
|
+
neo4j.targets.get(nodeId)
|
|
29
|
+
].forEach((list, i) => {
|
|
30
|
+
if (!list)
|
|
31
|
+
return;
|
|
32
|
+
let diffCount = 0;
|
|
33
|
+
let sameCount = 0;
|
|
34
|
+
list.forEach((edge) => {
|
|
35
|
+
const edgeId = edge[edgeField];
|
|
36
|
+
if (edge[sourceField] !== edge[targetField]) {
|
|
37
|
+
const anchor = anchors[edgeId] || (anchors[edgeId] = {});
|
|
38
|
+
anchor[i ? "target" : "source"] = count + diffCount++;
|
|
39
|
+
} else if (edgeId in anchors === false) {
|
|
40
|
+
anchors[edgeId] = {
|
|
41
|
+
source: sameCount,
|
|
42
|
+
target: sameCount++
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
count += diffCount;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
this.#anchors = anchors;
|
|
50
|
+
}
|
|
51
|
+
calcPoints(edge, index, total, type) {
|
|
52
|
+
const { neo4j, config: { getBox, radOffsetRaidx = 0.3125 } } = this;
|
|
53
|
+
const source = getBox(edge[neo4j.sourceField]);
|
|
54
|
+
const target = getBox(edge[neo4j.targetField]);
|
|
55
|
+
const rad = Math.atan2(
|
|
56
|
+
(source.centerY - target.centerY) * type,
|
|
57
|
+
(source.centerX - target.centerX) * type
|
|
58
|
+
);
|
|
59
|
+
let point = rotateRad([0.5, 0], rad);
|
|
60
|
+
if (total !== 1) {
|
|
61
|
+
point = rotateRad(point, radOffsetRaidx * (total / 2 - 0.5 - index));
|
|
62
|
+
}
|
|
63
|
+
const [x, y] = point;
|
|
64
|
+
return [x + 0.5, 0.5 - y];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 获取指定节点上出入边连接点的坐标
|
|
68
|
+
*/
|
|
69
|
+
getPoints(id) {
|
|
70
|
+
const { neo4j } = this;
|
|
71
|
+
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
72
|
+
const anchors = this.#anchors;
|
|
73
|
+
const points = [];
|
|
74
|
+
const caches = {};
|
|
75
|
+
neo4j.sources.get(id)?.forEach((edge) => {
|
|
76
|
+
const source = edge[sourceField];
|
|
77
|
+
const target = edge[targetField];
|
|
78
|
+
const direct = this.getDir(source, target);
|
|
79
|
+
const invert = this.getDir(target, source);
|
|
80
|
+
if (direct in caches)
|
|
81
|
+
return;
|
|
82
|
+
const directs = dirs.get(direct) || [];
|
|
83
|
+
const inverts = dirs.get(invert) || [];
|
|
84
|
+
const directsLength = directs.length;
|
|
85
|
+
const invertsLength = inverts.length;
|
|
86
|
+
const total = directsLength + invertsLength;
|
|
87
|
+
directs.forEach((data, index) => {
|
|
88
|
+
points[anchors[data[edgeField]].source] = this.calcPoints(data, directsLength - 1 - index, total, -1);
|
|
89
|
+
});
|
|
90
|
+
caches[direct] = direct;
|
|
91
|
+
});
|
|
92
|
+
neo4j.targets.get(id)?.forEach((edge) => {
|
|
93
|
+
const source = edge[sourceField];
|
|
94
|
+
const target = edge[targetField];
|
|
95
|
+
const direct = this.getDir(source, target);
|
|
96
|
+
const invert = this.getDir(target, source);
|
|
97
|
+
if (direct in caches)
|
|
98
|
+
return;
|
|
99
|
+
const directs = neo4j.dirs.get(direct) || [];
|
|
100
|
+
const inverts = neo4j.dirs.get(invert) || [];
|
|
101
|
+
const directsLength = directs.length;
|
|
102
|
+
const invertsLength = inverts.length;
|
|
103
|
+
const total = directsLength + invertsLength;
|
|
104
|
+
directs.forEach((data, index) => {
|
|
105
|
+
points[anchors[data[edgeField]].target] = this.calcPoints(data, invertsLength + index, total, 1);
|
|
106
|
+
});
|
|
107
|
+
caches[direct] = direct;
|
|
108
|
+
});
|
|
109
|
+
return points;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 查找边连接点的位置
|
|
113
|
+
*/
|
|
114
|
+
findAnchor(id) {
|
|
115
|
+
const anchor = this.#anchors[id];
|
|
116
|
+
if (!anchor)
|
|
117
|
+
return null;
|
|
118
|
+
return {
|
|
119
|
+
source: anchor.source || 0,
|
|
120
|
+
target: anchor.target || 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 获取指定边控制点距离两端点连线的距离(可理解为控制边的弯曲程度)
|
|
125
|
+
* @description 返回值是一个相对值,需要乘以一个基数值(基数值应为负值,如-30)
|
|
126
|
+
*/
|
|
127
|
+
getOffset(id) {
|
|
128
|
+
const { neo4j } = this;
|
|
129
|
+
const edge = neo4j.edges.get(id);
|
|
130
|
+
if (!edge)
|
|
131
|
+
return -1;
|
|
132
|
+
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
133
|
+
const source = edge[sourceField];
|
|
134
|
+
const target = edge[targetField];
|
|
135
|
+
const directs = dirs.get(this.getDir(source, target)) || [];
|
|
136
|
+
const inverts = dirs.get(this.getDir(target, source)) || [];
|
|
137
|
+
let count = 0;
|
|
138
|
+
let index = 0;
|
|
139
|
+
[directs, inverts].some((list) => {
|
|
140
|
+
const result = list.some((data, i) => {
|
|
141
|
+
if (data[edgeField] === id) {
|
|
142
|
+
index = i + count;
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
count += list.length;
|
|
147
|
+
return result;
|
|
148
|
+
});
|
|
149
|
+
const directsSize = directs.length;
|
|
150
|
+
const invertsSize = inverts.length;
|
|
151
|
+
const total = directsSize + invertsSize;
|
|
152
|
+
if (total === 1)
|
|
153
|
+
return -1;
|
|
154
|
+
if (directsSize === 0 || invertsSize === 0) {
|
|
155
|
+
return total / 2 - index - 0.5;
|
|
156
|
+
} else {
|
|
157
|
+
return Math.abs(directsSize - invertsSize) * (directsSize >= invertsSize ? 1 : -1) / 2 - index - 0.5;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 清理数据
|
|
162
|
+
*/
|
|
163
|
+
clear() {
|
|
164
|
+
this.#anchors = {};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
Neo4jAhchors as default
|
|
169
|
+
};
|
package/lib/neo4j.js
CHANGED
|
@@ -2,14 +2,31 @@ import { hash8strings } from "./convert/strings";
|
|
|
2
2
|
import { MemoryList } from "./memory/list";
|
|
3
3
|
import { MemorySimple } from "./memory/simple";
|
|
4
4
|
class Neo4j {
|
|
5
|
-
#
|
|
5
|
+
#nPrimaryKey;
|
|
6
|
+
#ePrimaryKey;
|
|
6
7
|
#sourceKey;
|
|
7
8
|
#targetKey;
|
|
9
|
+
#dirKey;
|
|
8
10
|
#nodes;
|
|
9
11
|
#edges;
|
|
10
12
|
#sources;
|
|
11
13
|
#targets;
|
|
12
14
|
#dirs;
|
|
15
|
+
get nodeField() {
|
|
16
|
+
return this.#nPrimaryKey;
|
|
17
|
+
}
|
|
18
|
+
get edgeField() {
|
|
19
|
+
return this.#ePrimaryKey;
|
|
20
|
+
}
|
|
21
|
+
get sourceField() {
|
|
22
|
+
return this.#sourceKey;
|
|
23
|
+
}
|
|
24
|
+
get targetField() {
|
|
25
|
+
return this.#targetKey;
|
|
26
|
+
}
|
|
27
|
+
get dirKey() {
|
|
28
|
+
return this.#dirKey;
|
|
29
|
+
}
|
|
13
30
|
/**
|
|
14
31
|
* 点视图
|
|
15
32
|
*/
|
|
@@ -35,13 +52,13 @@ class Neo4j {
|
|
|
35
52
|
eid,
|
|
36
53
|
sourceKey,
|
|
37
54
|
targetKey,
|
|
38
|
-
dir
|
|
55
|
+
dir = (edge) => edge[sourceKey] + "|" + edge[targetKey]
|
|
39
56
|
}) {
|
|
40
|
-
shield(this, "nodes", this.#nodes = new MemorySimple(this.#
|
|
41
|
-
shield(this, "edges", this.#edges = new MemorySimple(eid));
|
|
57
|
+
shield(this, "nodes", this.#nodes = new MemorySimple(this.#nPrimaryKey = nid));
|
|
58
|
+
shield(this, "edges", this.#edges = new MemorySimple(this.#ePrimaryKey = eid));
|
|
42
59
|
shield(this, "sources", this.#sources = new MemoryList(this.#sourceKey = sourceKey));
|
|
43
60
|
shield(this, "targets", this.#targets = new MemoryList(this.#targetKey = targetKey));
|
|
44
|
-
shield(this, "dirs", this.#dirs = new MemoryList(dir));
|
|
61
|
+
shield(this, "dirs", this.#dirs = new MemoryList(this.#dirKey = dir));
|
|
45
62
|
nodeList.forEach((node) => this.node("add", node));
|
|
46
63
|
edgeList.forEach((edge) => this.edge("add", edge));
|
|
47
64
|
}
|
|
@@ -54,7 +71,7 @@ class Neo4j {
|
|
|
54
71
|
if (!node)
|
|
55
72
|
return [];
|
|
56
73
|
nodes.delete(node);
|
|
57
|
-
const id = node[this.#
|
|
74
|
+
const id = node[this.#nPrimaryKey];
|
|
58
75
|
const sourceKey = this.#sourceKey;
|
|
59
76
|
const targetKey = this.#targetKey;
|
|
60
77
|
const edges = this.#edges;
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export { MemoryBasic } from './memory/basic';
|
|
|
17
17
|
export { MemoryList } from './memory/list';
|
|
18
18
|
export { MemoryPower } from './memory/power';
|
|
19
19
|
export { MemorySimple } from './memory/simple';
|
|
20
|
+
export { default as Neo4jAhchors } from './neo4j-anchors';
|
|
20
21
|
export { default as Neo4j } from './neo4j';
|
|
21
22
|
export { once } from './once';
|
|
22
23
|
export { parseNum } from './parse/num';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Neo4j from './neo4j';
|
|
2
|
+
interface IBox {
|
|
3
|
+
centerX: number;
|
|
4
|
+
centerY: number;
|
|
5
|
+
}
|
|
6
|
+
interface Config {
|
|
7
|
+
radOffsetRaidx?: number;
|
|
8
|
+
getBox(id: string): IBox;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 图布局之二阶贝塞尔曲线边锚点管理
|
|
12
|
+
*/
|
|
13
|
+
export default class Neo4jAhchors<INode extends object, IEdge extends object> {
|
|
14
|
+
#private;
|
|
15
|
+
protected neo4j: Neo4j<INode, IEdge>;
|
|
16
|
+
protected config: Config;
|
|
17
|
+
constructor(neo4j: Neo4j<INode, IEdge>, config: Config);
|
|
18
|
+
protected getDir(start: string, end: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* 当图数据准备好后调用
|
|
21
|
+
*/
|
|
22
|
+
read(): void;
|
|
23
|
+
protected calcPoints(edge: IEdge, index: number, total: number, type: 1 | -1): number[];
|
|
24
|
+
/**
|
|
25
|
+
* 获取指定节点上出入边连接点的坐标
|
|
26
|
+
*/
|
|
27
|
+
getPoints(id: string): number[][];
|
|
28
|
+
/**
|
|
29
|
+
* 查找边连接点的位置
|
|
30
|
+
*/
|
|
31
|
+
findAnchor(id: string): {
|
|
32
|
+
source: number;
|
|
33
|
+
target: number;
|
|
34
|
+
} | null;
|
|
35
|
+
/**
|
|
36
|
+
* 获取指定边控制点距离两端点连线的距离(可理解为控制边的弯曲程度)
|
|
37
|
+
* @description 返回值是一个相对值,需要乘以一个基数值(基数值应为负值,如-30)
|
|
38
|
+
*/
|
|
39
|
+
getOffset(id: string): number;
|
|
40
|
+
/**
|
|
41
|
+
* 清理数据
|
|
42
|
+
*/
|
|
43
|
+
clear(): void;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/types/neo4j.d.ts
CHANGED
|
@@ -3,17 +3,37 @@ import { GetGivenProps } from '@vope/types';
|
|
|
3
3
|
import { MemoryList } from './memory/list';
|
|
4
4
|
import { MemorySimple } from './memory/simple';
|
|
5
5
|
interface Config<INode extends object, IEdge extends object> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* 点主键字段
|
|
8
|
+
*/
|
|
9
|
+
nid: Extract<GetGivenProps<INode, string>, string>;
|
|
10
|
+
/**
|
|
11
|
+
* 边主键字段
|
|
12
|
+
*/
|
|
13
|
+
eid: Extract<GetGivenProps<IEdge, string>, string>;
|
|
14
|
+
/**
|
|
15
|
+
* (边)出点字段
|
|
16
|
+
*/
|
|
17
|
+
sourceKey: Extract<GetGivenProps<IEdge, string>, string>;
|
|
18
|
+
/**
|
|
19
|
+
* (边)入点字段
|
|
20
|
+
*/
|
|
21
|
+
targetKey: Extract<GetGivenProps<IEdge, string>, string>;
|
|
22
|
+
/**
|
|
23
|
+
* (边)方向键
|
|
24
|
+
*/
|
|
25
|
+
dir?(edge: IEdge): string;
|
|
11
26
|
}
|
|
12
27
|
/**
|
|
13
28
|
* 图管理
|
|
14
29
|
*/
|
|
15
30
|
export default class Neo4j<INode extends object, IEdge extends object> {
|
|
16
31
|
#private;
|
|
32
|
+
get nodeField(): keyof INode;
|
|
33
|
+
get edgeField(): keyof IEdge;
|
|
34
|
+
get sourceField(): keyof IEdge;
|
|
35
|
+
get targetField(): keyof IEdge;
|
|
36
|
+
get dirKey(): (edge: IEdge) => string;
|
|
17
37
|
/**
|
|
18
38
|
* 点视图
|
|
19
39
|
*/
|
|
@@ -57,6 +77,6 @@ declare const shield_keys: {
|
|
|
57
77
|
deleteType: number;
|
|
58
78
|
};
|
|
59
79
|
type Shield<T> = {
|
|
60
|
-
[P in Exclude<keyof T, keyof typeof shield_keys>]: T[P] extends (...args: infer A) => infer B ? Equal<B, T> extends true ? (...args: A) => Shield<T> : T[P] : T[P];
|
|
80
|
+
[P in Exclude<keyof T, keyof typeof shield_keys>]: T[P] extends (...args: infer A) => infer B ? Equal<[B], [T]> extends true ? (...args: A) => Shield<T> : T[P] : T[P];
|
|
61
81
|
};
|
|
62
82
|
export {};
|