Skip to content

Commit 0fa0176

Browse files
authored
[Graph-] Added forces panel (#1554)
1 parent d312eca commit 0fa0176

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

packages/foam-vscode/static/dataviz/graph.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
body {
22
overflow: hidden;
33
}
4-
/*
5-
[INFO] Custom width rules for dat.GUI controls (10% for controls, 90% for labels) were intentionally removed.
6-
This change was made to better accommodate new sliders, and to use dat.GUI's default proportions, which allocate more space to controls. If you notice any display issues (especially with type filter checkboxes), please verify in both light and dark VS Code themes.
7-
*/
84

95
.vscode-light .dg.main.taller-than-window .close-button {
106
border-top: 1px solid #ddd;

packages/foam-vscode/static/dataviz/graph.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@ const initGUI = () => {
44
const gui = new dat.gui.GUI();
55
const nodeTypeFilterFolder = gui.addFolder('Filter by type');
66
const nodeTypeFilterControllers = new Map();
7+
const forcesFolder = gui.addFolder('Forces');
8+
9+
forcesFolder
10+
.add(model.forces, 'collide', 0, 4)
11+
.step(0.1)
12+
.name('Collide Force')
13+
.onFinishChange(v => {
14+
graph.d3Force('collide').radius(graph.nodeRelSize() * v);
15+
graph.d3ReheatSimulation();
16+
});
17+
forcesFolder
18+
.add(model.forces, 'repel', 0, 200)
19+
.name('Repel Force')
20+
.onFinishChange(v => {
21+
model.forces.charge = -v;
22+
graph.d3Force('charge').strength(-v);
23+
graph.d3ReheatSimulation();
24+
});
25+
forcesFolder
26+
.add(model.forces, 'link', 0, 100)
27+
.step(1)
28+
.name('Link Distance')
29+
.onFinishChange(v => {
30+
graph.d3Force('link').distance(v);
31+
graph.d3ReheatSimulation();
32+
});
33+
forcesFolder
34+
.add(model.forces, 'velocityDecay', 0, 1)
35+
.step(0.01)
36+
.name('Velocity Decay')
37+
.onChange(v => {
38+
graph.d3VelocityDecay(1 - v);
39+
});
740
const selectionFolder = gui.addFolder('Selection');
841

942
selectionFolder
@@ -103,7 +136,13 @@ let model = {
103136
note: true,
104137
tag: true,
105138
},
106-
139+
forces: {
140+
collide: 2,
141+
repel: 30,
142+
charge: -30,
143+
link: 30,
144+
velocityDecay: 0.4,
145+
},
107146
selection: {
108147
neighborDepth: 1,
109148
enableRefocus: true,
@@ -240,7 +279,13 @@ function initDataviz(channel) {
240279
.linkHoverPrecision(8)
241280
.d3Force('x', d3.forceX())
242281
.d3Force('y', d3.forceY())
243-
.d3Force('collide', d3.forceCollide(graph.nodeRelSize()))
282+
.d3Force(
283+
'collide',
284+
d3.forceCollide(graph.nodeRelSize() * model.forces.collide)
285+
)
286+
.d3Force('charge', d3.forceManyBody().strength(model.forces.charge))
287+
.d3Force('link', d3.forceLink(model.data.links).distance(model.forces.link))
288+
.d3VelocityDecay(1 - model.forces.velocityDecay)
244289
.linkWidth(() => model.style.lineWidth)
245290
.linkDirectionalParticles(1)
246291
.linkDirectionalParticleWidth(link =>
@@ -404,6 +449,7 @@ function updateForceGraphDataFromModel(m) {
404449

405450
// annoying we need to call this function, but I haven't found a good workaround
406451
graph.graphData(m.data);
452+
graph.d3Force('link').links(m.data.links);
407453
}
408454

409455
const getNodeSize = d3

0 commit comments

Comments
 (0)