react-kggraph 0.0.17 → 0.0.18

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 (42) hide show
  1. package/README.md +46 -0
  2. package/lib/index.es.js +8 -6
  3. package/lib/index.es10.js +186 -69
  4. package/lib/index.es11.js +71 -28
  5. package/lib/index.es12.js +29 -69
  6. package/lib/index.es13.js +70 -224
  7. package/lib/index.es14.js +224 -4
  8. package/lib/index.es15.js +4 -35
  9. package/lib/index.es16.js +37 -0
  10. package/lib/index.es18.js +15462 -49
  11. package/lib/index.es19.js +50 -56
  12. package/lib/index.es20.js +57 -66
  13. package/lib/index.es21.js +68 -39
  14. package/lib/index.es22.js +40 -2
  15. package/lib/index.es23.js +1 -1
  16. package/lib/index.es24.js +2 -2
  17. package/lib/index.es25.js +1 -1
  18. package/lib/index.es26.js +1 -1
  19. package/lib/index.es27.js +1 -1
  20. package/lib/index.es28.js +1 -1
  21. package/lib/index.es29.js +1 -1
  22. package/lib/index.es3.js +173 -155
  23. package/lib/index.es30.js +1 -1
  24. package/lib/index.es31.js +1 -1
  25. package/lib/index.es32.js +2 -2
  26. package/lib/index.es33.js +4 -0
  27. package/lib/index.es35.js +4 -2
  28. package/lib/index.es36.js +4 -0
  29. package/lib/index.es4.js +17 -6
  30. package/lib/index.es5.js +6 -2
  31. package/lib/index.es6.js +2 -599
  32. package/lib/index.es7.js +580 -312
  33. package/lib/index.es8.js +294 -393
  34. package/lib/index.es9.js +408 -173
  35. package/lib/src/components/Graph/components/ActionBar/actionList.d.ts +10 -0
  36. package/lib/src/components/Graph/components/ActionBar/index.d.ts +15 -0
  37. package/lib/src/components/Graph/types.d.ts +51 -0
  38. package/lib/src/components/Graph/utils/edge_node_styles.d.ts +5 -2
  39. package/lib/style.css +1 -1
  40. package/package.json +1 -1
  41. package/lib/index.es17.js +0 -15469
  42. package/lib/index.es34.js +0 -6
