Skip to content

Commit bfe352d

Browse files
committed
[layout] fixed node for FA2
1 parent a13db8a commit bfe352d

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

packages/gephi-lite/src/core/layouts/collection/forceAtlas2.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,12 @@ export const ForceAtlas2Layout = {
7676
},
7777
{ id: "slowDown", type: "number", defaultValue: FA2_DEFAULT_SETTINGS.slowDown, min: 1, step:"any"},
7878
{ id: "strongGravityMode", type: "boolean", defaultValue: FA2_DEFAULT_SETTINGS.strongGravityMode },
79+
{
80+
id: "getNodeFixedAttribut",
81+
type: "attribute",
82+
itemType: "nodes",
83+
restriction: ["boolean"],
84+
required: false,
85+
},
7986
],
8087
} as WorkerLayout<ForceAtlas2LayoutParameters>;

packages/gephi-lite/src/core/layouts/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { dataGraphToFullGraph } from "../graph/utils";
1010
import { sessionAtom } from "../session";
1111
import { resetCamera } from "../sigma";
1212
import { LAYOUTS } from "./collection";
13-
import { LayoutMapping, LayoutQuality, LayoutState } from "./types";
13+
import { type Layout, LayoutMapping, LayoutQuality, LayoutState } from "./types";
1414

1515
function getEmptyLayoutState(): LayoutState {
1616
return { quality: { enabled: false, showGrid: true }, type: "idle" };
@@ -59,10 +59,11 @@ export const stopLayout = asyncAction(async (isForRestart = false) => {
5959
if (!isForRestart) layoutStateAtom.set((prev) => ({ ...prev, type: "idle" }));
6060
});
6161

62-
export const startLayout = asyncAction(async (id: string, params: unknown, isForRestart = false) => {
62+
export const startLayout = asyncAction(async (id: string, params: Record<string, unknown>, isForRestart = false) => {
6363
// Stop the previous algo (the "if needed" is done in the function itself)
6464
await stopLayout(isForRestart);
6565

66+
const dataset = graphDatasetAtom.get();
6667
const { setNodePositions } = graphDatasetActions;
6768

6869
// search the layout
@@ -74,7 +75,6 @@ export const startLayout = asyncAction(async (id: string, params: unknown, isFor
7475
layoutStateAtom.set((prev) => ({ ...prev, type: "running", layoutId: id, supervisor: undefined }));
7576

7677
// generate positions
77-
const dataset = graphDatasetAtom.get();
7878
const fullGraph = dataGraphToFullGraph(dataset);
7979
const positions = layout.run(fullGraph, { settings: params });
8080

@@ -91,6 +91,18 @@ export const startLayout = asyncAction(async (id: string, params: unknown, isFor
9191

9292
// Async layout
9393
if (layout.type === "worker") {
94+
const graph = sigmaGraphAtom.get();
95+
96+
// If layout parameter has a `getNodeFixedAttribut`, then we have to set the 'fixed'
97+
// attribut in sigma's graph
98+
if ("getNodeFixedAttribut" in params && params.getNodeFixedAttribut) {
99+
const fixedAttribut = `${params.getNodeFixedAttribut}`;
100+
graph.updateEachNodeAttributes((id, attrs) => ({
101+
...attrs,
102+
fixed: dataset.nodeData[id][fixedAttribut] === true,
103+
}));
104+
}
105+
94106
const worker = new layout.supervisor(sigmaGraphAtom.get(), { settings: params });
95107
worker.start();
96108
layoutStateAtom.set((prev) => ({ ...prev, type: "running", layoutId: id, supervisor: worker }));

packages/gephi-lite/src/locales/dev.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@
539539
"description": "Influence of the edge’s weights on the layout",
540540
"title": "Edge weight influence"
541541
},
542+
"getNodeFixedAttribut": {
543+
"title": "Attribute indicating whether the node’s position is fixed"
544+
},
542545
"gravity": {
543546
"description": "Strength of the layout’s gravity",
544547
"title": "Gravity"

packages/gephi-lite/src/locales/fr.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,9 @@
613613
"description": "Influence des poids des liens sur la spatialisation",
614614
"title": "Influence du poids des liens"
615615
},
616+
"getNodeFixedAttribut": {
617+
"title": "Attribut indiquant si la position du nœud est fixée"
618+
},
616619
"gravity": {
617620
"description": "Intensité de la gravité de la spatialisation",
618621
"title": "Gravité"

0 commit comments

Comments
 (0)