react-kggraph 0.0.20 → 0.0.21

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/lib/index.es3.js +122 -122
  2. package/package.json +1 -1
package/lib/index.es3.js CHANGED
@@ -1,72 +1,72 @@
1
- import { jsx as c, jsxs as te } from "react/jsx-runtime";
2
- import { useRef as N, useState as h, useEffect as S } from "react";
1
+ import { jsx as c, jsxs as oe } from "react/jsx-runtime";
2
+ import { useRef as N, useState as v, useEffect as D } from "react";
3
3
  import k from "cytoscape";
4
- import Ne from "cytoscape-cose-bilkent";
5
- import Ce from "cytoscape-cise";
6
- import ke from "cytoscape-fcose";
7
- import Ee from "storm-layout";
8
- import ze from "./index.es7.js";
4
+ import Ce from "cytoscape-cose-bilkent";
5
+ import ke from "cytoscape-cise";
6
+ import Ee from "cytoscape-fcose";
7
+ import ze from "storm-layout";
8
+ import we from "./index.es7.js";
9
9
  /* empty css */
10
- import { handleCalcPath as we, resDetailData as F } from "./index.es8.js";
11
- import { fixNodesToEdges as Le, coseBilkentLayout as oe } from "./index.es9.js";
12
- import { edgeNodeStyles as Re, defaultColors as ne } from "./index.es10.js";
13
- import je from "cytoscape-layout-utilities";
14
- import { Row as Te, Empty as $e, message as C } from "antd";
15
- import { menuItemsConfig as De } from "./index.es11.js";
10
+ import { handleCalcPath as Le, resDetailData as F } from "./index.es8.js";
11
+ import { fixNodesToEdges as Re, coseBilkentLayout as ne } from "./index.es9.js";
12
+ import { edgeNodeStyles as je, defaultColors as se } from "./index.es10.js";
13
+ import Te from "cytoscape-layout-utilities";
14
+ import { Row as $e, Empty as Oe, message as C } from "antd";
15
+ import { menuItemsConfig as Se } from "./index.es11.js";
16
16
  import { jsonStringify as R } from "./index.es12.js";
17
- import Oe from "./index.es13.js";
18
- import Se from "./index.es14.js";
19
- import { GraphProvider as Ie } from "./index.es15.js";
20
- import Pe from "./index.es16.js";
21
- k.use(je);
22
- k.use(Ce);
17
+ import De from "./index.es13.js";
18
+ import Ie from "./index.es14.js";
19
+ import { GraphProvider as Pe } from "./index.es15.js";
20
+ import Be from "./index.es16.js";
21
+ k.use(Te);
23
22
  k.use(ke);
24
23
  k.use(Ee);
