react-beauti-graph 0.0.0-stage → 1.3.0
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/LICENSE +191 -0
- package/NOTICE +8 -0
- package/README.md +371 -2
- package/dist/default_setting.d.cts +17 -0
- package/dist/default_setting.d.ts +17 -0
- package/dist/graphFactory.d.cts +244 -0
- package/dist/graphFactory.d.ts +244 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +868 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +356 -0
- package/package.json +92 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect as e, useId as t, useRef as n, useState as r } from "react";
|
|
3
|
+
import i from "cytoscape";
|
|
4
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
5
|
+
// src/default_setting.ts
|
|
6
|
+
var s = "#e91e63", c = "#2e7d32", l = "#7b1fa2", u = "#efeb00", d = "#8b4513", f = "rgb(239, 108, 0)", p = "22px", m = "18px", h = "#0066cc", g = "#fff", _ = "#f0f8ff", v = 2, y = -8, b = 16, x = 16, S = 14, C = [
|
|
7
|
+
["top", "Font Top Panel"],
|
|
8
|
+
["right", "Font Right Panel"],
|
|
9
|
+
["graph", "Font Graph Panel"]
|
|
10
|
+
], w = "Helvetica Neue, Helvetica, Arial, sans-serif", T = 1.2, E = .6, D = "macromolecule", O = "compartment", k = `node[class = "${D}"]`, A;
|
|
11
|
+
function j(e, t) {
|
|
12
|
+
if (A === void 0) try {
|
|
13
|
+
A = document.createElement("canvas").getContext("2d");
|
|
14
|
+
} catch {
|
|
15
|
+
A = null;
|
|
16
|
+
}
|
|
17
|
+
return A ? (A.font = `${t}px ${w}`, A.measureText(e).width) : e.length * t * E;
|
|
18
|
+
}
|
|
19
|
+
function ee(e, t = x) {
|
|
20
|
+
return {
|
|
21
|
+
width: Math.ceil(j(e ?? "", t)) + 8,
|
|
22
|
+
height: Math.ceil(t * T) + 8
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function M(e, t) {
|
|
26
|
+
return e.localeCompare(t, void 0, {
|
|
27
|
+
numeric: !0,
|
|
28
|
+
sensitivity: "base"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function N(e = []) {
|
|
32
|
+
let t = /* @__PURE__ */ new Map();
|
|
33
|
+
return e.map((e) => e.map((e) => {
|
|
34
|
+
let n = t.get(e) ?? 0;
|
|
35
|
+
if (t.set(e, n + 1), n === 0) return e;
|
|
36
|
+
let r = `${e}(${n})`;
|
|
37
|
+
return console.warn(`layout: duplicate id "${e}" — renamed to "${r}"`), r;
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
function te(e, t, n = {}) {
|
|
41
|
+
let { startX: r = 0, startY: i = 0, offsetX: a = 200, offsetY: o = 200, base: s = 1 } = n, c = /* @__PURE__ */ new Set();
|
|
42
|
+
t.forEach((t, n) => {
|
|
43
|
+
t.forEach((t, l) => {
|
|
44
|
+
let u = t, d = e.getElementById(u);
|
|
45
|
+
if (d.empty()) {
|
|
46
|
+
let n = /^(.+)\((\d+)\)$/.exec(t)?.[1];
|
|
47
|
+
n !== void 0 && e.getElementById(n).nonempty() && (u = n, d = e.getElementById(u), console.warn(`applyLayout: "${t}" not found — using "${u}" instead`));
|
|
48
|
+
}
|
|
49
|
+
d.empty() ? console.warn(`applyLayout: node "${t}" not found`) : c.has(u) ? console.warn(`applyLayout: duplicate layout entry for node "${u}" (from "${t}") — keeping the first position`) : (c.add(u), d.position({
|
|
50
|
+
x: r + (l + s) * a,
|
|
51
|
+
y: i + (n + s) * o
|
|
52
|
+
}));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function P(e, t) {
|
|
57
|
+
let n = e, r = 2;
|
|
58
|
+
for (; t.has(n);) n = `${e}_${r++}`;
|
|
59
|
+
return t.add(n), n;
|
|
60
|
+
}
|
|
61
|
+
function F(e, t = 10) {
|
|
62
|
+
let n = Math.max(1, Math.floor(t) || 1), r = e.filter((e) => e.data.class === D), i = e.filter((e) => e.data.class === O).map((e) => r.filter((t) => t.data.parent === e.data.id));
|
|
63
|
+
i.push(r.filter((e) => !e.data.parent));
|
|
64
|
+
let a = [];
|
|
65
|
+
for (let e of i) for (let t = 0; t < e.length; t += n) a.push(e.slice(t, t + n).map((e) => e.data.id));
|
|
66
|
+
return a;
|
|
67
|
+
}
|
|
68
|
+
function I(e = {}, t = [], n = []) {
|
|
69
|
+
let r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set([...t.flat(), ...n]);
|
|
70
|
+
for (let t of Object.values(e)) for (let e of t) i.add(e);
|
|
71
|
+
for (let e of a) i.add(e);
|
|
72
|
+
let o = (e) => {
|
|
73
|
+
let t = e.replace(/\s+/g, "");
|
|
74
|
+
return t ? t.charAt(0).toLowerCase() + t.slice(1) : "folder";
|
|
75
|
+
}, s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
|
|
76
|
+
for (let [t, n] of Object.entries(e)) {
|
|
77
|
+
let e = P(o(t), i);
|
|
78
|
+
c.set(t, e), r.push({ data: {
|
|
79
|
+
id: e,
|
|
80
|
+
class: O,
|
|
81
|
+
label: t
|
|
82
|
+
} });
|
|
83
|
+
for (let e of n) {
|
|
84
|
+
let n = s.get(e) ?? [], r = e;
|
|
85
|
+
if (n.length > 0) {
|
|
86
|
+
let t = n.length;
|
|
87
|
+
for (r = `${e}(${t})`; i.has(r);) r = `${e}(${++t})`;
|
|
88
|
+
i.add(r);
|
|
89
|
+
}
|
|
90
|
+
n.push({
|
|
91
|
+
actualId: r,
|
|
92
|
+
folderLabel: t
|
|
93
|
+
}), s.set(e, n);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let l = [];
|
|
97
|
+
for (let [e, t] of s) for (let { actualId: n, folderLabel: r } of t) l.push({
|
|
98
|
+
actualId: n,
|
|
99
|
+
originalId: e,
|
|
100
|
+
folderLabel: r
|
|
101
|
+
});
|
|
102
|
+
for (let e of a) s.has(e) || l.push({
|
|
103
|
+
actualId: e,
|
|
104
|
+
originalId: e,
|
|
105
|
+
folderLabel: null
|
|
106
|
+
});
|
|
107
|
+
for (let { actualId: e, originalId: t, folderLabel: n } of l) {
|
|
108
|
+
let i = {
|
|
109
|
+
id: e,
|
|
110
|
+
class: D,
|
|
111
|
+
rawLabel: t,
|
|
112
|
+
displayLabel: n ? `${t} (${n})` : t,
|
|
113
|
+
group: n
|
|
114
|
+
};
|
|
115
|
+
n && (i.parent = c.get(n)), r.push({ data: i });
|
|
116
|
+
}
|
|
117
|
+
let u = (e) => s.get(e)?.[0]?.actualId ?? e, d = (e, t) => `${e}->${t}`, f = /* @__PURE__ */ new Map();
|
|
118
|
+
return t.forEach(([e, t], n) => {
|
|
119
|
+
let a = u(e), o = u(t);
|
|
120
|
+
if (f.has(d(a, o))) return;
|
|
121
|
+
let s = f.get(d(o, a));
|
|
122
|
+
if (s) {
|
|
123
|
+
s.classes = "bidirectional";
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
let c = { data: {
|
|
127
|
+
id: P(`e${n + 1}`, i),
|
|
128
|
+
source: a,
|
|
129
|
+
target: o
|
|
130
|
+
} };
|
|
131
|
+
f.set(d(a, o), c), r.push(c);
|
|
132
|
+
}), r;
|
|
133
|
+
}
|
|
134
|
+
function ne(e, t, n) {
|
|
135
|
+
return e.filter((e) => t || e.data.class !== O).map((e) => {
|
|
136
|
+
if (e.data.class !== D) return {
|
|
137
|
+
...e,
|
|
138
|
+
data: { ...e.data }
|
|
139
|
+
};
|
|
140
|
+
let t = n ? e.data.displayLabel : e.data.rawLabel;
|
|
141
|
+
return {
|
|
142
|
+
...e,
|
|
143
|
+
data: {
|
|
144
|
+
...e.data,
|
|
145
|
+
graphLabel: t
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function L(e, t = !1) {
|
|
151
|
+
let n = (e) => ({
|
|
152
|
+
id: e.id(),
|
|
153
|
+
name: e.data("rawLabel") ?? e.id(),
|
|
154
|
+
group: e.data("group") ?? null
|
|
155
|
+
}), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
156
|
+
if (e.connectedEdges().forEach((t) => {
|
|
157
|
+
let a = t.hasClass("bidirectional");
|
|
158
|
+
t.target().same(e) && (r.set(t.source().id(), n(t.source())), a && i.set(t.source().id(), n(t.source()))), t.source().same(e) && (i.set(t.target().id(), n(t.target())), a && r.set(t.target().id(), n(t.target())));
|
|
159
|
+
}), t) {
|
|
160
|
+
let t = [[r, "parents"], [i, "children"]];
|
|
161
|
+
for (let [r, i] of t) r.clear(), R(e, i).nodes().forEach((t) => {
|
|
162
|
+
t.same(e) || r.set(t.id(), n(t));
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
let a = (e, t) => M(e.name, t.name);
|
|
166
|
+
return {
|
|
167
|
+
...n(e),
|
|
168
|
+
parents: [...r.values()].sort(a),
|
|
169
|
+
children: [...i.values()].sort(a)
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function R(e, t) {
|
|
173
|
+
let n = t === "parents", r = e.cy().collection(), i = /* @__PURE__ */ new Set([e.id()]), a = [e];
|
|
174
|
+
for (let e = a.shift(); e !== void 0; e = a.shift()) {
|
|
175
|
+
let t = e;
|
|
176
|
+
t.connectedEdges().forEach((e) => {
|
|
177
|
+
let o = e.hasClass("bidirectional"), s = null;
|
|
178
|
+
e.target().same(t) && (n || o) && (s = e.source()), e.source().same(t) && (!n || o) && (s = e.target()), s && (r = r.union(e), i.has(s.id()) || (i.add(s.id()), a.push(s)));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return r.union(e.cy().nodes().filter((e) => i.has(e.id())));
|
|
182
|
+
}
|
|
183
|
+
function z(e) {
|
|
184
|
+
return [["Parent Nodes", e.parents], ["Child Nodes", e.children]].filter(([, e]) => e.length > 0);
|
|
185
|
+
}
|
|
186
|
+
function re(e, t) {
|
|
187
|
+
let n = e.nodes(k).filter((e) => t.has(e.id())), r = e.nodes(":parent").filter((e) => e.children().every((e) => n.has(e)));
|
|
188
|
+
return n.union(r);
|
|
189
|
+
}
|
|
190
|
+
function B(e) {
|
|
191
|
+
let t = (e) => e.group ? `${e.name} (${e.group})` : e.name, n = [`Node: ${e.name}`];
|
|
192
|
+
e.group && n.push(`Group: ${e.group}`);
|
|
193
|
+
for (let [r, i] of z(e)) n.push("", `${r} (${i.length}):`, ...i.map(t));
|
|
194
|
+
return n.join("\n");
|
|
195
|
+
}
|
|
196
|
+
function V(e) {
|
|
197
|
+
let t = /^#([0-9a-f]{6})$/i.exec(e)?.[1];
|
|
198
|
+
if (t !== void 0) return parseInt(t, 16);
|
|
199
|
+
let n = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i.exec(e);
|
|
200
|
+
if (n === null) return null;
|
|
201
|
+
let [r = 0, i = 0, a = 0] = n.slice(1).map((e) => Math.min(Number(e), 255));
|
|
202
|
+
return r << 16 | i << 8 | a;
|
|
203
|
+
}
|
|
204
|
+
function H(e, t = .88) {
|
|
205
|
+
let n = V(e);
|
|
206
|
+
return n === null ? "#ffffff" : `#${[
|
|
207
|
+
16,
|
|
208
|
+
8,
|
|
209
|
+
0
|
|
210
|
+
].map((e) => {
|
|
211
|
+
let r = n >> e & 255;
|
|
212
|
+
return Math.round(r + (255 - r) * t).toString(16).padStart(2, "0");
|
|
213
|
+
}).join("")}`;
|
|
214
|
+
}
|
|
215
|
+
function ie(e, t, n = f) {
|
|
216
|
+
let r = ["track", "track2"], i = r.flatMap((e) => [
|
|
217
|
+
`${e}-parents`,
|
|
218
|
+
`${e}-children`,
|
|
219
|
+
`${e}-root`
|
|
220
|
+
]).concat("faded", "track-mixed").join(" ");
|
|
221
|
+
e.batch(() => {
|
|
222
|
+
e.elements().removeClass(i).removeData("trackMixColor trackMixFill");
|
|
223
|
+
let a = t.map(({ id: t, direction: n }, i) => {
|
|
224
|
+
if (!t) return null;
|
|
225
|
+
let a = e.getElementById(t);
|
|
226
|
+
if (a.empty()) return null;
|
|
227
|
+
let o = R(a, n), s = r[i] ?? "track";
|
|
228
|
+
return o.addClass(`${s}-${n}`), a.addClass(`${s}-root`), o;
|
|
229
|
+
}), o = a.filter((e) => e !== null);
|
|
230
|
+
if (o.length === 0) return;
|
|
231
|
+
let [s, c] = a;
|
|
232
|
+
s && c && s.intersection(c).forEach((e) => {
|
|
233
|
+
e.data({
|
|
234
|
+
trackMixColor: n,
|
|
235
|
+
trackMixFill: H(n)
|
|
236
|
+
}), e.addClass("track-mixed");
|
|
237
|
+
});
|
|
238
|
+
let l = o.reduce((e, t) => e.union(t));
|
|
239
|
+
e.elements().not(l).not("node:parent").addClass("faded");
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function U({ selectedColor: e = s, parentsColor: t = c, childrenColor: n = l, track2ParentsColor: r = u, track2ChildrenColor: i = d } = {}) {
|
|
243
|
+
return [
|
|
244
|
+
{
|
|
245
|
+
selector: "node",
|
|
246
|
+
style: {
|
|
247
|
+
"background-color": g,
|
|
248
|
+
label: "data(graphLabel)",
|
|
249
|
+
shape: "rectangle",
|
|
250
|
+
"font-family": w,
|
|
251
|
+
"font-size": x,
|
|
252
|
+
color: h,
|
|
253
|
+
"border-width": 2,
|
|
254
|
+
"border-color": h,
|
|
255
|
+
"text-valign": "center",
|
|
256
|
+
"text-halign": "center"
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
selector: "node:parent",
|
|
261
|
+
style: {
|
|
262
|
+
"background-color": _,
|
|
263
|
+
"background-opacity": .5,
|
|
264
|
+
"border-style": "dashed",
|
|
265
|
+
label: "data(label)",
|
|
266
|
+
"text-valign": "top",
|
|
267
|
+
"font-size": S,
|
|
268
|
+
"font-weight": "bold",
|
|
269
|
+
padding: "18px"
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
selector: ".selected",
|
|
274
|
+
style: {
|
|
275
|
+
"overlay-color": e,
|
|
276
|
+
"overlay-opacity": .35,
|
|
277
|
+
"overlay-padding": 8
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
selector: "edge",
|
|
282
|
+
style: {
|
|
283
|
+
"line-color": h,
|
|
284
|
+
width: 2,
|
|
285
|
+
"curve-style": "bezier",
|
|
286
|
+
"target-arrow-shape": "vee",
|
|
287
|
+
"target-arrow-color": h,
|
|
288
|
+
"target-arrow-fill": "filled",
|
|
289
|
+
"arrow-scale": 2
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
selector: "edge:loop",
|
|
294
|
+
style: {
|
|
295
|
+
"loop-direction": "0deg",
|
|
296
|
+
"loop-sweep": "-50deg",
|
|
297
|
+
"control-point-step-size": 70
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
selector: "edge.bidirectional",
|
|
302
|
+
style: {
|
|
303
|
+
"source-arrow-shape": "vee",
|
|
304
|
+
"source-arrow-color": h,
|
|
305
|
+
"source-arrow-fill": "filled"
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
selector: ".faded",
|
|
310
|
+
style: { opacity: .15 }
|
|
311
|
+
},
|
|
312
|
+
...[
|
|
313
|
+
[
|
|
314
|
+
"track-parents",
|
|
315
|
+
"track-root",
|
|
316
|
+
t
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
"track-children",
|
|
320
|
+
"track-root",
|
|
321
|
+
n
|
|
322
|
+
],
|
|
323
|
+
[
|
|
324
|
+
"track2-parents",
|
|
325
|
+
"track2-root",
|
|
326
|
+
r
|
|
327
|
+
],
|
|
328
|
+
[
|
|
329
|
+
"track2-children",
|
|
330
|
+
"track2-root",
|
|
331
|
+
i
|
|
332
|
+
]
|
|
333
|
+
].flatMap(([e, t, n]) => [
|
|
334
|
+
{
|
|
335
|
+
selector: `edge.${e}`,
|
|
336
|
+
style: {
|
|
337
|
+
"line-color": n,
|
|
338
|
+
"target-arrow-color": n,
|
|
339
|
+
"source-arrow-color": n,
|
|
340
|
+
width: 4
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
selector: `node.${e}`,
|
|
345
|
+
style: {
|
|
346
|
+
"border-color": n,
|
|
347
|
+
"border-width": 3
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
selector: `node.${e}.${t}`,
|
|
352
|
+
style: {
|
|
353
|
+
"border-width": 5,
|
|
354
|
+
"background-color": H(n)
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
]),
|
|
358
|
+
{
|
|
359
|
+
selector: "edge.track-mixed",
|
|
360
|
+
style: {
|
|
361
|
+
"line-color": "data(trackMixColor)",
|
|
362
|
+
"target-arrow-color": "data(trackMixColor)",
|
|
363
|
+
"source-arrow-color": "data(trackMixColor)",
|
|
364
|
+
width: 5
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
selector: "node.track-mixed",
|
|
369
|
+
style: {
|
|
370
|
+
"border-color": "data(trackMixColor)",
|
|
371
|
+
"border-width": 4
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
selector: "node.track-mixed.track-root, node.track-mixed.track2-root",
|
|
376
|
+
style: {
|
|
377
|
+
"border-width": 6,
|
|
378
|
+
"background-color": "data(trackMixFill)"
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
selector: ".hidden",
|
|
383
|
+
style: { display: "none" }
|
|
384
|
+
}
|
|
385
|
+
];
|
|
386
|
+
}
|
|
387
|
+
var W = "ALL";
|
|
388
|
+
function G({ id: t, options: i, selectedId: s, onSelect: c, noneLabel: l = W, hiddenIds: u, onToggleVisible: d }) {
|
|
389
|
+
let [f, p] = r(""), [m, h] = r(""), [g, _] = r(!1), [v, y] = r(0), b = n(null), x = n(null), S = i.find((e) => e.id === s)?.label ?? "", [C, w] = r(null);
|
|
390
|
+
C !== S && (w(S), p(S));
|
|
391
|
+
let T = m.trim().toLowerCase(), E = T ? i.filter((e) => e.label.toLowerCase().includes(T)) : i, D = {
|
|
392
|
+
id: "",
|
|
393
|
+
label: l
|
|
394
|
+
}, O = !T || l.toLowerCase().includes(T) ? [D, ...E] : E, k = () => {
|
|
395
|
+
h(""), y(0), _(!0);
|
|
396
|
+
}, A = () => {
|
|
397
|
+
_(!1), h(""), p(S);
|
|
398
|
+
}, j = (e) => {
|
|
399
|
+
c(e.id), p(e.id ? e.label : ""), h(""), _(!1);
|
|
400
|
+
};
|
|
401
|
+
return e(() => {
|
|
402
|
+
if (!g) return;
|
|
403
|
+
let e = (e) => {
|
|
404
|
+
b.current?.contains(e.target) || A();
|
|
405
|
+
};
|
|
406
|
+
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
407
|
+
}), e(() => {
|
|
408
|
+
x.current?.children[v]?.scrollIntoView({ block: "nearest" });
|
|
409
|
+
}, [v, g]), /* @__PURE__ */ o("div", {
|
|
410
|
+
className: "node-search",
|
|
411
|
+
ref: b,
|
|
412
|
+
children: [
|
|
413
|
+
/* @__PURE__ */ a("input", {
|
|
414
|
+
id: t,
|
|
415
|
+
type: "text",
|
|
416
|
+
value: f,
|
|
417
|
+
placeholder: "-- type to search --",
|
|
418
|
+
autoComplete: "off",
|
|
419
|
+
onChange: (e) => {
|
|
420
|
+
p(e.target.value), h(e.target.value), y(0), _(!0);
|
|
421
|
+
},
|
|
422
|
+
onFocus: (e) => {
|
|
423
|
+
e.target.select(), k();
|
|
424
|
+
},
|
|
425
|
+
onClick: () => {
|
|
426
|
+
g || k();
|
|
427
|
+
},
|
|
428
|
+
onKeyDown: (e) => {
|
|
429
|
+
if (e.key === "ArrowDown") e.preventDefault(), g || _(!0), y((e) => Math.min(e + 1, O.length - 1));
|
|
430
|
+
else if (e.key === "ArrowUp") e.preventDefault(), y((e) => Math.max(e - 1, 0));
|
|
431
|
+
else if (e.key === "Enter" && g) {
|
|
432
|
+
let t = O[v];
|
|
433
|
+
t && (e.preventDefault(), j(t));
|
|
434
|
+
} else e.key === "Escape" && A();
|
|
435
|
+
}
|
|
436
|
+
}),
|
|
437
|
+
f && /* @__PURE__ */ a("button", {
|
|
438
|
+
type: "button",
|
|
439
|
+
className: "node-search-clear",
|
|
440
|
+
"aria-label": "Clear",
|
|
441
|
+
onClick: () => {
|
|
442
|
+
c(""), p(""), h("");
|
|
443
|
+
},
|
|
444
|
+
children: "×"
|
|
445
|
+
}),
|
|
446
|
+
g && /* @__PURE__ */ a("ul", {
|
|
447
|
+
className: "node-search-list",
|
|
448
|
+
ref: x,
|
|
449
|
+
role: "listbox",
|
|
450
|
+
children: O.length === 0 ? /* @__PURE__ */ a("li", {
|
|
451
|
+
className: "node-search-empty",
|
|
452
|
+
role: "option",
|
|
453
|
+
"aria-selected": "false",
|
|
454
|
+
"aria-disabled": "true",
|
|
455
|
+
children: "no match"
|
|
456
|
+
}) : O.map((e, t) => /* @__PURE__ */ o("li", {
|
|
457
|
+
role: "option",
|
|
458
|
+
"aria-selected": t === v,
|
|
459
|
+
className: [t === v && "active", u?.has(e.id) && "off"].filter(Boolean).join(" ") || void 0,
|
|
460
|
+
onMouseDown: (t) => {
|
|
461
|
+
t.preventDefault(), j(e);
|
|
462
|
+
},
|
|
463
|
+
onMouseEnter: () => y(t),
|
|
464
|
+
children: [d && e.id && /* @__PURE__ */ a("input", {
|
|
465
|
+
type: "checkbox",
|
|
466
|
+
checked: !u?.has(e.id),
|
|
467
|
+
"aria-label": `Show ${e.label}`,
|
|
468
|
+
onMouseDown: (e) => {
|
|
469
|
+
e.preventDefault(), e.stopPropagation();
|
|
470
|
+
},
|
|
471
|
+
onClick: (e) => e.stopPropagation(),
|
|
472
|
+
onChange: () => d(e.id)
|
|
473
|
+
}), e.label]
|
|
474
|
+
}, e.id || "__none__"))
|
|
475
|
+
})
|
|
476
|
+
]
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
function K(h = {}, g = [], _ = null, w = {}) {
|
|
480
|
+
let T = Array.isArray(_) ? _ : null, E = _ !== null && !Array.isArray(_) ? _ : w, D = T !== null && T.length > 0, { selectedColor: O = s, parentsColor: A = c, childrenColor: j = l, track2ParentsColor: P = u, track2ChildrenColor: R = d, commonColor: V = f, topControlsFontSize: H = p, rightDisplayFontSize: W = m, layoutColumns: K = 10 } = E, ae = U({
|
|
481
|
+
selectedColor: O,
|
|
482
|
+
parentsColor: A,
|
|
483
|
+
childrenColor: j,
|
|
484
|
+
track2ParentsColor: P,
|
|
485
|
+
track2ChildrenColor: R
|
|
486
|
+
}), oe = {
|
|
487
|
+
"--rbg-parents-color": A,
|
|
488
|
+
"--rbg-children-color": j
|
|
489
|
+
}, se = {
|
|
490
|
+
"--rbg-parents-color": P,
|
|
491
|
+
"--rbg-children-color": R
|
|
492
|
+
}, q = I(h, g, T !== null && D ? T.flat() : []), ce = T !== null && D ? N(T) : F(q, K);
|
|
493
|
+
function J() {
|
|
494
|
+
let s = n(null), c = n(null), l = t(), [u, d] = r([]), [f, p] = r(""), [m, h] = r(0), [g, _] = r(""), [w, T] = r("parents"), [D, O] = r(""), [A, j] = r("parents"), [N, P] = r(!0), [F, I] = r(!0), [R, U] = r(null), [K, J] = r(null), [Y, le] = r("top"), [X, ue] = r({
|
|
495
|
+
top: 0,
|
|
496
|
+
right: 0,
|
|
497
|
+
graph: 0
|
|
498
|
+
}), [Z, de] = r(!1), Q = n(!1);
|
|
499
|
+
e(() => {
|
|
500
|
+
Q.current = Z;
|
|
501
|
+
}, [Z]);
|
|
502
|
+
let [$, fe] = r(() => /* @__PURE__ */ new Set());
|
|
503
|
+
e(() => {
|
|
504
|
+
let e = s.current;
|
|
505
|
+
if (!e) return;
|
|
506
|
+
let t = i({
|
|
507
|
+
container: e,
|
|
508
|
+
elements: ne(q, N, F),
|
|
509
|
+
style: ae,
|
|
510
|
+
layout: {
|
|
511
|
+
name: "preset",
|
|
512
|
+
fit: !1
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
t.on("cxttap", k, (e) => {
|
|
516
|
+
let t = B(L(e.target, Q.current)), { clientX: n, clientY: r } = e.originalEvent;
|
|
517
|
+
U({
|
|
518
|
+
x: n,
|
|
519
|
+
y: r,
|
|
520
|
+
copyText: t
|
|
521
|
+
});
|
|
522
|
+
}), t.on("dbltap", k, (e) => {
|
|
523
|
+
J(L(e.target, Q.current));
|
|
524
|
+
}), t.on("tap cxttap", (e) => {
|
|
525
|
+
e.target === t && U(null);
|
|
526
|
+
}), t.on("tap", "node", () => U(null)), t.on("viewport", () => U(null));
|
|
527
|
+
let n = (e) => e.preventDefault();
|
|
528
|
+
return e.addEventListener("contextmenu", n), te(t, ce, E), requestAnimationFrame(() => t.resize()), d(t.nodes(k).map((e) => ({
|
|
529
|
+
id: e.id(),
|
|
530
|
+
label: e.data("displayLabel")
|
|
531
|
+
})).sort((e, t) => M(e.label, t.label))), c.current = t, () => {
|
|
532
|
+
e.removeEventListener("contextmenu", n), U(null), t.destroy(), c.current = null;
|
|
533
|
+
};
|
|
534
|
+
}, [N, F]), e(() => {
|
|
535
|
+
let e = c.current;
|
|
536
|
+
if (!e) return;
|
|
537
|
+
let t = X.graph;
|
|
538
|
+
e.batch(() => {
|
|
539
|
+
e.nodes(k).forEach((e) => {
|
|
540
|
+
let n = x + t, { width: r, height: i } = ee(e.data("graphLabel"), n);
|
|
541
|
+
e.style({
|
|
542
|
+
"font-size": n,
|
|
543
|
+
width: r,
|
|
544
|
+
height: i
|
|
545
|
+
});
|
|
546
|
+
}), e.nodes(":parent").style("font-size", S + t);
|
|
547
|
+
});
|
|
548
|
+
}, [
|
|
549
|
+
X.graph,
|
|
550
|
+
N,
|
|
551
|
+
F
|
|
552
|
+
]), e(() => {
|
|
553
|
+
if (!R) return;
|
|
554
|
+
let e = (e) => {
|
|
555
|
+
e.target.closest(".node-context-menu") || U(null);
|
|
556
|
+
}, t = (e) => {
|
|
557
|
+
e.key === "Escape" && U(null);
|
|
558
|
+
};
|
|
559
|
+
return document.addEventListener("mousedown", e), document.addEventListener("keydown", t), () => {
|
|
560
|
+
document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
|
|
561
|
+
};
|
|
562
|
+
}, [R]);
|
|
563
|
+
let pe = () => {
|
|
564
|
+
if (R === null) return;
|
|
565
|
+
let { copyText: e } = R;
|
|
566
|
+
U(null), navigator.clipboard.writeText(e).catch((e) => {
|
|
567
|
+
console.error("Failed to copy:", e);
|
|
568
|
+
});
|
|
569
|
+
}, me = (e) => {
|
|
570
|
+
fe((t) => {
|
|
571
|
+
let n = new Set(t);
|
|
572
|
+
return n.has(e) ? n.delete(e) : n.add(e), n;
|
|
573
|
+
});
|
|
574
|
+
}, he = (e) => {
|
|
575
|
+
let t = c.current?.getElementById(e);
|
|
576
|
+
t && !t.empty() && ($.has(e) && me(e), p(e), J(L(t, Z)));
|
|
577
|
+
}, ge = () => {
|
|
578
|
+
p(""), J(null), h((e) => e + 1);
|
|
579
|
+
};
|
|
580
|
+
e(() => {
|
|
581
|
+
let e = c.current;
|
|
582
|
+
e && e.batch(() => {
|
|
583
|
+
e.elements().removeClass("hidden"), re(e, $).addClass("hidden");
|
|
584
|
+
});
|
|
585
|
+
}, [
|
|
586
|
+
$,
|
|
587
|
+
N,
|
|
588
|
+
F
|
|
589
|
+
]), e(() => {
|
|
590
|
+
let e = c.current;
|
|
591
|
+
m && e && (e.stop(), e.resize(), e.animate({ fit: {
|
|
592
|
+
eles: e.elements().not(".hidden"),
|
|
593
|
+
padding: 30
|
|
594
|
+
} }, { duration: 400 }));
|
|
595
|
+
}, [m]), e(() => {
|
|
596
|
+
let e = c.current;
|
|
597
|
+
if (!e || (e.nodes().removeClass("selected"), !f)) return;
|
|
598
|
+
let t = e.getElementById(f);
|
|
599
|
+
t.nonempty() && (t.addClass("selected"), e.animate({
|
|
600
|
+
center: { eles: t },
|
|
601
|
+
zoom: 1.8
|
|
602
|
+
}, { duration: 400 }));
|
|
603
|
+
}, [
|
|
604
|
+
f,
|
|
605
|
+
N,
|
|
606
|
+
F
|
|
607
|
+
]), e(() => {
|
|
608
|
+
let e = c.current;
|
|
609
|
+
e && ie(e, [{
|
|
610
|
+
id: g,
|
|
611
|
+
direction: w
|
|
612
|
+
}, {
|
|
613
|
+
id: D,
|
|
614
|
+
direction: A
|
|
615
|
+
}], V);
|
|
616
|
+
}, [
|
|
617
|
+
g,
|
|
618
|
+
w,
|
|
619
|
+
D,
|
|
620
|
+
A,
|
|
621
|
+
N,
|
|
622
|
+
F
|
|
623
|
+
]), e(() => {
|
|
624
|
+
c.current?.resize();
|
|
625
|
+
}, [K !== null]), e(() => {
|
|
626
|
+
let e = () => c.current?.resize();
|
|
627
|
+
return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
628
|
+
}, []);
|
|
629
|
+
let _e = [{
|
|
630
|
+
n: 1,
|
|
631
|
+
id: g,
|
|
632
|
+
setId: _,
|
|
633
|
+
direction: w,
|
|
634
|
+
setDirection: T,
|
|
635
|
+
style: void 0
|
|
636
|
+
}, {
|
|
637
|
+
n: 2,
|
|
638
|
+
id: D,
|
|
639
|
+
setId: O,
|
|
640
|
+
direction: A,
|
|
641
|
+
setDirection: j,
|
|
642
|
+
style: se
|
|
643
|
+
}], ve = [{
|
|
644
|
+
label: "Smaller text",
|
|
645
|
+
symbol: "−",
|
|
646
|
+
step: -2,
|
|
647
|
+
atLimit: X[Y] <= y
|
|
648
|
+
}, {
|
|
649
|
+
label: "Larger text",
|
|
650
|
+
symbol: "+",
|
|
651
|
+
step: v,
|
|
652
|
+
atLimit: X[Y] >= b
|
|
653
|
+
}];
|
|
654
|
+
return /* @__PURE__ */ o("div", {
|
|
655
|
+
className: "rbg-graph",
|
|
656
|
+
style: {
|
|
657
|
+
...oe,
|
|
658
|
+
"--rbg-top-controls-font-size": `calc(${H} + ${X.top}px)`,
|
|
659
|
+
"--rbg-right-display-font-size": `calc(${W} + ${X.right}px)`
|
|
660
|
+
},
|
|
661
|
+
children: [
|
|
662
|
+
/* @__PURE__ */ o("div", {
|
|
663
|
+
className: "controls",
|
|
664
|
+
children: [
|
|
665
|
+
/* @__PURE__ */ o("span", {
|
|
666
|
+
className: "control-group",
|
|
667
|
+
children: [/* @__PURE__ */ a("label", {
|
|
668
|
+
htmlFor: `${l}-search`,
|
|
669
|
+
children: "Node to Display:"
|
|
670
|
+
}), /* @__PURE__ */ a(G, {
|
|
671
|
+
id: `${l}-search`,
|
|
672
|
+
options: u,
|
|
673
|
+
selectedId: f,
|
|
674
|
+
onSelect: (e) => e ? he(e) : ge(),
|
|
675
|
+
hiddenIds: $,
|
|
676
|
+
onToggleVisible: me
|
|
677
|
+
})]
|
|
678
|
+
}),
|
|
679
|
+
/* @__PURE__ */ o("label", { children: [/* @__PURE__ */ a("input", {
|
|
680
|
+
type: "checkbox",
|
|
681
|
+
checked: N,
|
|
682
|
+
onChange: (e) => P(e.target.checked)
|
|
683
|
+
}), "Show Groups"] }),
|
|
684
|
+
/* @__PURE__ */ o("label", { children: [/* @__PURE__ */ a("input", {
|
|
685
|
+
type: "checkbox",
|
|
686
|
+
checked: F,
|
|
687
|
+
onChange: (e) => I(e.target.checked)
|
|
688
|
+
}), "Add Group to Node Name"] }),
|
|
689
|
+
_e.map(({ n: e, id: t, setId: n, direction: r, setDirection: i, style: s }) => /* @__PURE__ */ o("span", {
|
|
690
|
+
className: "control-group",
|
|
691
|
+
style: s,
|
|
692
|
+
children: [
|
|
693
|
+
/* @__PURE__ */ o("label", {
|
|
694
|
+
htmlFor: `${l}-track${e}`,
|
|
695
|
+
children: [
|
|
696
|
+
"Show Dependency ",
|
|
697
|
+
e,
|
|
698
|
+
":"
|
|
699
|
+
]
|
|
700
|
+
}),
|
|
701
|
+
/* @__PURE__ */ a(G, {
|
|
702
|
+
id: `${l}-track${e}`,
|
|
703
|
+
options: u,
|
|
704
|
+
selectedId: t,
|
|
705
|
+
onSelect: n,
|
|
706
|
+
noneLabel: "Show Nothing"
|
|
707
|
+
}),
|
|
708
|
+
/* @__PURE__ */ o("span", {
|
|
709
|
+
className: t ? "track-switch" : "track-switch disabled",
|
|
710
|
+
children: [
|
|
711
|
+
/* @__PURE__ */ a("span", {
|
|
712
|
+
className: r === "parents" ? "parents on" : "parents",
|
|
713
|
+
children: "Parents"
|
|
714
|
+
}),
|
|
715
|
+
/* @__PURE__ */ a("button", {
|
|
716
|
+
type: "button",
|
|
717
|
+
role: "switch",
|
|
718
|
+
"aria-checked": r === "children",
|
|
719
|
+
"aria-label": `Show Dependency ${e}: track children instead of parents`,
|
|
720
|
+
className: "switch",
|
|
721
|
+
disabled: !t,
|
|
722
|
+
onClick: () => i((e) => e === "parents" ? "children" : "parents"),
|
|
723
|
+
children: /* @__PURE__ */ a("span", { className: "switch-knob" })
|
|
724
|
+
}),
|
|
725
|
+
/* @__PURE__ */ a("span", {
|
|
726
|
+
className: r === "children" ? "children on" : "children",
|
|
727
|
+
children: "Children"
|
|
728
|
+
})
|
|
729
|
+
]
|
|
730
|
+
})
|
|
731
|
+
]
|
|
732
|
+
}, e)),
|
|
733
|
+
/* @__PURE__ */ o("span", {
|
|
734
|
+
className: "help",
|
|
735
|
+
children: [/* @__PURE__ */ a("button", {
|
|
736
|
+
type: "button",
|
|
737
|
+
className: "help-icon",
|
|
738
|
+
"aria-label": "Help",
|
|
739
|
+
"aria-describedby": `${l}-help`,
|
|
740
|
+
children: "?"
|
|
741
|
+
}), /* @__PURE__ */ o("span", {
|
|
742
|
+
id: `${l}-help`,
|
|
743
|
+
role: "tooltip",
|
|
744
|
+
className: "help-tooltip",
|
|
745
|
+
children: [
|
|
746
|
+
/* @__PURE__ */ a("strong", { children: "Double click" }),
|
|
747
|
+
" on a node to see its information, parents and children.",
|
|
748
|
+
/* @__PURE__ */ a("br", {}),
|
|
749
|
+
/* @__PURE__ */ a("strong", { children: "Right click" }),
|
|
750
|
+
" on a node to save the same information to the clipboard."
|
|
751
|
+
]
|
|
752
|
+
})]
|
|
753
|
+
}),
|
|
754
|
+
/* @__PURE__ */ o("span", {
|
|
755
|
+
className: "font-size-buttons",
|
|
756
|
+
children: [/* @__PURE__ */ a("select", {
|
|
757
|
+
"aria-label": "Area whose text size the + and - buttons change",
|
|
758
|
+
value: Y,
|
|
759
|
+
onChange: (e) => le(e.target.value),
|
|
760
|
+
children: C.map(([e, t]) => /* @__PURE__ */ a("option", {
|
|
761
|
+
value: e,
|
|
762
|
+
children: t
|
|
763
|
+
}, e))
|
|
764
|
+
}), ve.map(({ label: e, symbol: t, step: n, atLimit: r }) => /* @__PURE__ */ a("button", {
|
|
765
|
+
type: "button",
|
|
766
|
+
className: "help-icon",
|
|
767
|
+
"aria-label": e,
|
|
768
|
+
disabled: r,
|
|
769
|
+
onClick: () => ue((e) => ({
|
|
770
|
+
...e,
|
|
771
|
+
[Y]: e[Y] + n
|
|
772
|
+
})),
|
|
773
|
+
children: t
|
|
774
|
+
}, e))]
|
|
775
|
+
})
|
|
776
|
+
]
|
|
777
|
+
}),
|
|
778
|
+
/* @__PURE__ */ o("div", {
|
|
779
|
+
className: "graph-area",
|
|
780
|
+
children: [/* @__PURE__ */ a("div", {
|
|
781
|
+
ref: s,
|
|
782
|
+
className: "cy-container"
|
|
783
|
+
}), K && /* @__PURE__ */ o("aside", {
|
|
784
|
+
className: "node-info-panel",
|
|
785
|
+
children: [
|
|
786
|
+
/* @__PURE__ */ o("div", {
|
|
787
|
+
className: "node-info-header",
|
|
788
|
+
children: [/* @__PURE__ */ o("h2", { children: [
|
|
789
|
+
/* @__PURE__ */ a("strong", { children: "Node:" }),
|
|
790
|
+
" ",
|
|
791
|
+
K.name
|
|
792
|
+
] }), /* @__PURE__ */ a("button", {
|
|
793
|
+
type: "button",
|
|
794
|
+
onClick: () => J(null),
|
|
795
|
+
"aria-label": "Close",
|
|
796
|
+
children: "×"
|
|
797
|
+
})]
|
|
798
|
+
}),
|
|
799
|
+
K.group && /* @__PURE__ */ o("p", { children: [
|
|
800
|
+
/* @__PURE__ */ a("strong", { children: "Group:" }),
|
|
801
|
+
" ",
|
|
802
|
+
K.group
|
|
803
|
+
] }),
|
|
804
|
+
/* @__PURE__ */ o("div", {
|
|
805
|
+
className: "track-switch level-switch",
|
|
806
|
+
children: [
|
|
807
|
+
/* @__PURE__ */ a("span", {
|
|
808
|
+
className: Z ? "" : "parents on",
|
|
809
|
+
children: "One level"
|
|
810
|
+
}),
|
|
811
|
+
/* @__PURE__ */ a("button", {
|
|
812
|
+
type: "button",
|
|
813
|
+
role: "switch",
|
|
814
|
+
"aria-checked": Z,
|
|
815
|
+
"aria-label": "Show all levels of parents and children",
|
|
816
|
+
className: "switch",
|
|
817
|
+
onClick: () => {
|
|
818
|
+
let e = !Z;
|
|
819
|
+
de(e);
|
|
820
|
+
let t = c.current?.getElementById(K.id);
|
|
821
|
+
t && !t.empty() && J(L(t, e));
|
|
822
|
+
},
|
|
823
|
+
children: /* @__PURE__ */ a("span", { className: "switch-knob" })
|
|
824
|
+
}),
|
|
825
|
+
/* @__PURE__ */ a("span", {
|
|
826
|
+
className: Z ? "children on" : "",
|
|
827
|
+
children: "All levels"
|
|
828
|
+
})
|
|
829
|
+
]
|
|
830
|
+
}),
|
|
831
|
+
z(K).map(([e, t]) => /* @__PURE__ */ o("section", { children: [/* @__PURE__ */ o("h3", { children: [
|
|
832
|
+
e,
|
|
833
|
+
" (",
|
|
834
|
+
t.length,
|
|
835
|
+
"):"
|
|
836
|
+
] }), /* @__PURE__ */ a("ul", { children: t.map((e) => /* @__PURE__ */ a("li", { children: /* @__PURE__ */ o("button", {
|
|
837
|
+
type: "button",
|
|
838
|
+
onClick: () => he(e.id),
|
|
839
|
+
children: [e.name, e.group && /* @__PURE__ */ o("span", { children: [
|
|
840
|
+
" (",
|
|
841
|
+
e.group,
|
|
842
|
+
")"
|
|
843
|
+
] })]
|
|
844
|
+
}) }, e.id)) })] }, e))
|
|
845
|
+
]
|
|
846
|
+
})]
|
|
847
|
+
}),
|
|
848
|
+
R && /* @__PURE__ */ a("div", {
|
|
849
|
+
className: "node-context-menu",
|
|
850
|
+
style: {
|
|
851
|
+
left: R.x,
|
|
852
|
+
top: R.y
|
|
853
|
+
},
|
|
854
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
855
|
+
children: /* @__PURE__ */ a("button", {
|
|
856
|
+
type: "button",
|
|
857
|
+
onClick: pe,
|
|
858
|
+
children: "Save to clipboard"
|
|
859
|
+
})
|
|
860
|
+
})
|
|
861
|
+
]
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
return J.displayName = "CytoscapeGraph", J;
|
|
865
|
+
}
|
|
866
|
+
export { G as NodeSearch, K as create_graph, B as formatNodeInfo, L as getNodeInfo };
|
|
867
|
+
|
|
868
|
+
//# sourceMappingURL=index.js.map
|