1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-11 10:18:07 +09:00

JS-3684: orphan nodes filtering

This commit is contained in:
Andrew Simachev 2023-12-30 13:20:27 +01:00
parent f43186a8cb
commit d48c4dda3e
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8

19
dist/workers/graph.js vendored
View file

@ -173,6 +173,8 @@ image = ({ src, bitmap }) => {
initForces = () => {
const { center, charge, link, forceX, forceY } = forceProps;
updateOrphans();
simulation
.force('link', d3.forceLink().id(d => d.id))
.force('charge', d3.forceManyBody())
@ -210,6 +212,8 @@ updateForces = () => {
edges = util.objectCopy(data.edges);
nodes = util.objectCopy(data.nodes);
updateOrphans();
// Filter links
if (!settings.link) {
edges = edges.filter(d => d.type != EdgeType.Link);
@ -231,13 +235,7 @@ updateForces = () => {
let map = getNodeMap();
edges = edges.filter(d => map.get(d.source) && map.get(d.target));
// Recalculate orphans
nodes = nodes.map(d => {
d.sourceCnt = edges.filter(it => it.source == d.id).length;
d.targetCnt = edges.filter(it => it.target == d.id).length;
d.isOrphan = !d.sourceCnt && !d.targetCnt;
return d;
});
//updateOrphans();
// Filter orphans
if (!settings.orphan) {
@ -305,6 +303,13 @@ updateTheme = ({ theme }) => {
redraw();
};
updateOrphans = () => {
nodes = nodes.map(d => {
d.isOrphan = !!!edges.find(it => (it.source == d.id) || (it.target == d.id));
return d;
});
};
draw = (t) => {
const radius = 5.7 / transform.k;