25
- k.use(Ne);
26
- const rt = ({
27
- data: re,
24
+ k.use(ze);
25
+ k.use(Ce);
26
+ const dt = ({
27
+ data: de,
28
28
  getAllGraphData: I,
29
29
  highPathAnalysis: E = [],
30
- graphInfo: m,
31
- stepNextApi: se,
32
- knowledgeCardApi: de,
30
+ graphInfo: h,
31
+ stepNextApi: re,
32
+ knowledgeCardApi: ae,
33
33
  colors: z,
34
- actionBar: ae,
35
- actionCircle: ie,
36
- noDataDesc: le = "暂无数据"
34
+ actionBar: ie,
35
+ actionCircle: le,
36
+ noDataDesc: ce = "暂无数据"
37
37
  }) => {
38
- var _, G;
39
- const j = N(null), [v, P] = h([]), p = N(null), K = N(null), X = 1, [Be, J] = h(!1), [w, B] = h({}), [T, W] = h({}), [ce, pe] = h("cose-bilkent"), Q = N(null), V = N(null), [ue, Y] = h(["", ""]), H = N(z);
40
- S(() => {
38
+ var _, G, ee;
39
+ const j = N(null), [u, P] = v([]), p = N(null), K = N(null), X = 1, [We, J] = v(!1), [w, B] = v({}), [T, W] = v({}), [pe, ue] = v("cose-bilkent"), Q = N(null), V = N(null), [ge, Y] = v(["", ""]), H = N(z);
40
+ D(() => {
41
41
  H.current = z;
42
42
  }, [z]);
43
- const [u, L] = h({
43
+ const [g, L] = v({
44
44
  visible: !1,
45
45
  x: 0,
46
46
  y: 0,
47
47
  targetNode: null,
48
48
  bgColor: ""
49
- }), [$, Z] = h({
49
+ }), [$, Z] = v({
50
50
  visible: !1,
51
51
  x: 0,
52
52
  y: 0,
53
53
  content: ""
54
- }), ge = De({ cyRef: p, setContextMenu: L, onPathAnalysis: (_ = K.current) == null ? void 0 : _.onPathAnalysis, setPathNodes: Y, actionCircle: ie });
55
- S(() => {
56
- (E == null ? void 0 : E.length) > 1 && we(p, { pathNodes: E, isGrayed: !1 });
57
- }, [R(E), R(v)]), S(() => {
58
- I == null || I({ graphData: v, nodeStatic: w, relationStatic: T });
59
- }, [R(v), R(w), R(T)]), S(() => {
60
- var d;
54
+ }), ye = Se({ cyRef: p, setContextMenu: L, onPathAnalysis: (_ = K.current) == null ? void 0 : _.onPathAnalysis, setPathNodes: Y, actionCircle: le });
55
+ D(() => {
56
+ (E == null ? void 0 : E.length) > 1 && Le(p, { pathNodes: E, isGrayed: !1 });
57
+ }, [R(E), R(u)]), D(() => {
58
+ I == null || I({ graphData: u, nodeStatic: w, relationStatic: T });
59
+ }, [R(u), R(w), R(T)]), D(() => {
60
+ var r;
61
61
  if (!j.current || p.current) return;
62
- const { elements: r, typeListObj: a, relationListObj: g } = F(re, { typeObj: w, graphInfo: m });
63
- B(a), P(r), W(g), document.addEventListener("contextmenu", function(t) {
62
+ const { elements: s, typeListObj: a, relationListObj: y } = F(de, { typeObj: w, graphInfo: h });
63
+ B(a), P(s), W(y), document.addEventListener("contextmenu", function(t) {
64
64
  t.preventDefault();
65
65
  });
66
66
  const e = k({
67
67
  container: j.current,
68
- elements: r,
69
- style: Re({ elements: r, colors: z }),
68
+ elements: s,
69
+ style: je({ elements: s, colors: z }),
70
70
  autounselectify: !1,
71
71
  autolock: !1,
72
72
  layout: {
@@ -74,14 +74,14 @@ const rt = ({
74
74
  // 使用预设布局,完全依赖 position
75
75
  }
76
76
  });
77
- if (p.current = e, ((d = m == null ? void 0 : m.searchNodes) == null ? void 0 : d.length) === 2)
78
- Le(
77
+ if (p.current = e, ((r = h == null ? void 0 : h.searchNodes) == null ? void 0 : r.length) === 2)
78
+ Re(
79
79
  e,
80
- m.searchNodes[0],
81
- m.searchNodes[1]
80
+ h.searchNodes[0],
81
+ h.searchNodes[1]
82
82
  );
83
83
  else {
84
- const t = e.layout(oe());
84
+ const t = e.layout(ne());
85
85
  t.run(), t.on("layoutstop", () => {
86
86
  e.fit(void 0, 50), e.center();
87
87
  });
@@ -90,10 +90,10 @@ const rt = ({
90
90
  var n;
91
91
  const o = t.target;
92
92
  if (!o.hasClass("path-edge")) {
93
- const s = ((n = H.current) == null ? void 0 : n.edgeHoverColor) ?? ne.edgeHoverColor;
93
+ const d = ((n = H.current) == null ? void 0 : n.edgeHoverColor) ?? se.edgeHoverColor;
94
94
  o.style({
95
- "line-color": s,
96
- "target-arrow-color": s,
95
+ "line-color": d,
96
+ "target-arrow-color": d,
97
97
  opacity: 0.8
98
98
  });
99
99
  }
@@ -101,10 +101,10 @@ const rt = ({
101
101
  var n;
102
102
  const o = t.target;
103
103
  if (!o.hasClass("path-edge")) {
104
- const s = ((n = H.current) == null ? void 0 : n.edgeDefaultColor) ?? ne.edgeDefaultColor;
104
+ const d = ((n = H.current) == null ? void 0 : n.edgeDefaultColor) ?? se.edgeDefaultColor;
105
105
  o.style({
106
- "line-color": s,
107
- "target-arrow-color": s,
106
+ "line-color": d,
107
+ "target-arrow-color": d,
108
108
  opacity: 1
109
109
  });
110
110
  }
@@ -112,12 +112,12 @@ const rt = ({
112
112
  const o = t.target;
113
113
  o.hasClass("selected") || o.addClass("hover");
114
114
  }), e.on("mouseover", "node", (t) => {
115
- const o = t.target, n = o.renderedPosition(), s = o.data("name") || "";
115
+ const o = t.target, n = o.renderedPosition(), d = o.data("name") || "";
116
116
  o.addClass("hover"), Z({
117
117
  visible: !0,
118
118
  x: n.x,
119
119
  y: n.y - 60,
120
- content: s
120
+ content: d
121
121
  });
122
122
  }), e.on("mouseout", "node", (t) => {
123
123
  t.target.removeClass("hover"), Z((n) => ({ ...n, visible: !1 }));
@@ -134,52 +134,52 @@ const rt = ({
134
134
  }), p.current = e, e.on("click", "node", (t) => {
135
135
  const o = t.target;
136
136
  e.nodes().removeClass("selected grayed highlighted"), e.edges().removeClass("selected grayed highlighted"), o.addClass("selected");
137
- const s = o.neighborhood().nodes().add(o), x = s.edgesWith(s);
138
- console.log("cy.nodes().not(relatedNodes):::", s), e.nodes().not(s).addClass("grayed"), e.edges().not(x).addClass("grayed"), s.addClass("highlighted"), x.addClass("highlighted");
137
+ const d = o.neighborhood().nodes().add(o), x = d.edgesWith(d);
138
+ console.log("cy.nodes().not(relatedNodes):::", d), e.nodes().not(d).addClass("grayed"), e.edges().not(x).addClass("grayed"), d.addClass("highlighted"), x.addClass("highlighted");
139
139
  }), e.on("tap", (t) => {
140
140
  t.target === e && (L((o) => ({ ...o, visible: !1 })), e.nodes().removeClass("grayed highlighted highlight selected correlationStyle path-node level-highlight level-selected level-grayed"), e.edges().removeClass("grayed highlighted highlight selected correlationStyle path-edge level-highlightedge level-grayed"));
141
141
  }), () => {
142
142
  p.current && (p.current.destroy(), p.current = null);
143
143
  };
144
144
  }, []);
145
- const ye = async (r) => {
146
- const { id: a, kgId: g } = r, e = p.current;
145
+ const fe = async (s) => {
146
+ const { id: a, kgId: y } = s, e = p.current;
147
147
  if (!e) return;
148
- const d = e.$(`#${a}`);
149
- if (!d || d.length === 0) {
148
+ const r = e.$(`#${a}`);
149
+ if (!r || r.length === 0) {
150
150
  console.error("当前节点不存在");
151
151
  return;
152
152
  }
153
- const t = e.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === a || n.data("idLabel") === `${a}-${n.data("name")}`) && n.data("zktype") === r.zktype : !1);
153
+ const t = e.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === a || n.data("idLabel") === `${a}-${n.data("name")}`) && n.data("zktype") === s.zktype : !1);
154
154
  if (t.length > 0) {
155
- const n = t.map((l) => l.id()), s = t.connectedEdges(), x = e.edges().filter(
155
+ const n = t.map((l) => l.id()), d = t.connectedEdges(), x = e.edges().filter(
156
156
  (l) => l.data("source") === a && n.includes(l.data("target"))
157
- ), D = e.edges().filter((l) => l.data("appendedBy") === a), M = s.merge(x).merge(D).filter((l) => l.data().zktype === r.zktype);
157
+ ), O = e.edges().filter((l) => l.data("appendedBy") === a), M = d.merge(x).merge(O).filter((l) => l.data().zktype === s.zktype);
158
158
  t.animate({
159
159
  style: { opacity: 0 }
160
160
  }, {
161
161
  duration: 200,
162
162
  complete: () => {
163
163
  e.remove(t), e.remove(M), P((l) => {
164
- const O = l.filter((f) => {
165
- var b, ee;
166
- const i = f.data.zktype;
167
- if (f.group === "nodes" && n.includes((b = f.data) == null ? void 0 : b.id) && i && i === r.zktype)
164
+ const S = l.filter((m) => {
165
+ var b, te;
166
+ const i = m.data.zktype;
167
+ if (m.group === "nodes" && n.includes((b = m.data) == null ? void 0 : b.id) && i && i === s.zktype)
168
168
  return !1;
169
- if (f.group === "edges" && i && i === r.zktype) {
170
- const he = Array.from(D).map((xe) => {
171
- const A = xe.data();
169
+ if (m.group === "edges" && i && i === s.zktype) {
170
+ const ve = Array.from(O).map((Ne) => {
171
+ const A = Ne.data();
172
172
  return `${A.source}-${A.target}-${A.label}`;
173
- }), q = f.data, ve = he.includes(`${q.source}-${q.target}-${q.label}`), be = ((ee = f.data) == null ? void 0 : ee.appendedBy) === a;
174
- return !ve && !be;
173
+ }), q = m.data, be = ve.includes(`${q.source}-${q.target}-${q.label}`), xe = ((te = m.data) == null ? void 0 : te.appendedBy) === a;
174
+ return !be && !xe;
175
175
  }
176
176
  return !0;
177
- }), { typeListObj: y, relationListObj: U } = F({}, { graphData: O, typeObj: {} });
178
- return B(y), W(U), O;
179
- }), d.data("appendedNodes", []), d.data("isExpanded", !1);
177
+ }), { typeListObj: f, relationListObj: U } = F({}, { graphData: S, typeObj: {} });
178
+ return B(f), W(U), S;
179
+ }), r.data("appendedNodes", []), r.data("isExpanded", !1);
180
180
  }
181
181
  }), setTimeout(() => {
182
- d.removed() || (d.style("border-width", ""), d.style("border-color", ""));
182
+ r.removed() || (r.style("border-width", ""), r.style("border-color", ""));
183
183
  }, 300);
184
184
  } else {
185
185
  try {
@@ -188,21 +188,21 @@ const rt = ({
188
188
  content: "正在展开...",
189
189
  duration: 0
190
190
  });
191
- const n = await se({ uri: a, queryType: 1, kgId: g, zktype: r.zktype }), { elements: s, typeListObj: x, relationListObj: D } = F(n.data, { graphData: v, typeObj: w, relationObj: T, zktype: r.zktype });
192
- if (B(x), W(D), !((s == null ? void 0 : s.length) > 0)) {
191
+ const n = await re({ uri: a, queryType: 1, kgId: y, zktype: s.zktype }), { elements: d, typeListObj: x, relationListObj: O } = F(n.data, { graphData: u, typeObj: w, relationObj: T, zktype: s.zktype });
192
+ if (B(x), W(O), !((d == null ? void 0 : d.length) > 0)) {
193
193
  setTimeout(() => {
194
194
  C.destroy(), C.warning("暂无数据");
195
195
  }, 2e3);
196
196
  return;
197
197
  }
198
- if ((s == null ? void 0 : s.length) > 0) {
198
+ if ((d == null ? void 0 : d.length) > 0) {
199
199
  const M = e.layoutUtilities({
200
- ...oe(),
200
+ ...ne(),
201
201
  idealEdgeLength: 80,
202
202
  // 与你的期望边长匹配
203
203
  offset: 30
204
204
  // 随机偏移,避免完全重叠
205
- }), l = s.map((i) => {
205
+ }), l = d.map((i) => {
206
206
  if (i.group === "nodes") {
207
207
  const b = 80 * X;
208
208
  return {
@@ -219,7 +219,7 @@ const rt = ({
219
219
  appendedBy: a,
220
220
  // 标记由谁追加
221
221
  idLabel: a + "-" + i.data.label,
222
- zktype: r.zktype,
222
+ zktype: s.zktype,
223
223
  isAppended: !0,
224
224
  // 标记是追加节点
225
225
  baseWidth: b,
@@ -232,15 +232,15 @@ const rt = ({
232
232
  data: {
233
233
  ...i.data,
234
234
  appendedBy: a,
235
- zktype: r.zktype
235
+ zktype: s.zktype
236
236
  }
237
237
  };
238
- }), O = e.add(l);
239
- P([...v, ...l]);
240
- const y = O.filter(":node"), U = y.map((i) => i.id());
241
- d.data("appendedNodes", U), d.data("isExpanded", !0);
242
- const f = e.nodes().difference(y);
243
- f.forEach((i) => i.lock()), M.placeNewNodes(y), e.layout({
238
+ }), S = e.add(l);
239
+ P([...u, ...l]);
240
+ const f = S.filter(":node"), U = f.map((i) => i.id());
241
+ r.data("appendedNodes", U), r.data("isExpanded", !0);
242
+ const m = e.nodes().difference(f);
243
+ m.forEach((i) => i.lock()), M.placeNewNodes(f), e.layout({
244
244
  name: "cose-bilkent",
245
245
  randomize: !1,
246
246
  // ⚠️ 这是关键!保持已有节点位置不变
@@ -256,8 +256,8 @@ const rt = ({
256
256
  // 可以适当减少,因为只需要微调
257
257
  gravity: 0.6
258
258
  }).run(), setTimeout(() => {
259
- f.forEach((i) => i.unlock());
260
- }, 2e3), y.animate({
259
+ m.forEach((i) => i.unlock());
260
+ }, 2e3), f.animate({
261
261
  style: {
262
262
  opacity: 1,
263
263
  width: 20,
@@ -267,10 +267,10 @@ const rt = ({
267
267
  duration: 400,
268
268
  easing: "ease-out",
269
269
  complete: () => {
270
- y.style("opacity", ""), y.style("width", ""), y.style("height", "");
270
+ f.style("opacity", ""), f.style("width", ""), f.style("height", "");
271
271
  }
272
272
  }), setTimeout(() => {
273
- d.removed() || (d.style("border-width", ""), d.style("border-color", ""), e.center(d), e.zoom(e.zoom()));
273
+ r.removed() || (r.style("border-width", ""), r.style("border-color", ""), e.center(r), e.zoom(e.zoom()));
274
274
  }, 600);
275
275
  } else
276
276
  console.log("没有找到相关节点数据");
@@ -281,19 +281,19 @@ const rt = ({
281
281
  J(!1);
282
282
  }
283
283
  L({ visible: !1 });
284
- }, fe = {
284
+ }, me = {
285
285
  expanded: "typed-literal",
286
286
  contract: "uri"
287
- }, me = (r, a) => {
287
+ }, he = (s, a) => {
288
288
  var e;
289
- console.log("handleMenuAction:::", r, a);
290
- const g = a || u.targetNode;
291
- if (g) {
292
- const d = r.ids, t = g.data();
293
- if (["expanded", "contract"].includes(d))
294
- ye({ kgId: 3, ...t, zktype: fe[d] });
295
- else if (d === "nodeInfo") {
296
- const o = g, n = {
289
+ console.log("handleMenuAction:::", s, a);
290
+ const y = a || g.targetNode;
291
+ if (y) {
292
+ const r = s.ids, t = y.data();
293
+ if (["expanded", "contract"].includes(r))
294
+ fe({ kgId: 3, ...t, zktype: me[r] });
295
+ else if (r === "nodeInfo") {
296
+ const o = y, n = {
297
297
  id: o.id(),
298
298
  data: o.data(),
299
299
  position: o.position(),
@@ -304,35 +304,35 @@ const rt = ({
304
304
  style: o.style()
305
305
  };
306
306
  Q.current.open(n);
307
- } else d === "knowledgeCard" && V.current.open(g.data());
308
- (e = r.onClick) == null || e.call(r, g), L({ visible: !1, x: 0, y: 0, targetNode: null });
307
+ } else r === "knowledgeCard" && V.current.open(y.data());
308
+ (e = s.onClick) == null || e.call(s, y), L({ visible: !1, x: 0, y: 0, targetNode: null });
309
309
  }
310
310
  };
311
- return v.length < 1 ? /* @__PURE__ */ c(Te, { className: "h-100", align: "middle", justify: "center", children: /* @__PURE__ */ c($e, { description: le }) }) : /* @__PURE__ */ c(Ie, { value: { pathNodes: ue, setPathNodes: Y, graphInfo: m, graphData: v, layoutType: ce, setLayoutType: pe, knowledgeCardApi: de }, children: /* @__PURE__ */ te("div", { className: "cytoscape-container relative", children: [
311
+ return ((G = u == null ? void 0 : u.nodes) == null ? void 0 : G.length) > 0 ? /* @__PURE__ */ c(Pe, { value: { pathNodes: ge, setPathNodes: Y, graphInfo: h, graphData: u, layoutType: pe, setLayoutType: ue, knowledgeCardApi: ae }, children: /* @__PURE__ */ oe("div", { className: "cytoscape-container relative", children: [
312
312
  /* @__PURE__ */ c("div", { className: "btn-group" }),
313
313
  /* @__PURE__ */ c(
314
- ze,
314
+ we,
315
315
  {
316
316
  ref: K,
317
317
  cyRef: p,
318
- graphInfo: m,
318
+ graphInfo: h,
319
319
  initNodeScale: X,
320
320
  cyContainerRef: j,
321
321
  typeObj: w,
322
322
  relationObj: T,
323
323
  colors: z,
324
- actionBar: ae
324
+ actionBar: ie
325
325
  }
326
326
  ),
327
- /* @__PURE__ */ te("div", { className: "relative h-100", children: [
327
+ /* @__PURE__ */ oe("div", { className: "relative h-100", children: [
328
328
  /* @__PURE__ */ c("div", { ref: j, className: "cy-container" }),
329
- u.visible && u.targetNode && /* @__PURE__ */ c(
329
+ g.visible && g.targetNode && /* @__PURE__ */ c(
330
330
  "div",
331
331
  {
332
332
  style: {
333
333
  position: "absolute",
334
- left: `${u.x}px`,
335
- top: `${u.y}px`,
334
+ left: `${g.x}px`,
335
+ top: `${g.y}px`,
336
336
  // backgroundColor: 'white',
337
337
  // border: '1px solid #ccc',
338
338
  // borderRadius: '50%',
@@ -345,8 +345,8 @@ const rt = ({
345
345
  height: "200px",
346
346
  overflow: "hidden"
347
347
  },
348
- onClick: (r) => r.stopPropagation(),
349
- children: /* @__PURE__ */ c(Oe, { items: ge, centerImage: (G = u == null ? void 0 : u.targetNode) == null ? void 0 : G.data().image, targetNode: u.targetNode, onClick: (r, a) => me(r, a) })
348
+ onClick: (s) => s.stopPropagation(),
349
+ children: /* @__PURE__ */ c(De, { items: ye, centerImage: (ee = g == null ? void 0 : g.targetNode) == null ? void 0 : ee.data().image, targetNode: g.targetNode, onClick: (s, a) => he(s, a) })
350
350
  }
351
351
  ),
352
352
  $.visible && /* @__PURE__ */ c(
@@ -373,10 +373,10 @@ const rt = ({
373
373
  }
374
374
  )
375
375
  ] }),
376
- /* @__PURE__ */ c(Se, { ref: Q }),
377
- /* @__PURE__ */ c(Pe, { ref: V })
378
- ] }) });
376
+ /* @__PURE__ */ c(Ie, { ref: Q }),
377
+ /* @__PURE__ */ c(Be, { ref: V })
378
+ ] }) }) : /* @__PURE__ */ c($e, { className: "h-100", align: "middle", justify: "center", children: /* @__PURE__ */ c(Oe, { description: ce }) });
379
379
  };
380
380
  export {
381
- rt as default
381
+ dt as default
382
382
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-kggraph",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "A knowledge graph visualization component based on Cytoscape",
5
5
  "type": "module",
6
6
  "main": "./lib/index.es.js",