@flexible-graphrag/graph-view 0.0.0-stage → 0.10.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 +201 -0
- package/README.md +48 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +270 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts.d.ts +3 -0
- package/dist/layouts.js +33 -0
- package/dist/layouts.js.map +1 -0
- package/dist/palette.d.ts +9 -0
- package/dist/palette.js +47 -0
- package/dist/palette.js.map +1 -0
- package/dist/style.d.ts +3 -0
- package/dist/style.js +82 -0
- package/dist/style.js.map +1 -0
- package/dist/types.d.ts +96 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flexible-graphrag/graph-view
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-free property-graph view for the Flexible GraphRAG **Graph** tab, built on
|
|
4
|
+
[Cytoscape.js](https://js.cytoscape.org/) (force layout via fcose, hierarchical via dagre).
|
|
5
|
+
Used by the React, Vue and Angular UIs and by `@flexible-graphrag/angular-ui`.
|
|
6
|
+
|
|
7
|
+
It does no fetching and no auth: the host app calls the backend
|
|
8
|
+
(`POST /api/graph/subgraph`, `POST /api/graph/neighbors`) and hands the result to the view.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { createGraphView } from '@flexible-graphrag/graph-view';
|
|
12
|
+
|
|
13
|
+
const view = createGraphView(document.getElementById('graph')!, { layout: 'force', theme: 'light' });
|
|
14
|
+
|
|
15
|
+
const res = await fetch('/api/graph/subgraph', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: { 'Content-Type': 'application/json' },
|
|
18
|
+
body: JSON.stringify({ processing_id: '524d6f13', limit: 500 }),
|
|
19
|
+
});
|
|
20
|
+
view.setGraph(await res.json());
|
|
21
|
+
|
|
22
|
+
view.on('select', (e) => console.log(e)); // tap a node or edge
|
|
23
|
+
view.on('expand', async (e) => { // double-tap a node
|
|
24
|
+
const r = await fetch('/api/graph/neighbors', { /* same scope + node_id: e.id */ });
|
|
25
|
+
view.mergeGraph(await r.json());
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
API: `setGraph`, `mergeGraph`, `setLayout('force' | 'hierarchical' | 'concentric')`, `setTheme`,
|
|
30
|
+
`setTypeVisible` / `setAllTypesVisible` / `types()` (entity types, for a legend),
|
|
31
|
+
`setRelationshipVisible` / `setAllRelationshipsVisible` / `relationshipTypes()`,
|
|
32
|
+
`setChunksVisible` / `chunkCount()`, `setSelection`, `focus`, `fit`, `resize` (call when a hidden
|
|
33
|
+
tab becomes visible), `toPng`, `nodeCount`, `edgeCount`, `on`, `destroy`.
|
|
34
|
+
|
|
35
|
+
Chunks (requested with `include_chunks: true`) are nodes with `kind: 'chunk'`, drawn as small grey
|
|
36
|
+
squares; their MENTIONS edges to entities have `kind: 'mention'` and are drawn dashed.
|
|
37
|
+
|
|
38
|
+
Node colours are stable per type across views and apps (`colorFor(type)`).
|
|
39
|
+
|
|
40
|
+
## Develop
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install
|
|
44
|
+
npm run build # -> dist/
|
|
45
|
+
npm run demo # http://localhost:5180, proxies /api to the backend on :8000
|
|
46
|
+
# http://localhost:5180/?processing_id=<job id> loads a job's graph
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
License: Apache-2.0.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @flexible-graphrag/graph-view: a framework-free property-graph view on Cytoscape.js.
|
|
3
|
+
*
|
|
4
|
+
* No fetching, no auth, no framework code: the React / Vue / Angular Graph tabs fetch
|
|
5
|
+
* /api/graph/subgraph themselves and hand the result to setGraph().
|
|
6
|
+
*/
|
|
7
|
+
import cytoscape from 'cytoscape';
|
|
8
|
+
import dagre from 'cytoscape-dagre';
|
|
9
|
+
import fcose from 'cytoscape-fcose';
|
|
10
|
+
import { layoutOptions } from './layouts';
|
|
11
|
+
import { colorFor } from './palette';
|
|
12
|
+
import { stylesheet } from './style';
|
|
13
|
+
export * from './types';
|
|
14
|
+
export { colorFor, PALETTE, ENTITY_COLOR } from './palette';
|
|
15
|
+
let registered = false;
|
|
16
|
+
function register() {
|
|
17
|
+
if (registered)
|
|
18
|
+
return;
|
|
19
|
+
cytoscape.use(fcose);
|
|
20
|
+
cytoscape.use(dagre);
|
|
21
|
+
registered = true;
|
|
22
|
+
}
|
|
23
|
+
const BACKGROUND = { light: '#ffffff', dark: '#121212' };
|
|
24
|
+
export function createGraphView(container, options = {}) {
|
|
25
|
+
register();
|
|
26
|
+
let layout = options.layout ?? 'force';
|
|
27
|
+
let theme = options.theme ?? 'light';
|
|
28
|
+
const maxLabel = options.maxLabelLength ?? 28;
|
|
29
|
+
const hiddenTypes = new Set();
|
|
30
|
+
const hiddenRels = new Set();
|
|
31
|
+
let chunksVisible = true;
|
|
32
|
+
const listeners = {
|
|
33
|
+
select: new Set(), expand: new Set(), background: new Set(),
|
|
34
|
+
};
|
|
35
|
+
let running = null;
|
|
36
|
+
const cy = cytoscape({
|
|
37
|
+
container,
|
|
38
|
+
style: stylesheet(theme),
|
|
39
|
+
minZoom: 0.05,
|
|
40
|
+
maxZoom: 4,
|
|
41
|
+
wheelSensitivity: 0.3,
|
|
42
|
+
boxSelectionEnabled: false,
|
|
43
|
+
});
|
|
44
|
+
const emit = (name, e) => listeners[name].forEach((fn) => fn(e));
|
|
45
|
+
const caption = (s) => (s.length > maxLabel ? s.slice(0, maxLabel - 1) + '…' : s);
|
|
46
|
+
const nodeElement = (n) => ({
|
|
47
|
+
group: 'nodes',
|
|
48
|
+
data: { id: n.id, caption: caption(n.label || n.id), type: n.type, kind: n.kind ?? 'entity',
|
|
49
|
+
color: colorFor(n.type), raw: n },
|
|
50
|
+
});
|
|
51
|
+
const edgeElement = (e) => ({
|
|
52
|
+
group: 'edges',
|
|
53
|
+
data: { id: e.id, source: e.source, target: e.target, type: e.type, kind: e.kind ?? 'fact',
|
|
54
|
+
raw: { ...e, doc_ids: [...(e.doc_ids ?? [])] } },
|
|
55
|
+
});
|
|
56
|
+
const isChunk = (el) => el.data('kind') === 'chunk';
|
|
57
|
+
/** Hidden: entities of a hidden type, chunks when chunks are off, relationships (MENTIONS
|
|
58
|
+
* included) of a hidden type; an edge also disappears with either end. */
|
|
59
|
+
const applyVisibility = () => {
|
|
60
|
+
cy.batch(() => {
|
|
61
|
+
cy.nodes().forEach((n) => {
|
|
62
|
+
n.toggleClass('hidden', isChunk(n) ? !chunksVisible : hiddenTypes.has(n.data('type')));
|
|
63
|
+
});
|
|
64
|
+
cy.edges().forEach((e) => {
|
|
65
|
+
e.toggleClass('hidden', hiddenRels.has(e.data('type')));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
/** After showing something: lay out again, keeping what is placed roughly where it is. */
|
|
70
|
+
const shown = (visible) => {
|
|
71
|
+
applyVisibility();
|
|
72
|
+
if (visible)
|
|
73
|
+
run(false);
|
|
74
|
+
};
|
|
75
|
+
const count = (els, visible, color) => {
|
|
76
|
+
const counts = new Map();
|
|
77
|
+
els.forEach((el) => {
|
|
78
|
+
const t = el.data('type');
|
|
79
|
+
counts.set(t, (counts.get(t) ?? 0) + 1);
|
|
80
|
+
});
|
|
81
|
+
return [...counts.entries()]
|
|
82
|
+
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
83
|
+
.map(([type, n]) => ({ type, count: n, color: color(type), visible: visible(type) }));
|
|
84
|
+
};
|
|
85
|
+
const highlight = (center) => {
|
|
86
|
+
cy.batch(() => {
|
|
87
|
+
if (!center) {
|
|
88
|
+
cy.elements().removeClass('faded');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const keep = center.isNode() ? center.closedNeighborhood() : center.union(center.connectedNodes());
|
|
92
|
+
cy.elements().addClass('faded');
|
|
93
|
+
keep.removeClass('faded');
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const run = (randomize) => {
|
|
97
|
+
running?.stop();
|
|
98
|
+
running = cy.elements(':visible').layout(layoutOptions(layout, cy.nodes().length, randomize));
|
|
99
|
+
running.run();
|
|
100
|
+
};
|
|
101
|
+
const zoomBy = (factor) => {
|
|
102
|
+
const level = Math.min(cy.maxZoom(), Math.max(cy.minZoom(), cy.zoom() * factor));
|
|
103
|
+
cy.animate({ zoom: { level, renderedPosition: { x: cy.width() / 2, y: cy.height() / 2 } }, duration: 150 });
|
|
104
|
+
};
|
|
105
|
+
/** Adds what is missing; returns the nodes that were new. */
|
|
106
|
+
const add = (data) => {
|
|
107
|
+
const known = new Set(cy.nodes().map((n) => n.id()));
|
|
108
|
+
const fresh = [];
|
|
109
|
+
for (const n of data.nodes ?? []) {
|
|
110
|
+
if (!known.has(n.id)) {
|
|
111
|
+
fresh.push(nodeElement(n));
|
|
112
|
+
known.add(n.id);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const e of data.edges ?? []) {
|
|
116
|
+
if (!known.has(e.source) || !known.has(e.target))
|
|
117
|
+
continue;
|
|
118
|
+
const existing = cy.getElementById(e.id);
|
|
119
|
+
if (existing.nonempty()) {
|
|
120
|
+
const raw = existing.data('raw');
|
|
121
|
+
for (const d of e.doc_ids ?? [])
|
|
122
|
+
if (!raw.doc_ids.includes(d))
|
|
123
|
+
raw.doc_ids.push(d);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
fresh.push(edgeElement(e));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return cy.add(fresh).nodes();
|
|
130
|
+
};
|
|
131
|
+
cy.on('tap', 'node', (evt) => {
|
|
132
|
+
const n = evt.target;
|
|
133
|
+
highlight(n);
|
|
134
|
+
emit('select', { kind: 'node', id: n.id(), node: n.data('raw') });
|
|
135
|
+
});
|
|
136
|
+
cy.on('tap', 'edge', (evt) => {
|
|
137
|
+
highlight(evt.target);
|
|
138
|
+
emit('select', { kind: 'edge', id: evt.target.id(), edge: evt.target.data('raw') });
|
|
139
|
+
});
|
|
140
|
+
cy.on('tap', (evt) => {
|
|
141
|
+
if (evt.target === cy) {
|
|
142
|
+
highlight(null);
|
|
143
|
+
emit('background', { kind: 'background' });
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
cy.on('dbltap', 'node', (evt) => {
|
|
147
|
+
const n = evt.target;
|
|
148
|
+
emit('expand', { kind: 'node', id: n.id(), node: n.data('raw') });
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
setGraph(data) {
|
|
152
|
+
running?.stop();
|
|
153
|
+
cy.batch(() => {
|
|
154
|
+
cy.elements().remove();
|
|
155
|
+
add(data);
|
|
156
|
+
});
|
|
157
|
+
applyVisibility();
|
|
158
|
+
run(true);
|
|
159
|
+
},
|
|
160
|
+
mergeGraph(data) {
|
|
161
|
+
const fresh = add(data);
|
|
162
|
+
applyVisibility();
|
|
163
|
+
if (fresh.empty())
|
|
164
|
+
return;
|
|
165
|
+
// Start new nodes next to a node they connect to, so the layout grows outward from there.
|
|
166
|
+
fresh.forEach((n) => {
|
|
167
|
+
const anchor = n.neighborhood('node').difference(fresh).first();
|
|
168
|
+
if (anchor.nonempty()) {
|
|
169
|
+
const p = anchor.position();
|
|
170
|
+
n.position({ x: p.x + (Math.random() - 0.5) * 60, y: p.y + (Math.random() - 0.5) * 60 });
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
run(false);
|
|
174
|
+
},
|
|
175
|
+
setLayout(name) {
|
|
176
|
+
layout = name;
|
|
177
|
+
run(true);
|
|
178
|
+
},
|
|
179
|
+
setTheme(next) {
|
|
180
|
+
theme = next;
|
|
181
|
+
cy.style(stylesheet(theme));
|
|
182
|
+
},
|
|
183
|
+
setTypeVisible(type, visible) {
|
|
184
|
+
if (visible)
|
|
185
|
+
hiddenTypes.delete(type);
|
|
186
|
+
else
|
|
187
|
+
hiddenTypes.add(type);
|
|
188
|
+
shown(visible);
|
|
189
|
+
},
|
|
190
|
+
setAllTypesVisible(visible) {
|
|
191
|
+
hiddenTypes.clear();
|
|
192
|
+
if (!visible)
|
|
193
|
+
cy.nodes().forEach((n) => { if (!isChunk(n))
|
|
194
|
+
hiddenTypes.add(n.data('type')); });
|
|
195
|
+
shown(visible);
|
|
196
|
+
},
|
|
197
|
+
types() {
|
|
198
|
+
return count(cy.nodes().filter((n) => !isChunk(n)), (t) => !hiddenTypes.has(t), colorFor);
|
|
199
|
+
},
|
|
200
|
+
setRelationshipVisible(type, visible) {
|
|
201
|
+
if (visible)
|
|
202
|
+
hiddenRels.delete(type);
|
|
203
|
+
else
|
|
204
|
+
hiddenRels.add(type);
|
|
205
|
+
shown(visible);
|
|
206
|
+
},
|
|
207
|
+
setAllRelationshipsVisible(visible) {
|
|
208
|
+
hiddenRels.clear();
|
|
209
|
+
if (!visible)
|
|
210
|
+
cy.edges().forEach((e) => { hiddenRels.add(e.data('type')); });
|
|
211
|
+
shown(visible);
|
|
212
|
+
},
|
|
213
|
+
relationshipTypes() {
|
|
214
|
+
// MENTIONS (chunk links) last, after the facts
|
|
215
|
+
const all = count(cy.edges(), (t) => !hiddenRels.has(t), () => '');
|
|
216
|
+
return [...all.filter((r) => r.type !== 'MENTIONS'), ...all.filter((r) => r.type === 'MENTIONS')];
|
|
217
|
+
},
|
|
218
|
+
setChunksVisible(visible) {
|
|
219
|
+
chunksVisible = visible;
|
|
220
|
+
shown(visible);
|
|
221
|
+
},
|
|
222
|
+
chunkCount: () => cy.nodes().filter((n) => isChunk(n)).length,
|
|
223
|
+
setSelection(ids) {
|
|
224
|
+
cy.batch(() => {
|
|
225
|
+
cy.elements().unselect();
|
|
226
|
+
ids.forEach((id) => cy.getElementById(id).select());
|
|
227
|
+
});
|
|
228
|
+
const sel = cy.$(':selected');
|
|
229
|
+
const one = sel.length === 1 ? sel[0] : null;
|
|
230
|
+
highlight(one);
|
|
231
|
+
if (one?.isNode())
|
|
232
|
+
emit('select', { kind: 'node', id: one.id(), node: one.data('raw') });
|
|
233
|
+
else if (one)
|
|
234
|
+
emit('select', { kind: 'edge', id: one.id(), edge: one.data('raw') });
|
|
235
|
+
},
|
|
236
|
+
focus(ids) {
|
|
237
|
+
const els = cy.collection();
|
|
238
|
+
ids.forEach((id) => els.merge(cy.getElementById(id)));
|
|
239
|
+
if (els.nonempty())
|
|
240
|
+
cy.animate({ fit: { eles: els.closedNeighborhood(), padding: 60 }, duration: 300 });
|
|
241
|
+
},
|
|
242
|
+
fit() {
|
|
243
|
+
cy.fit(cy.elements(':visible'), 30);
|
|
244
|
+
},
|
|
245
|
+
zoomIn() {
|
|
246
|
+
zoomBy(1.25);
|
|
247
|
+
},
|
|
248
|
+
zoomOut() {
|
|
249
|
+
zoomBy(1 / 1.25);
|
|
250
|
+
},
|
|
251
|
+
resize() {
|
|
252
|
+
cy.resize();
|
|
253
|
+
},
|
|
254
|
+
toPng() {
|
|
255
|
+
return cy.png({ output: 'blob-promise', full: true, scale: 2, bg: BACKGROUND[theme] });
|
|
256
|
+
},
|
|
257
|
+
nodeCount: () => cy.nodes().length,
|
|
258
|
+
edgeCount: () => cy.edges().length,
|
|
259
|
+
on(event, fn) {
|
|
260
|
+
listeners[event].add(fn);
|
|
261
|
+
return () => listeners[event].delete(fn);
|
|
262
|
+
},
|
|
263
|
+
destroy() {
|
|
264
|
+
running?.stop();
|
|
265
|
+
Object.values(listeners).forEach((s) => s.clear());
|
|
266
|
+
cy.destroy();
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAMrC,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE5D,IAAI,UAAU,GAAG,KAAK,CAAC;AACvB,SAAS,QAAQ;IACf,IAAI,UAAU;QAAE,OAAO;IACvB,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,UAAU,GAAG,IAAI,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,GAA0B,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAEhF,MAAM,UAAU,eAAe,CAAC,SAAsB,EAAE,UAA4B,EAAE;IACpF,QAAQ,EAAE,CAAC;IACX,IAAI,MAAM,GAAe,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;IACnD,IAAI,KAAK,GAAU,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC;IAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;IAC9C,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC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AE,CAAC,CAAC;QACtC,CAAC;QAED,MAAM;YACJ,MAAM,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;QAED,OAAO;YACL,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACnB,CAAC;QAED,MAAM;YACJ,EAAE,CAAC,MAAM,EAAE,CAAC;QACd,CAAC;QAED,KAAK;YACH,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzF,CAAC;QAED,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM;QAClC,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,MAAM;QAElC,EAAE,CAAC,KAAK,EAAE,EAAE;YACV,SAAS,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACzB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO;YACL,OAAO,EAAE,IAAI,EAAE,CAAC;YAChB,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;YACnD,EAAE,CAAC,OAAO,EAAE,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/layouts.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Above this many nodes layouts are not animated (keeps big graphs responsive). */
|
|
2
|
+
const ANIMATE_MAX_NODES = 300;
|
|
3
|
+
export function layoutOptions(name, nodeCount, randomize = true) {
|
|
4
|
+
const animate = nodeCount <= ANIMATE_MAX_NODES;
|
|
5
|
+
const common = { fit: true, padding: 30, animate, animationDuration: 400 };
|
|
6
|
+
switch (name) {
|
|
7
|
+
case 'hierarchical':
|
|
8
|
+
return { ...common, name: 'dagre', rankDir: 'LR', nodeSep: 30, rankSep: 90, edgeSep: 10 };
|
|
9
|
+
case 'concentric':
|
|
10
|
+
return {
|
|
11
|
+
...common,
|
|
12
|
+
name: 'concentric',
|
|
13
|
+
concentric: (n) => n.degree(),
|
|
14
|
+
levelWidth: () => 2,
|
|
15
|
+
minNodeSpacing: 24,
|
|
16
|
+
avoidOverlap: true,
|
|
17
|
+
};
|
|
18
|
+
case 'force':
|
|
19
|
+
default:
|
|
20
|
+
return {
|
|
21
|
+
...common,
|
|
22
|
+
name: 'fcose',
|
|
23
|
+
quality: nodeCount > 1500 ? 'draft' : 'default',
|
|
24
|
+
randomize,
|
|
25
|
+
nodeRepulsion: 9000,
|
|
26
|
+
idealEdgeLength: 90,
|
|
27
|
+
edgeElasticity: 0.45,
|
|
28
|
+
nodeSeparation: 80,
|
|
29
|
+
packComponents: true,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=layouts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layouts.js","sourceRoot":"","sources":["../src/layouts.ts"],"names":[],"mappings":"AAGA,oFAAoF;AACpF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAM,UAAU,aAAa,CAAC,IAAgB,EAAE,SAAiB,EAAE,SAAS,GAAG,IAAI;IACjF,MAAM,OAAO,GAAG,SAAS,IAAI,iBAAiB,CAAC;IAC/C,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC;IAC3E,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,cAAc;YACjB,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAmB,CAAC;QAC7G,KAAK,YAAY;YACf,OAAO;gBACL,GAAG,MAAM;gBACT,IAAI,EAAE,YAAY;gBAClB,UAAU,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE;gBAClC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;gBACnB,cAAc,EAAE,EAAE;gBAClB,YAAY,EAAE,IAAI;aACF,CAAC;QACrB,KAAK,OAAO,CAAC;QACb;YACE,OAAO;gBACL,GAAG,MAAM;gBACT,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAC/C,SAAS;gBACT,aAAa,EAAE,IAAI;gBACnB,eAAe,EAAE,EAAE;gBACnB,cAAc,EAAE,IAAI;gBACpB,cAAc,EAAE,EAAE;gBAClB,cAAc,EAAE,IAAI;aACJ,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable type -> colour, the same in every view, session and app (React, Vue, Angular, KG Spaces).
|
|
3
|
+
* Common schema types get fixed, distinct colours (synonyms share one); any other type is
|
|
4
|
+
* hashed to a hue.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PALETTE: Record<string, string>;
|
|
7
|
+
/** Colour for the generic fallback type, so untyped entities read as "no type". */
|
|
8
|
+
export declare const ENTITY_COLOR = "#8C8C8C";
|
|
9
|
+
export declare function colorFor(type: string): string;
|
package/dist/palette.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable type -> colour, the same in every view, session and app (React, Vue, Angular, KG Spaces).
|
|
3
|
+
* Common schema types get fixed, distinct colours (synonyms share one); any other type is
|
|
4
|
+
* hashed to a hue.
|
|
5
|
+
*/
|
|
6
|
+
// Okabe-Ito based, extended; readable on light and dark backgrounds.
|
|
7
|
+
export const PALETTE = {
|
|
8
|
+
PERSON: '#0072B2',
|
|
9
|
+
ORGANIZATION: '#E69F00',
|
|
10
|
+
LOCATION: '#009E73',
|
|
11
|
+
TECHNOLOGY: '#CC79A7',
|
|
12
|
+
PROJECT: '#7F63B8',
|
|
13
|
+
DOCUMENT: '#A0785A',
|
|
14
|
+
EVENT: '#D55E00',
|
|
15
|
+
DATE: '#B8A000',
|
|
16
|
+
PRODUCT: '#56B4E9',
|
|
17
|
+
SKILL: '#2CA6A4',
|
|
18
|
+
TOPIC: '#E2556F',
|
|
19
|
+
DEPARTMENT: '#6C8EBF',
|
|
20
|
+
};
|
|
21
|
+
const SYNONYMS = {
|
|
22
|
+
COMPANY: 'ORGANIZATION', ORG: 'ORGANIZATION',
|
|
23
|
+
PLACE: 'LOCATION', CITY: 'LOCATION', COUNTRY: 'LOCATION', GPE: 'LOCATION',
|
|
24
|
+
PEOPLE: 'PERSON', EMPLOYEE: 'PERSON',
|
|
25
|
+
TIME: 'DATE',
|
|
26
|
+
};
|
|
27
|
+
/** Colour for the generic fallback type, so untyped entities read as "no type". */
|
|
28
|
+
export const ENTITY_COLOR = '#8C8C8C';
|
|
29
|
+
function hash(s) {
|
|
30
|
+
let h = 0x811c9dc5; // FNV-1a
|
|
31
|
+
for (let i = 0; i < s.length; i++) {
|
|
32
|
+
h ^= s.charCodeAt(i);
|
|
33
|
+
h = Math.imul(h, 0x01000193);
|
|
34
|
+
}
|
|
35
|
+
return h >>> 0;
|
|
36
|
+
}
|
|
37
|
+
export function colorFor(type) {
|
|
38
|
+
const t = (type || '').toUpperCase();
|
|
39
|
+
if (!t || t === 'ENTITY')
|
|
40
|
+
return ENTITY_COLOR;
|
|
41
|
+
const known = PALETTE[SYNONYMS[t] ?? t];
|
|
42
|
+
if (known)
|
|
43
|
+
return known;
|
|
44
|
+
const h = hash(t);
|
|
45
|
+
return `hsl(${h % 360}, ${45 +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,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,YAAY,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACxC,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,OAAO,OAAO,CAAC,GAAG,GAAG,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC;AAC5E,CAAC"}
|
package/dist/style.d.ts
ADDED
package/dist/style.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const THEMES = {
|
|
2
|
+
light: { text: '#1f2328', outline: '#ffffff', edge: '#a0a7b0', edgeText: '#57606a', selected: '#ff6d00',
|
|
3
|
+
chunk: '#9aa1a9', mention: '#b4bac1' },
|
|
4
|
+
dark: { text: '#e6edf3', outline: '#121212', edge: '#5c6670', edgeText: '#9aa4ae', selected: '#ffab40',
|
|
5
|
+
chunk: '#6b747d', mention: '#4c555e' },
|
|
6
|
+
};
|
|
7
|
+
export function stylesheet(theme) {
|
|
8
|
+
const t = THEMES[theme] ?? THEMES.light;
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
selector: 'node',
|
|
12
|
+
style: {
|
|
13
|
+
'background-color': 'data(color)',
|
|
14
|
+
width: 26, // one size for every entity
|
|
15
|
+
height: 26,
|
|
16
|
+
label: 'data(caption)',
|
|
17
|
+
'font-size': 9,
|
|
18
|
+
color: t.text,
|
|
19
|
+
'text-valign': 'bottom',
|
|
20
|
+
'text-halign': 'center',
|
|
21
|
+
'text-margin-y': 4,
|
|
22
|
+
'text-outline-color': t.outline,
|
|
23
|
+
'text-outline-width': 2,
|
|
24
|
+
'min-zoomed-font-size': 6,
|
|
25
|
+
'border-width': 1,
|
|
26
|
+
'border-color': t.outline,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
selector: 'edge',
|
|
31
|
+
style: {
|
|
32
|
+
width: 1.5,
|
|
33
|
+
'curve-style': 'bezier',
|
|
34
|
+
'line-color': t.edge,
|
|
35
|
+
'target-arrow-color': t.edge,
|
|
36
|
+
'target-arrow-shape': 'triangle',
|
|
37
|
+
'arrow-scale': 0.9,
|
|
38
|
+
label: 'data(type)',
|
|
39
|
+
'font-size': 7,
|
|
40
|
+
color: t.edgeText,
|
|
41
|
+
'text-rotation': 'autorotate',
|
|
42
|
+
'text-outline-color': t.outline,
|
|
43
|
+
'text-outline-width': 2,
|
|
44
|
+
'min-zoomed-font-size': 7, // edge captions only once zoomed in
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
// Chunks: small grey squares, captions only when zoomed in; MENTIONS: thin dashed, no caption
|
|
48
|
+
{
|
|
49
|
+
selector: 'node[kind = "chunk"]',
|
|
50
|
+
style: {
|
|
51
|
+
shape: 'round-rectangle',
|
|
52
|
+
'background-color': t.chunk,
|
|
53
|
+
width: 14,
|
|
54
|
+
height: 14,
|
|
55
|
+
'font-size': 7,
|
|
56
|
+
'min-zoomed-font-size': 10,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
selector: 'edge[kind = "mention"]',
|
|
61
|
+
style: {
|
|
62
|
+
width: 1,
|
|
63
|
+
'line-style': 'dashed',
|
|
64
|
+
'line-color': t.mention,
|
|
65
|
+
'target-arrow-color': t.mention,
|
|
66
|
+
'arrow-scale': 0.6,
|
|
67
|
+
label: '',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
selector: 'node:selected',
|
|
72
|
+
style: { 'border-width': 4, 'border-color': t.text }, // text colour: shows on any type colour
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
selector: 'edge:selected',
|
|
76
|
+
style: { width: 3, 'line-color': t.selected, 'target-arrow-color': t.selected },
|
|
77
|
+
},
|
|
78
|
+
{ selector: '.faded', style: { opacity: 0.15, 'text-opacity': 0 } },
|
|
79
|
+
{ selector: '.hidden', style: { display: 'none' } },
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS;QAC9F,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE;IAC/C,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS;QAC9F,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE;CAC/C,CAAC;AAEF,MAAM,UAAU,UAAU,CAAC,KAAY;IACrC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;IACxC,OAAO;QACL;YACE,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE;gBACL,kBAAkB,EAAE,aAAa;gBACjC,KAAK,EAAE,EAAE,EAAE,4BAA4B;gBACvC,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,eAAe;gBACtB,WAAW,EAAE,CAAC;gBACd,KAAK,EAAE,CAAC,CAAC,IAAI;gBACb,aAAa,EAAE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c,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,wCAAwC;SAC/F;QACD;YACE,QAAQ,EAAE,eAAe;YACzB,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,QAAQ,EAAE,oBAAoB,EAAE,CAAC,CAAC,QAAQ,EAAE;SAChF;QACD,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,EAAE,EAAE;QACnE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;KACpD,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** Shapes returned by POST /api/graph/subgraph and /api/graph/neighbors. */
|
|
2
|
+
export interface GraphNode {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
type: string;
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
/** 'chunk' for a text chunk (include_chunks); entities have none. */
|
|
8
|
+
kind?: 'chunk';
|
|
9
|
+
/** A chunk's document(s). */
|
|
10
|
+
doc_ids?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface GraphEdge {
|
|
13
|
+
id: string;
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
type: string;
|
|
17
|
+
properties: Record<string, unknown>;
|
|
18
|
+
/** Documents this relationship was extracted from (within the requested scope). */
|
|
19
|
+
doc_ids: string[];
|
|
20
|
+
/** 'mention' for a chunk -MENTIONS-> entity edge; facts have none. */
|
|
21
|
+
kind?: 'mention';
|
|
22
|
+
}
|
|
23
|
+
export interface GraphData {
|
|
24
|
+
nodes: GraphNode[];
|
|
25
|
+
edges: GraphEdge[];
|
|
26
|
+
/** Per-document metadata (file_name, source, ...), sent once instead of on every element. */
|
|
27
|
+
documents?: Record<string, Record<string, unknown>>;
|
|
28
|
+
truncated?: boolean;
|
|
29
|
+
store?: string;
|
|
30
|
+
doc_count?: number;
|
|
31
|
+
unsigned?: string[];
|
|
32
|
+
message?: string;
|
|
33
|
+
}
|
|
34
|
+
export type LayoutName = 'force' | 'hierarchical' | 'concentric';
|
|
35
|
+
export type Theme = 'light' | 'dark';
|
|
36
|
+
export interface GraphViewOptions {
|
|
37
|
+
layout?: LayoutName;
|
|
38
|
+
theme?: Theme;
|
|
39
|
+
/** Longest node caption before it is shortened with an ellipsis. */
|
|
40
|
+
maxLabelLength?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface TypeInfo {
|
|
43
|
+
type: string;
|
|
44
|
+
color: string;
|
|
45
|
+
count: number;
|
|
46
|
+
visible: boolean;
|
|
47
|
+
}
|
|
48
|
+
export type GraphViewEvent = {
|
|
49
|
+
kind: 'node';
|
|
50
|
+
id: string;
|
|
51
|
+
node: GraphNode;
|
|
52
|
+
} | {
|
|
53
|
+
kind: 'edge';
|
|
54
|
+
id: string;
|
|
55
|
+
edge: GraphEdge;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'background';
|
|
58
|
+
};
|
|
59
|
+
export type GraphViewEventName = 'select' | 'expand' | 'background';
|
|
60
|
+
export interface GraphView {
|
|
61
|
+
/** Replace everything shown. */
|
|
62
|
+
setGraph(data: GraphData): void;
|
|
63
|
+
/** Add nodes and edges (expand neighbours); existing ones keep their place. */
|
|
64
|
+
mergeGraph(data: GraphData): void;
|
|
65
|
+
setLayout(layout: LayoutName): void;
|
|
66
|
+
setTheme(theme: Theme): void;
|
|
67
|
+
/** Show or hide the entities of one type. */
|
|
68
|
+
setTypeVisible(type: string, visible: boolean): void;
|
|
69
|
+
setAllTypesVisible(visible: boolean): void;
|
|
70
|
+
/** Entity types present (chunks not included), with their colour and count, for a legend. */
|
|
71
|
+
types(): TypeInfo[];
|
|
72
|
+
/** Show or hide the relationships of one type. */
|
|
73
|
+
setRelationshipVisible(type: string, visible: boolean): void;
|
|
74
|
+
setAllRelationshipsVisible(visible: boolean): void;
|
|
75
|
+
/** Relationship types present (MENTIONS included when chunks are loaded), with their count. */
|
|
76
|
+
relationshipTypes(): TypeInfo[];
|
|
77
|
+
/** Show or hide the chunks and their MENTIONS edges. */
|
|
78
|
+
setChunksVisible(visible: boolean): void;
|
|
79
|
+
chunkCount(): number;
|
|
80
|
+
/** Select these elements; with exactly one, a 'select' event fires as for a tap. */
|
|
81
|
+
setSelection(ids: string[]): void;
|
|
82
|
+
/** Center and zoom on these node ids. */
|
|
83
|
+
focus(ids: string[]): void;
|
|
84
|
+
fit(): void;
|
|
85
|
+
/** Zoom around the centre of the view (factor 1.25 per step). */
|
|
86
|
+
zoomIn(): void;
|
|
87
|
+
zoomOut(): void;
|
|
88
|
+
/** Call when a hidden tab becomes visible or the container is resized. */
|
|
89
|
+
resize(): void;
|
|
90
|
+
toPng(): Promise<Blob>;
|
|
91
|
+
nodeCount(): number;
|
|
92
|
+
edgeCount(): number;
|
|
93
|
+
/** select: tap on a node or edge; expand: double-tap on a node; background: tap on empty space. */
|
|
94
|
+
on(event: GraphViewEventName, fn: (e: GraphViewEvent) => void): () => void;
|
|
95
|
+
destroy(): void;
|
|
96
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4EAA4E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexible-graphrag/graph-view",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Framework-free property-graph view (Cytoscape.js) for the Flexible GraphRAG Graph tab",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"keywords": ["graph", "knowledge-graph", "cytoscape", "graphrag", "flexible-graphrag"],
|
|
7
|
+
"homepage": "https://stevereiner.github.io/flexible-graphrag/",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/stevereiner/flexible-graphrag.git",
|
|
11
|
+
"directory": "flexible-graphrag-ui/graph-view"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/stevereiner/flexible-graphrag/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"demo": "vite --config demo/vite.config.ts",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"cytoscape": "^3.34.4",
|
|
35
|
+
"cytoscape-dagre": "^4.0.1",
|
|
36
|
+
"cytoscape-fcose": "^2.2.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/cytoscape-dagre": "^2.3.4",
|
|
40
|
+
"@types/cytoscape-fcose": "^2.2.5",
|
|
41
|
+
"typescript": "~5.9.0",
|
|
42
|
+
"vite": "^6.3.5"
|
|
43
|
+
}
|
|
44
|
+
}
|