react-kggraph 0.0.34 → 0.0.35

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/lib/index.es3.js CHANGED
@@ -1,9 +1,9 @@
1
- import { jsx as y, jsxs as ne } from "react/jsx-runtime";
1
+ import { jsx as f, jsxs as ne } from "react/jsx-runtime";
2
2
  import { useRef as C, useState as m, useEffect as T } from "react";
3
3
  import z from "cytoscape";
4
4
  import Ee from "cytoscape-cose-bilkent";
5
- import Ne from "cytoscape-cise";
6
- import Pe from "cytoscape-fcose";
5
+ import Pe from "cytoscape-cise";
6
+ import Ne from "cytoscape-fcose";
7
7
  import je from "storm-layout";
8
8
  import we from "./index.es7.js";
9
9
  /* empty css */
@@ -20,18 +20,18 @@ import { GraphProvider as Me } from "./index.es15.js";
20
20
  import Ae from "./index.es16.js";
21
21
  import We from "./index.es17.js";
22
22
  z.use(Te);
23
- z.use(Ne);
24
23
  z.use(Pe);
24
+ z.use(Ne);
25
25
  z.use(je);
26
26
  z.use(Ee);
27
27
  const ct = ({
28
28
  data: E,
29
29
  getAllGraphData: $,
30
30
  highPathAnalysis: F = [],
31
- graphInfo: u,
31
+ graphInfo: g,
32
32
  stepNextApi: ae,
33
33
  knowledgeCardApi: re,
34
- colors: N,
34
+ colors: P,
35
35
  actionBar: ie,
36
36
  actionCircle: de,
37
37
  queryStatisticsConfig: le = [{ label: "实体", key: "entity" }, { label: "关系", key: "relation" }],
@@ -39,11 +39,11 @@ const ct = ({
39
39
  noDataDesc: He = "暂无数据"
40
40
  }) => {
41
41
  var V, G;
42
- const L = C(null), [v, X] = m([]), c = C(null), q = C(null), K = 1, [Ze, U] = m(!1), [b, I] = m({}), [O, B] = m({}), [pe, ge] = m("cose-bilkent"), Y = C(null), _ = C(null), [ue, J] = m(["", ""]), M = C(N);
42
+ const L = C(null), [v, X] = m([]), c = C(null), q = C(null), K = 1, [Ze, U] = m(!1), [b, I] = m({}), [O, B] = m({}), [pe, ge] = m("cose-bilkent"), Y = C(null), _ = C(null), [ue, J] = m(["", ""]), M = C(P);
43
43
  T(() => {
44
- M.current = N;
45
- }, [N]);
46
- const [f, P] = m({
44
+ M.current = P;
45
+ }, [P]);
46
+ const [u, N] = m({
47
47
  visible: !1,
48
48
  x: 0,
49
49
  y: 0,
@@ -54,26 +54,26 @@ const ct = ({
54
54
  x: 0,
55
55
  y: 0,
56
56
  content: ""
57
- }), fe = $e({ cyRef: c, setContextMenu: P, onPathAnalysis: (V = q.current) == null ? void 0 : V.onPathAnalysis, setPathNodes: J, actionCircle: de });
57
+ }), fe = $e({ cyRef: c, setContextMenu: N, onPathAnalysis: (V = q.current) == null ? void 0 : V.onPathAnalysis, setPathNodes: J, actionCircle: de });
58
58
  T(() => {
59
- const { nodes: t, links: e } = F || {};
60
- ((t == null ? void 0 : t.length) > 0 || (e == null ? void 0 : e.length) > 0) && Le(c, { nodes: t, links: e, isGrayed: !1 });
59
+ const { nodes: e, links: t } = F || {};
60
+ ((e == null ? void 0 : e.length) > 0 || (t == null ? void 0 : t.length) > 0) && Le(c, { nodes: e, links: t, isGrayed: !1 });
61
61
  }, [w(F), w(v)]), T(() => {
62
- const t = [], e = [];
62
+ const e = [], t = [];
63
63
  v.forEach((d) => {
64
- d.group === "nodes" ? t.push(d.data) : d.group === "edges" && e.push(d.data);
65
- }), $ == null || $({ graphData: v, nodeStatic: b, relationStatic: O, data: { nodes: t, links: e }, paths: E.paths, data2: E.data2, logId: E.logId, costtime: E.costtime });
64
+ d.group === "nodes" ? e.push(d.data) : d.group === "edges" && t.push(d.data);
65
+ }), $ == null || $({ graphData: v, nodeStatic: b, relationStatic: O, data: { nodes: e, links: t }, paths: E.paths, data2: E.data2, logId: E.logId, costtime: E.costtime });
66
66
  }, [w(v), w(b), w(O)]), T(() => {
67
67
  var i;
68
68
  if (!L.current || c.current) return;
69
- const { elements: t, typeListObj: e, relationListObj: d } = Z(E, { typeObj: b, graphInfo: u });
70
- I(e), X(t), B(d), document.addEventListener("contextmenu", function(a) {
69
+ const { elements: e, typeListObj: t, relationListObj: d } = Z(E, { typeObj: b, graphInfo: g });
70
+ I(t), X(e), B(d), document.addEventListener("contextmenu", function(a) {
71
71
  a.preventDefault();
72
72
  });
73
73
  const s = z({
74
74
  container: L.current,
75
- elements: t,
76
- style: Re({ elements: t, colors: N }),
75
+ elements: e,
76
+ style: Re({ elements: e, colors: P }),
77
77
  autounselectify: !1,
78
78
  autolock: !1,
79
79
  maxZoom: 1,
@@ -82,11 +82,11 @@ const ct = ({
82
82
  // 使用预设布局,完全依赖 position
83
83
  }
84
84
  });
85
- if (c.current = s, ((i = u == null ? void 0 : u.searchNodes) == null ? void 0 : i.length) === 2)
85
+ if (c.current = s, ((i = g == null ? void 0 : g.searchNodes) == null ? void 0 : i.length) === 2)
86
86
  Oe(
87
87
  s,
88
- u.searchNodes[0],
89
- u.searchNodes[1]
88
+ g.searchNodes[0],
89
+ g.searchNodes[1]
90
90
  );
91
91
  else {
92
92
  const a = s.layout(De());
@@ -132,7 +132,7 @@ const ct = ({
132
132
  }), s.on("cxttap", "node", (a) => {
133
133
  a.preventDefault(), a.stopPropagation(), a.stopImmediatePropagation(), a.originalEvent && (a.originalEvent.preventDefault(), a.originalEvent.stopPropagation(), a.originalEvent.stopImmediatePropagation());
134
134
  const o = a.target, n = o.renderedPosition();
135
- console.log("renderedPos:::", o.data(), o.style("background-color")), P({
135
+ console.log("renderedPos:::", o.data(), o.style("background-color")), N({
136
136
  visible: !0,
137
137
  x: n.x - 90,
138
138
  y: n.y - 90,
@@ -142,23 +142,27 @@ const ct = ({
142
142
  }), c.current = s, s.on("click", "node", (a) => {
143
143
  const o = a.target;
144
144
  s.nodes().removeClass("selected grayed highlighted"), s.edges().removeClass("selected grayed highlighted"), o.addClass("selected");
145
- const r = o.neighborhood().nodes().add(o), g = r.edgesWith(r);
146
- console.log("cy.nodes().not(relatedNodes):::", r), s.nodes().not(r).addClass("grayed"), s.edges().not(g).addClass("grayed"), r.addClass("highlighted"), g.addClass("highlighted");
145
+ const r = o.neighborhood().nodes().add(o), p = r.edgesWith(r);
146
+ console.log("cy.nodes().not(relatedNodes):::", r), s.nodes().not(r).addClass("grayed"), s.edges().not(p).addClass("grayed"), r.addClass("highlighted"), p.addClass("highlighted");
147
147
  }), s.on("tap", (a) => {
148
- a.target === s && (P((o) => ({ ...o, visible: !1 })), s.nodes().removeClass("grayed highlighted highlight selected correlationStyle path-node level-highlight level-selected level-grayed"), s.edges().removeClass("grayed highlighted highlight selected correlationStyle path-edge level-highlightedge level-grayed"));
148
+ a.target === s && (N((o) => ({ ...o, visible: !1 })), s.nodes().removeClass("grayed highlighted highlight selected correlationStyle path-node level-highlight level-selected level-grayed"), s.edges().removeClass("grayed highlighted highlight selected correlationStyle path-edge level-highlightedge level-grayed"));
149
149
  }), () => {
150
150
  c.current && (c.current.destroy(), c.current = null);
151
151
  };
152
152
  }, []);
153
- const ye = ({ addedNodes: t, currentNode: e, cy: d, currentZoom: s }) => {
154
- const i = t == null ? void 0 : t.length;
155
- e.data("originalPosition") || e.data("originalPosition", { ...e.position() });
153
+ const ye = ({ addedNodes: e, currentNode: t, cy: d, currentZoom: s }) => {
154
+ const i = e == null ? void 0 : e.length;
155
+ t.data("originalPosition") || t.data("originalPosition", { ...t.position() });
156
156
  const a = Math.max(0.1, 18 / (i || 1)), o = d.layout({
157
157
  name: "concentric",
158
158
  spacingFactor: a,
159
159
  // 节点越多间距越小,防止溢出
160
+ eles: e.union(t),
161
+ // 只布局新节点+当前节点,不重算全图
160
162
  minNodeSpacing: 0,
161
163
  // 最小间距设为0
164
+ fit: !1,
165
+ // 禁止自动适配视口,保持缩放
162
166
  animate: !1,
163
167
  concentric: function(n) {
164
168
  return n.degree();
@@ -172,26 +176,26 @@ const ct = ({
172
176
  // },
173
177
  // 添加随机偏移,打破完美圆环
174
178
  transform: function(n, r) {
175
- const g = (Math.random() - 0.5) * 40, x = (Math.random() - 0.5) * 10;
179
+ const p = (Math.random() - 0.5) * 40, x = (Math.random() - 0.5) * 10;
176
180
  return {
177
- x: r.x + g,
181
+ x: r.x + p,
178
182
  y: r.y + x
179
183
  };
180
184
  }
181
185
  });
182
186
  o.one("layoutstop", () => {
183
- t.forEach((g) => {
184
- g.style("z-index", Math.floor(Math.random() * 500) + 1);
185
- }), e.style("z-index", 1e3);
186
- const n = e.data("originalPosition"), r = { ...e.position() };
187
- n && (e.position(n), e.animate({
188
- center: { eles: e },
187
+ e.forEach((p) => {
188
+ p.style("z-index", Math.floor(Math.random() * 500) + 1);
189
+ }), t.style("z-index", 1e3);
190
+ const n = t.data("originalPosition"), r = { ...t.position() };
191
+ n && (t.position(n), t.animate({
192
+ center: { eles: t },
189
193
  position: r
190
194
  }, {
191
195
  duration: 900,
192
196
  easing: "ease-out",
193
197
  complete: () => {
194
- t.animate({
198
+ e.animate({
195
199
  style: { opacity: 1 }
196
200
  }, {
197
201
  duration: 900,
@@ -200,19 +204,19 @@ const ct = ({
200
204
  }
201
205
  })), h.destroy();
202
206
  }), o.run(), d.nodes().forEach((n) => n.unlock());
203
- }, me = async (t) => {
204
- const { id: e, kgId: d } = t, s = c.current;
207
+ }, me = async (e) => {
208
+ const { id: t, kgId: d } = e, s = c.current;
205
209
  if (!s) return;
206
- const i = s.$id(e);
210
+ const i = s.$id(t);
207
211
  if (!i || i.length === 0) {
208
212
  console.error("当前节点不存在");
209
213
  return;
210
214
  }
211
- const a = s.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === e || n.data("idLabel") === `${e}-${n.data("name")}`) && n.data("zktype") === t.zktype : !1);
215
+ const a = s.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === t || n.data("idLabel") === `${t}-${n.data("name")}`) && n.data("zktype") === e.zktype : !1);
212
216
  if (a.length > 0) {
213
- const n = a.map((l) => l.id()), r = a.connectedEdges(), g = s.edges().filter(
214
- (l) => l.data("source") === e && n.includes(l.data("target"))
215
- ), x = s.edges().filter((l) => l.data("appendedBy") === e), A = r.merge(g).merge(x).filter((l) => l.data().zktype === t.zktype);
217
+ const n = a.map((l) => l.id()), r = a.connectedEdges(), p = s.edges().filter(
218
+ (l) => l.data("source") === t && n.includes(l.data("target"))
219
+ ), x = s.edges().filter((l) => l.data("appendedBy") === t), A = r.merge(p).merge(x).filter((l) => l.data().zktype === e.zktype);
216
220
  a.animate({
217
221
  style: { opacity: 0 }
218
222
  }, {
@@ -222,18 +226,18 @@ const ct = ({
222
226
  const j = ee.filter((k) => {
223
227
  var te, oe;
224
228
  const S = k.data.zktype;
225
- if (k.group === "nodes" && n.includes((te = k.data) == null ? void 0 : te.id) && S && S === t.zktype)
229
+ if (k.group === "nodes" && n.includes((te = k.data) == null ? void 0 : te.id) && S && S === e.zktype)
226
230
  return !1;
227
- if (k.group === "edges" && S && S === t.zktype) {
231
+ if (k.group === "edges" && S && S === e.zktype) {
228
232
  const xe = Array.from(x).map((ze) => {
229
233
  const H = ze.data();
230
234
  return `${H.source}-${H.target}-${H.label}`;
231
- }), W = k.data, ke = xe.includes(`${W.source}-${W.target}-${W.label}`), Ce = ((oe = k.data) == null ? void 0 : oe.appendedBy) === e;
235
+ }), W = k.data, ke = xe.includes(`${W.source}-${W.target}-${W.label}`), Ce = ((oe = k.data) == null ? void 0 : oe.appendedBy) === t;
232
236
  return !ke && !Ce;
233
237
  }
234
238
  return !0;
235
- }), { typeListObj: p, relationListObj: R } = Z({}, { graphData: j, typeObj: {} });
236
- return I(p), B(R), j;
239
+ }), { typeListObj: y, relationListObj: R } = Z({}, { graphData: j, typeObj: {} });
240
+ return I(y), B(R), j;
237
241
  }), i.data("appendedNodes", []), i.data("isExpanded", !1);
238
242
  const l = i.data("originalPosition");
239
243
  l && (i.animate({
@@ -250,8 +254,8 @@ const ct = ({
250
254
  content: "正在展开...",
251
255
  duration: 0
252
256
  });
253
- const n = await ae({ uri: e, queryType: 1, kgId: d, zktype: t.zktype }), { elements: r, typeListObj: g, relationListObj: x } = Z(n.data, { graphData: v, typeObj: b, relationObj: O, zktype: t.zktype });
254
- if (I(g), B(x), !((r == null ? void 0 : r.length) > 0)) {
257
+ const n = await ae({ uri: t, queryType: 1, kgId: d, zktype: e.zktype }), { elements: r, typeListObj: p, relationListObj: x } = Z(n.data, { graphData: v, typeObj: b, relationObj: O, zktype: e.zktype });
258
+ if (I(p), B(x), !((r == null ? void 0 : r.length) > 0)) {
255
259
  setTimeout(() => {
256
260
  h.destroy(), h.warning("暂无数据");
257
261
  }, 2e3);
@@ -259,19 +263,19 @@ const ct = ({
259
263
  }
260
264
  const A = s.zoom();
261
265
  if ((r == null ? void 0 : r.length) > 0) {
262
- const l = r.map((p) => {
263
- if (p.group === "nodes") {
266
+ const l = r.map((y) => {
267
+ if (y.group === "nodes") {
264
268
  const R = Se * K;
265
269
  return {
266
- ...p,
270
+ ...y,
267
271
  // position,
268
272
  style: { opacity: 0, width: R, height: R },
269
273
  data: {
270
- ...p.data,
271
- parentId: e,
272
- appendedBy: e,
273
- idLabel: e + "-" + p.data.label,
274
- zktype: t.zktype,
274
+ ...y.data,
275
+ parentId: t,
276
+ appendedBy: t,
277
+ idLabel: t + "-" + y.data.label,
278
+ zktype: e.zktype,
275
279
  isAppended: !0,
276
280
  baseWidth: 80,
277
281
  baseHeight: 80
@@ -279,14 +283,11 @@ const ct = ({
279
283
  };
280
284
  }
281
285
  return {
282
- ...p,
283
- data: { ...p.data, appendedBy: e, zktype: t.zktype }
286
+ ...y,
287
+ data: { ...y.data, appendedBy: t, zktype: e.zktype }
284
288
  };
285
289
  });
286
- console.log(888, l), s.nodes().forEach((p) => {
287
- if (p.data("id") !== e)
288
- return p.lock();
289
- });
290
+ console.log(888, l), s.nodes().lock(), i.unlock();
290
291
  const j = s.add(l).filter(":node");
291
292
  j.style("opacity", 0), ye({ addedNodes: j, currentNode: i, cy: s, currentZoom: A });
292
293
  } else
@@ -297,18 +298,18 @@ const ct = ({
297
298
  }
298
299
  U(!1);
299
300
  }
300
- P({ visible: !1 });
301
+ N({ visible: !1 });
301
302
  }, he = {
302
303
  expanded: "typed-literal",
303
304
  contract: "uri"
304
- }, ve = (t, e) => {
305
+ }, ve = (e, t) => {
305
306
  var s;
306
- console.log("handleMenuAction:::", t, e);
307
- const d = e || f.targetNode;
307
+ console.log("handleMenuAction:::", e, t);
308
+ const d = t || u.targetNode;
308
309
  if (d) {
309
- const i = t.ids, a = d.data();
310
+ const i = e.ids, a = d.data();
310
311
  if (["expanded", "contract"].includes(i))
311
- me({ kgId: u.kgId, ...a, zktype: he[i] });
312
+ me({ kgId: g.kgId, ...a, zktype: he[i] });
312
313
  else if (i === "nodeInfo") {
313
314
  const o = d, n = {
314
315
  id: o.id(),
@@ -322,38 +323,38 @@ const ct = ({
322
323
  };
323
324
  Y.current.open(n);
324
325
  } else i === "knowledgeCard" && _.current.open(d.data());
325
- (s = t.onClick) == null || s.call(t, d), P({ visible: !1, x: 0, y: 0, targetNode: null });
326
+ (s = e.onClick) == null || s.call(e, d), N({ visible: !1, x: 0, y: 0, targetNode: null });
326
327
  }
327
328
  }, be = () => {
328
- const t = {};
329
- return Object.keys(b).forEach((e) => {
330
- e !== "_" && (t[e] = b[e]);
331
- }), t;
329
+ const e = {};
330
+ return Object.keys(b).forEach((t) => {
331
+ t !== "_" && (e[t] = b[t]);
332
+ }), e;
332
333
  };
333
- return /* @__PURE__ */ y(Me, { value: { pathNodes: ue, setPathNodes: J, graphInfo: u, graphData: v, layoutType: pe, setLayoutType: ge, knowledgeCardApi: re, queryStatisticsConfig: le, actionBar: ie }, children: /* @__PURE__ */ ne("div", { className: We("cytoscape-container relative", ce), children: [
334
- /* @__PURE__ */ y("div", { className: "btn-group" }),
335
- /* @__PURE__ */ y(
334
+ return /* @__PURE__ */ f(Me, { value: { pathNodes: ue, setPathNodes: J, graphInfo: g, graphData: v, layoutType: pe, setLayoutType: ge, knowledgeCardApi: re, queryStatisticsConfig: le, actionBar: ie }, children: /* @__PURE__ */ ne("div", { className: We("cytoscape-container relative", ce), children: [
335
+ /* @__PURE__ */ f("div", { className: "btn-group" }),
336
+ /* @__PURE__ */ f(
336
337
  we,
337
338
  {
338
339
  ref: q,
339
340
  cyRef: c,
340
- graphInfo: u,
341
+ graphInfo: g,
341
342
  initNodeScale: K,
342
343
  cyContainerRef: L,
343
344
  typeObj: be(),
344
345
  relationObj: O,
345
- colors: N
346
+ colors: P
346
347
  }
347
348
  ),
348
349
  /* @__PURE__ */ ne("div", { className: "relative h-100", children: [
349
- /* @__PURE__ */ y("div", { ref: L, className: "cy-container" }),
350
- f.visible && f.targetNode && /* @__PURE__ */ y(
350
+ /* @__PURE__ */ f("div", { ref: L, className: "cy-container" }),
351
+ u.visible && u.targetNode && /* @__PURE__ */ f(
351
352
  "div",
352
353
  {
353
354
  style: {
354
355
  position: "absolute",
355
- left: `${f.x}px`,
356
- top: `${f.y}px`,
356
+ left: `${u.x}px`,
357
+ top: `${u.y}px`,
357
358
  // backgroundColor: 'white',
358
359
  // border: '1px solid #ccc',
359
360
  // borderRadius: '50%',
@@ -366,11 +367,11 @@ const ct = ({
366
367
  height: "200px",
367
368
  overflow: "hidden"
368
369
  },
369
- onClick: (t) => t.stopPropagation(),
370
- children: /* @__PURE__ */ y(Ie, { items: fe, centerImage: (G = f == null ? void 0 : f.targetNode) == null ? void 0 : G.data().image, targetNode: f.targetNode, onClick: (t, e) => ve(t, e) })
370
+ onClick: (e) => e.stopPropagation(),
371
+ children: /* @__PURE__ */ f(Ie, { items: fe, centerImage: (G = u == null ? void 0 : u.targetNode) == null ? void 0 : G.data().image, targetNode: u.targetNode, onClick: (e, t) => ve(e, t) })
371
372
  }
372
373
  ),
373
- D.visible && /* @__PURE__ */ y(
374
+ D.visible && /* @__PURE__ */ f(
374
375
  "div",
375
376
  {
376
377
  style: {
@@ -394,8 +395,8 @@ const ct = ({
394
395
  }
395
396
  )
396
397
  ] }),
397
- /* @__PURE__ */ y(Be, { ref: Y, cyRef: c }),
398
- /* @__PURE__ */ y(Ae, { ref: _ })
398
+ /* @__PURE__ */ f(Be, { ref: Y, cyRef: c }),
399
+ /* @__PURE__ */ f(Ae, { ref: _ })
399
400
  ] }) });
400
401
  };
401
402
  export {
package/lib/index.es45.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as i } from "react/jsx-runtime";
2
2
  import { useState as m, useEffect as w } from "react";
3
- import h from "./index.es50.js";
3
+ import h from "./index.es47.js";
4
4
  const k = ({ relations: t, kgIds: s, viewMode: a = "list", source: c = "" }) => {
5
5
  const [d, l] = m(t);
6
6
  w(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-kggraph",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "A knowledge graph visualization component based on Cytoscape",
5
5
  "type": "module",
6
6
  "main": "./lib/index.es.js",
File without changes