Skip to content

Commit 0c820d2

Browse files
committed
[layout] fixed node for FA2
1 parent 45e2ff6 commit 0c820d2

4 files changed

Lines changed: 28 additions & 3 deletions

File tree

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: 1 },
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
@@ -9,7 +9,7 @@ import { graphDatasetActions, graphDatasetAtom, sigmaGraphAtom } from "../graph"
99
import { dataGraphToFullGraph } from "../graph/utils";
1010
import { resetCamera } from "../sigma";
1111
import { LAYOUTS } from "./collection";
12-
import { LayoutMapping, LayoutQuality, LayoutState } from "./types";
12+
import { type Layout, LayoutMapping, LayoutQuality, LayoutState } from "./types";
1313

1414
function getEmptyLayoutState(): LayoutState {
1515
return { quality: { enabled: false, showGrid: true }, type: "idle" };
@@ -34,7 +34,7 @@ export const layoutStateAtom = atom<LayoutState>(getLocalStorageLayoutState());
3434
* Actions:
3535
* ********
3636
*/
37-
export const startLayout = asyncAction(async (id: string, params: unknown) => {
37+
export const startLayout = asyncAction(async (id: Layout["id"], params: Record<string, unknown>) => {
3838
const { setNodePositions } = graphDatasetActions;
3939
const dataset = graphDatasetAtom.get();
4040

@@ -62,7 +62,19 @@ export const startLayout = asyncAction(async (id: string, params: unknown) => {
6262

6363
// Async layout
6464
if (layout && layout.type === "worker") {
65-
const worker = new layout.supervisor(sigmaGraphAtom.get(), { settings: params });
65+
const graph = sigmaGraphAtom.get();
66+
67+
// If layout parameter has a `getNodeFixedAttribut`, then we have to set the 'fixed'
68+
// attribut in sigma's graph
69+
if ("getNodeFixedAttribut" in params && params.getNodeFixedAttribut) {
70+
const fixedAttribut = `${params.getNodeFixedAttribut}`;
71+
graph.updateEachNodeAttributes((id, attrs) => ({
72+
...attrs,
73+
fixed: dataset.nodeData[id][fixedAttribut] === true,
74+
}));
75+
}
76+
77+
const worker = new layout.supervisor(graph, { settings: params });
6678
worker.start();
6779
layoutStateAtom.set((prev) => ({ ...prev, type: "running", layoutId: id, supervisor: worker }));
6880
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@
534534
"description": "Influence of the edge’s weights on the layout",
535535
"title": "Edge weight influence"
536536
},
537+
"getNodeFixedAttribut": {
538+
"title": "Attribute indicating whether the node’s position is fixed"
539+
},
537540
"gravity": {
538541
"description": "Strength of the layout’s gravity",
539542
"title": "Gravity"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@
609609
"description": "Influence des poids des liens sur la spatialisation",
610610
"title": "Influence du poids des liens"
611611
},
612+
"getNodeFixedAttribut": {
613+
"title": "Attribut indiquant si la position du nœud est fixée"
614+
},
612615
"gravity": {
613616
"description": "Intensité de la gravité de la spatialisation",
614617
"title": "Gravité"

0 commit comments

Comments
 (0)