package/README.md CHANGED
@@ -125,6 +125,7 @@ const App = () => {
125
125
  | graphInfo | `GraphInfo` | ❌ | 图谱配置信息 |
126
126
  | stepNextApi | `(params: any) => Promise<any>` | ❌ | 下一步API(用于知识图谱展开) |
127
127
  | knowledgeCardApi | `(params: any) => Promise<any>` | ❌ | 知识卡片API |
128
+ | colors | `GraphColors` | ❌ | 颜色配置 |
128
129
 
129
130
  ## 类型定义
130
131
 
@@ -167,6 +168,51 @@ interface GraphInfo {
167
168
  }
168
169
  ```
169
170
 
171
+ ### GraphColors(颜色配置)
172
+
173
+ ```typescript
174
+ interface GraphColors {
175
+ /** 节点标签文字颜色,默认 #000 */
176
+ nodeLabelColor?: string;
177
+ /** 节点标签文字大小,默认 18 */
178
+ nodeLabelFontSize?: number;
179
+ /** 边标签文字颜色,默认 #666 */
180
+ edgeLabelColor?: string;
181
+ /** 边标签文字大小,默认 18 */
182
+ edgeLabelFontSize?: number;
183
+ /** URI类型节点背景色,默认 #f7de63 */
184
+ uriNodeColor?: string;
185
+ /** 普通节点背景色,默认 #1890FF */
186
+ normalNodeColor?: string;
187
+ /** 节点边框悬停颜色,默认 #0d6ac2 */
188
+ nodeBorderHoverColor?: string;
189
+ /** 边默认颜色,默认 #a29e9e */
190
+ edgeDefaultColor?: string;
191
+ /** 边悬停颜色,默认 #1890ff */
192
+ edgeHoverColor?: string;
193
+ /** 路径高亮颜色,默认 #145AFD */
194
+ pathHighlightColor?: string;
195
+ /** 路径节点颜色,默认 #145AFD */
196
+ pathNodeColor?: string;
197
+ }
198
+ ```
199
+
200
+ ### 颜色配置示例
201
+
202
+ ```tsx
203
+ <CytoscapeReact
204
+ data={data}
205
+ colors={{
206
+ nodeLabelColor: '#333',
207
+ edgeLabelColor: '#999',
208
+ normalNodeColor: '#52c41a',
209
+ uriNodeColor: '#faad14',
210
+ edgeDefaultColor: '#d9d9d9',
211
+ pathHighlightColor: '#f5222d',
212
+ }}
213
+ />
214
+ ```
215
+
170
216
  ## 图谱布局
171
217
 
172
218
  组件支持多种布局算法:
package/lib/index.es.js CHANGED
@@ -1,9 +1,11 @@
1
1
  /* empty css */
2
- import { default as t } from "./index.es3.js";
3
- import { default as p } from "./index.es4.js";
4
- import { SearchType as m } from "./index.es5.js";
2
+ import { default as r } from "./index.es3.js";
3
+ import { actionList as p } from "./index.es4.js";
4
+ import { default as m } from "./index.es5.js";
5
+ import { SearchType as s } from "./index.es6.js";
5
6
  export {
6
- t as CytoscapeReact,
7
- p as Demo,
8
- m as SearchType
7
+ r as CytoscapeReact,
8
+ m as Demo,
9
+ s as SearchType,
10
+ p as actionList
9
11
  };
package/lib/index.es10.js CHANGED
@@ -1,75 +1,192 @@
1
- const i = ({ cyRef: n, setContextMenu: r, onPathAnalysis: l, setPathNodes: s }) => [
2
- {
3
- label: "展收实体",
4
- ids: "contract",
5
- action: (e) => {
6
- const o = n.current;
7
- console.log("新增属性", o);
1
+ const g = {
2
+ nodeLabelColor: "#000",
3
+ nodeLabelFontSize: 18,
4
+ edgeLabelColor: "#666",
5
+ edgeLabelFontSize: 18,
6
+ uriNodeColor: "#f7de63",
7
+ // 节点类型为uri的节点颜色,默认节点颜色
8
+ normalNodeColor: "#1890FF",
9
+ nodeBorderHoverColor: "#0d6ac2",
10
+ //节点hover边框效果
11
+ edgeDefaultColor: "#a29e9e",
12
+ //连线颜色
13
+ edgeHoverColor: "#145AFD",
14
+ //边悬停颜色
15
+ pathHighlightColor: "#145AFD",
16
+ //路径高亮颜色
17
+ pathNodeColor: "#145AFD"
18
+ //路径节点颜色-不生效
19
+ }, h = ({ elements: c, colors: n = {} }) => {
20
+ const e = { ...g, ...n }, l = [], t = 80;
21
+ c.map((o) => {
22
+ var a, d, i;
23
+ !l.includes((a = o == null ? void 0 : o.data) == null ? void 0 : a.type) && ((d = o == null ? void 0 : o.data) != null && d.type) && l.push((i = o.data) == null ? void 0 : i.type);
24
+ });
25
+ const r = [];
26
+ r.push({
27
+ selector: '[properties-type="uri"]',
28
+ style: {
29
+ "background-color": e.uriNodeColor,
30
+ "background-image": "data(image)",
31
+ "background-fit": "cover",
32
+ width: t,
33
+ height: t,
34
+ label: "data(name)",
35
+ color: e.nodeLabelColor,
36
+ "text-valign": "bottom",
37
+ "font-size": e.nodeLabelFontSize,
38
+ "text-max-width": "250px",
39
+ "text-wrap": "ellipsis",
40
+ "text-overflow-wrap": "anywhere"
8
41
  }
9
- },
10
- {
11
- label: "展收属性",
12
- ids: "expanded",
13
- action: (e) => {
14
- if (console.log("展开", e), !n.current) {
15
- console.error("Cytoscape instance is not available");
16
- return;
17
- }
18
- console.log("New node and edge added");
19
- }
20
- },
21
- {
22
- label: "节点信息",
23
- ids: "nodeInfo",
24
- action: (e) => {
25
- console.log("节点信息:", e);
26
- }
27
- },
28
- {
29
- label: "知识卡片",
30
- ids: "knowledgeCard",
31
- action: (e) => {
32
- const o = n.current;
33
- console.log("知识卡片", o);
42
+ }), r.push({
43
+ selector: '[properties-type!="uri"]',
44
+ style: {
45
+ "background-color": e.normalNodeColor,
46
+ "background-image": "data(image)",
47
+ "background-fit": "cover",
48
+ width: t,
49
+ height: t,
50
+ label: "data(name)",
51
+ color: e.nodeLabelColor,
52
+ "text-valign": "bottom",
53
+ "font-size": e.nodeLabelFontSize,
54
+ "text-max-width": "250px",
55
+ "text-wrap": "ellipsis",
56
+ "text-overflow-wrap": "anywhere"
34
57
  }
35
- },
36
- // {
37
- // label: '新增关系',
38
- // action: (node) => {
39
- // const cy = cyRef.current;
40
- // console.log('新增关系', cy)
41
- // },
42
- // },
43
- {
44
- label: "选中关联",
45
- ids: "selRelate",
46
- action: (e) => {
47
- const o = n.current;
48
- if (!o || !e || e.removed()) {
49
- console.error("节点或Cytoscape实例无效"), r((t) => ({ ...t, visible: !1 }));
50
- return;
58
+ });
59
+ const s = [
60
+ {
61
+ selector: "node",
62
+ style: {
63
+ "text-margin-y": "5px"
64
+ }
65
+ },
66
+ {
67
+ selector: "edge",
68
+ style: {
69
+ "line-color": e.edgeDefaultColor,
70
+ "target-arrow-color": e.edgeDefaultColor,
71
+ opacity: 1,
72
+ "target-arrow-shape": "triangle",
73
+ width: 2,
74
+ "curve-style": "bezier",
75
+ "transition-property": "line-color, target-arrow-color, opacity",
76
+ "transition-duration": "0.2s",
77
+ label: "data(name)",
78
+ "z-index": 9999,
79
+ "text-opacity": 1,
80
+ "font-size": e.edgeLabelFontSize,
81
+ color: e.edgeLabelColor,
82
+ "text-background-color": "#fff",
83
+ "text-background-opacity": 1,
84
+ "text-background-shape": "roundrectangle",
85
+ "text-background-padding": "3px"
86
+ }
87
+ },
88
+ {
89
+ selector: ".highlight",
90
+ style: {
91
+ "border-color": "rgba(174, 255, 45, 0.2)",
92
+ "border-width": 4
93
+ }
94
+ },
95
+ {
96
+ selector: ".path-node",
97
+ style: {
98
+ "background-color": e.pathNodeColor,
99
+ "border-color": e.pathNodeColor,
100
+ "border-width": 2
101
+ }
102
+ },
103
+ {
104
+ selector: ".path-edge",
105
+ style: {
106
+ "line-color": e.pathHighlightColor,
107
+ "target-arrow-color": e.pathHighlightColor,
108
+ width: 4,
109
+ "border-width": 2,
110
+ "border-color": e.pathHighlightColor
111
+ }
112
+ },
113
+ {
114
+ selector: ".grayed",
115
+ style: {
116
+ opacity: 0.15,
117
+ "text-opacity": 0.15
118
+ }
119
+ },
120
+ {
121
+ selector: "node.selected, edge.selected",
122
+ style: {
123
+ "border-color": "rgba(174, 255, 45, 0.2)",
124
+ "border-width": 4
125
+ }
126
+ },
127
+ {
128
+ selector: ".correlationStyle",
129
+ style: {
130
+ width: 60,
131
+ height: 60,
132
+ "outline-width": "10px",
133
+ "outline-color": "rgba(188, 220, 255, 0.4)",
134
+ "outline-style": "solid",
135
+ "line-opacity": "0.2",
136
+ "outline-offset": "2px",
137
+ filter: "blur(20px)",
138
+ "z-index": 9999
139
+ }
140
+ },
141
+ {
142
+ selector: ".hover",
143
+ style: {
144
+ "border-width": 3,
145
+ "border-color": e.nodeBorderHoverColor
146
+ }
147
+ },
148
+ // 层级分析样式 - 目标节点
149
+ {
150
+ selector: ".level-selected",
151
+ style: {
152
+ "background-color": "#f8bbd0",
153
+ "border-color": "#e91e63",
154
+ "border-width": 4,
155
+ color: "#880e4f"
156
+ }
157
+ },
158
+ // 层级分析样式 - 关联节点
159
+ {
160
+ selector: ".level-highlight",
161
+ style: {
162
+ "background-color": "#bbdefb",
163
+ "border-color": "#2196f3",
164
+ "border-width": 3,
165
+ color: "#0d47a1"
166
+ }
167
+ },
168
+ // 层级分析样式 - 边高亮
169
+ {
170
+ selector: ".level-highlightedge",
171
+ style: {
172
+ "line-color": "#1976d2",
173
+ "target-arrow-color": "#1976d2",
174
+ width: 3,
175
+ opacity: 1
176
+ }
177
+ },
178
+ // 层级分析样式 - 置灰
179
+ {
180
+ selector: ".level-grayed",
181
+ style: {
182
+ opacity: 0.15,
183
+ "text-opacity": 0.15
51
184
  }
52
- const d = e, c = d.neighborhood().nodes().add(d);
53
- c.edgesWith(c), o.nodes().not(c).removeClass("correlationStyle"), c.addClass("correlationStyle"), r((t) => ({ ...t, visible: !1 }));
54
- }
55
- },
56
- {
57
- label: "路径分析",
58
- action: (e) => {
59
- n.current, console.log(11, e.data("name")), l == null || l(), s([e.data("name"), ""]);
60
185
  }
61
- }
62
- // {
63
- // label: '删除节点',
64
- // action: (node) => {
65
- // const cy = cyRef.current;
66
- // console.log('删除节点cy::::', cy)
67
- // if (node && !node.removed()) {
68
- // node.remove();
69
- // }
70
- // },
71
- // },
72
- ];
186
+ ];
187
+ return r.concat(s);
188
+ };
73
189
  export {
74
- i as menuItemsConfig
190
+ g as defaultColors,
191
+ h as edgeNodeStyles
75
192
  };
package/lib/index.es11.js CHANGED
@@ -1,32 +1,75 @@
1
- const t = (r) => {
2
- if (n(r) || Array.isArray(r))
3
- try {
4
- return JSON.stringify(r);
5
- } catch (e) {
6
- console.log("JSON.stringify", e);
1
+ const i = ({ cyRef: n, setContextMenu: r, onPathAnalysis: l, setPathNodes: s }) => [
2
+ {
3
+ label: "展收实体",
4
+ ids: "contract",
5
+ action: (e) => {
6
+ const o = n.current;
7
+ console.log("新增属性", o);
7
8
  }
8
- else
9
- return r;
10
- }, c = (r) => {
11
- if (n(r) || Array.isArray(r))
12
- try {
13
- return JSON.parse(JSON.stringify(r));
14
- } catch (e) {
15
- console.log("JSON.stringify-JSON.parse", e);
9
+ },
10
+ {
11
+ label: "展收属性",
12
+ ids: "expanded",
13
+ action: (e) => {
14
+ if (console.log("展开", e), !n.current) {
15
+ console.error("Cytoscape instance is not available");
16
+ return;
17
+ }
18
+ console.log("New node and edge added");
16
19
  }
17
- else
18
- return r;
19
- };
20
- function n(r) {
21
- return r !== null && typeof r == "object" && !Array.isArray(r);
22
- }
23
- const i = (r, e) => {
24
- const o = document.createElement("a");
25
- o.href = r, o.download = e, document.body.appendChild(o), o.click(), document.body.removeChild(o);
26
- };
20
+ },
21
+ {
22
+ label: "节点信息",
23
+ ids: "nodeInfo",
24
+ action: (e) => {
25
+ console.log("节点信息:", e);
26
+ }
27
+ },
28
+ {
29
+ label: "知识卡片",
30
+ ids: "knowledgeCard",
31
+ action: (e) => {
32
+ const o = n.current;
33
+ console.log("知识卡片", o);
34
+ }
35
+ },
36
+ // {
37
+ // label: '新增关系',
38
+ // action: (node) => {
39
+ // const cy = cyRef.current;
40
+ // console.log('新增关系', cy)
41
+ // },
42
+ // },
43
+ {
44
+ label: "选中关联",
45
+ ids: "selRelate",
46
+ action: (e) => {
47
+ const o = n.current;
48
+ if (!o || !e || e.removed()) {
49
+ console.error("节点或Cytoscape实例无效"), r((t) => ({ ...t, visible: !1 }));
50
+ return;
51
+ }
52
+ const d = e, c = d.neighborhood().nodes().add(d);
53
+ c.edgesWith(c), o.nodes().not(c).removeClass("correlationStyle"), c.addClass("correlationStyle"), r((t) => ({ ...t, visible: !1 }));
54
+ }
55
+ },
56
+ {
57
+ label: "路径分析",
58
+ action: (e) => {
59
+ n.current, console.log(11, e.data("name")), l == null || l(), s([e.data("name"), ""]);
60
+ }
61
+ }
62
+ // {
63
+ // label: '删除节点',
64
+ // action: (node) => {
65
+ // const cy = cyRef.current;
66
+ // console.log('删除节点cy::::', cy)
67
+ // if (node && !node.removed()) {
68
+ // node.remove();
69
+ // }
70
+ // },
71
+ // },
72
+ ];
27
73
  export {
28
- i as downloadFile,
29
- n as isObject,
30
- t as jsonStringify,
31
- c as jsonStringifyParse
74
+ i as menuItemsConfig
32
75
  };
package/lib/index.es12.js CHANGED
@@ -1,72 +1,32 @@
1
- import { jsxs as d, jsx as e } from "react/jsx-runtime";
2
- import { useMemo as b } from "react";
3
- /* empty css */
4
- const L = ({
5
- items: h = [
6
- // { label: '知识卡片' },
7
- // { label: '选中关联' },
8
- // { label: '路径分析' },
9
- // { label: '展收实体' },
10
- // { label: '展收属性' },
11
- // { label: '节点配置' },
12
- ],
13
- centerImage: f,
14
- size: c = 200,
15
- onClick: $
16
- }) => {
17
- const t = c / 2, a = c / 2 - 10, s = 30, o = 360 / h.length, p = b(() => h.map((n, r) => {
18
- const l = (r * o - 90) * (Math.PI / 180), i = ((r + 1) * o - 90) * (Math.PI / 180), m = ((r + 0.5) * o - 90) * (Math.PI / 180), y = t + a * Math.cos(l), v = t + a * Math.sin(l), w = t + a * Math.cos(i), A = t + a * Math.sin(i), N = t + s * Math.cos(i), k = t + s * Math.sin(i), u = t + s * Math.cos(l), x = t + s * Math.sin(l), g = o > 180 ? 1 : 0, I = `M ${u} ${x} L ${y} ${v} A ${a} ${a} 0 ${g} 1 ${w} ${A} L ${N} ${k} A ${s} ${s} 0 ${g} 0 ${u} ${x}`, M = (a + s) / 2 + 5, P = t + M * Math.cos(m), R = t + M * Math.sin(m);
19
- return {
20
- ...n,
21
- path: I,
22
- textX: P,
23
- textY: R,
24
- rotation: (r + 0.5) * o - 90
25
- };
26
- }), [h, o, t, a, s]);
27
- return /* @__PURE__ */ d("div", { className: "radial-menu", style: { width: c, height: c }, children: [
28
- /* @__PURE__ */ d("svg", { width: c, height: c, className: "radial-svg", children: [
29
- /* @__PURE__ */ e("defs", { children: /* @__PURE__ */ e("filter", { id: "shadow", x: "-20%", y: "-20%", width: "140%", height: "140%", children: /* @__PURE__ */ e("feDropShadow", { dx: "0", dy: "2", stdDeviation: "3", floodOpacity: "0.3" }) }) }),
30
- /* @__PURE__ */ e("circle", { cx: t, cy: t, r: a, fill: "#f5f5f5", stroke: "#ddd", strokeWidth: "1" }),
31
- p.map((n, r) => /* @__PURE__ */ d("g", { onClick: () => $(n), className: "sector-group", children: [
32
- /* @__PURE__ */ e(
33
- "path",
34
- {
35
- d: n.path,
36
- fill: "#333",
37
- stroke: "rgb(185, 185, 185)",
38
- strokeWidth: "1",
39
- filter: "url(#shadow)",
40
- className: "sector-path"
41
- }
42
- ),
43
- /* @__PURE__ */ e(
44
- "text",
45
- {
46
- x: n.textX,
47
- y: n.textY,
48
- textAnchor: "middle",
49
- dominantBaseline: "middle",
50
- fill: "#fff",
51
- fontSize: "12",
52
- fontWeight: "500",
53
- className: "sector-label",
54
- children: n.label
55
- }
56
- )
57
- ] }, r)),
58
- /* @__PURE__ */ e("circle", { cx: t, cy: t, r: s + 2, fill: "#fff" })
59
- ] }),
60
- /* @__PURE__ */ e(
61
- "div",
62
- {
63
- className: "center-avatar",
64
- style: { width: s * 2, height: s * 2 },
65
- children: f ? /* @__PURE__ */ e("img", { src: f, alt: "avatar" }) : /* @__PURE__ */ e("span", { className: "center-text", children: "菜单" })
66
- }
67
- )
68
- ] });
1
+ const t = (r) => {
2
+ if (n(r) || Array.isArray(r))
3
+ try {
4
+ return JSON.stringify(r);
5
+ } catch (e) {
6
+ console.log("JSON.stringify", e);
7
+ }
8
+ else
9
+ return r;
10
+ }, c = (r) => {
11
+ if (n(r) || Array.isArray(r))
12
+ try {
13
+ return JSON.parse(JSON.stringify(r));
14
+ } catch (e) {
15
+ console.log("JSON.stringify-JSON.parse", e);
16
+ }
17
+ else
18
+ return r;
19
+ };
20
+ function n(r) {
21
+ return r !== null && typeof r == "object" && !Array.isArray(r);
22
+ }
23
+ const i = (r, e) => {
24
+ const o = document.createElement("a");
25
+ o.href = r, o.download = e, document.body.appendChild(o), o.click(), document.body.removeChild(o);
69
26
  };
70
27
  export {
71
- L as default
28
+ i as downloadFile,
29
+ n as isObject,
30
+ t as jsonStringify,
31
+ c as jsonStringifyParse
72
32
  };