Skip to content

Commit 1c22f18

Browse files
committed
Setup layout
1 parent 3302164 commit 1c22f18

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

src/js/panel._utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ window.Widgets.Panel.Utils = {};
8585
layout: {
8686
left: 20,
8787
top: 20,
88-
distanceX: 100,
89-
distanceY: 100
88+
distanceX: 200,
89+
distanceY: 200
9090
},
9191
boxSize: 10,
9292
tree_edge_thickness: 0.75,
9393
graph_edge_thickness: 1,
9494
linkStrength: 200,
9595
nodeStrength: -100,
9696
centreStrength: 80,
97-
promoSim: false,
97+
promoSim: true,
9898
theme: 'light',
9999
light_theme: {
100100
treeFill: 'white',
@@ -358,7 +358,7 @@ window.Widgets.Panel.Utils = {};
358358
//Is it the head object?
359359
if (node.id === annotate.id) {
360360
// Its the top level object
361-
node.positionX = annotate.centreX;
361+
node.positionX = annotate.centreX ;
362362
node.positionY = annotate.topY;
363363
// return node;
364364
} else {

src/js/panel.promo.js

+40-9
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ window.Widgets.Panel.Promo = {}
6060

6161

6262
ns.promotable_sim = d3
63-
.forceSimulation()
63+
.forceSimulation(panelUtilsNs.split.promo.nodes)
6464
.force("link", d3.forceLink() // This force provides links between nodes
6565
.id(d => d.id) // This sets the node id accessor to the specified function. If not specified, will default to the index of a node.
6666
// .distance(500 * ns.options.icon_size)
@@ -203,18 +203,49 @@ window.Widgets.Panel.Promo = {}
203203
}); //use simulation.on to listen for tick events as the simulation runs.
204204

205205
// This function is run at each iteration of the force algorithm, updating the nodes position (the nodes data array is directly manipulated).
206-
ns.promotable_sim.force("link")
207-
.links(panelUtilsNs.split.promo.edges)
208-
.id(d => d.id)
209-
.distance(function() {return 5 * ns.options.icon_size;});
206+
// ns.promotable_sim;
210207

211208
// Setup either the Layout, or Default Force Graph
212-
if (ns.options.promoSim) {
213-
ns.promotable_sim
214-
.force("charge", d3.forceManyBody().strength(-500)) // This adds repulsion (if it's negative) between nodes.
215-
// .force("charge", d3.forceManyBody().strength(-500)) // This adds repulsion (if it's negative) between nodes.
209+
if (ns.options.promoSim) {
210+
211+
212+
213+
ns.promotable_sim
214+
.force("link")
215+
.links(panelUtilsNs.split.promo.edges)
216+
.id(d => d.id)
217+
.distance(function() {return 4 * ns.options.icon_size;})
218+
.strength(0.05);
219+
220+
ns.promotable_sim
221+
.force('x', d3.forceX().x(function(d) {
222+
return d.positionX;
223+
}).strength(function(d) {
224+
// ignore forceX below the first two layers
225+
if (d.positionX === 0) {
226+
return 0;
227+
} else {
228+
return 1;
229+
}
230+
}))
231+
.force('y', d3.forceY().y(function(d) {
232+
return d.positionY;
233+
}).strength(1))
234+
// .force('collision', d3.forceCollide().radius(function(d) {
235+
// console.log("d is ->", d)
236+
// return d.radius;
237+
// }))
238+
.force("collide", d3.forceCollide(ns.options.icon_size))
239+
// .force("charge", d3.forceManyBody().strength(-200)) // This adds repulsion (if it's negative) between nodes.
240+
.force("charge", d3.forceManyBody().strength(-500)) // This adds repulsion (if it's negative) between nodes.
216241
// .force("center", d3.forceCenter(ns.options.width / 2, ns.options.height / 2)); // This force attracts nodes to the center of the svg area
217242
} else {
243+
ns.promotable_sim
244+
.force("link")
245+
.links(panelUtilsNs.split.promo.edges)
246+
.id(d => d.id)
247+
.distance(function() {return 1.5 * ns.options.icon_size;});
248+
218249
ns.promotable_sim
219250
.force("charge", d3.forceManyBody().strength(-500)) // This adds repulsion (if it's negative) between nodes.
220251
.force("center", d3.forceCenter(ns.options.width / 2, ns.options.height / 2)); // This force attracts nodes to the center of the svg area

src/js/panel.scratch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ window.Widgets.Panel.Scratch = {}
5959
}
6060

6161
ns.scratch_sim = d3
62-
.forceSimulation()
62+
.forceSimulation(panelUtilsNs.split.promo.nodes)
6363
// .on('end', function() {
6464
// console.log(this);
6565
// console.log(["scratch_sim",this]);

0 commit comments

Comments
 (0)