Skip to content

Commit ee26dcf

Browse files
Children nodes better position when expanding
1 parent 44227d1 commit ee26dcf

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iknow-entity-browser",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {

src/static/js/graph/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let svg = null,
3030
d3.forceManyBody()
3131
.strength(d => { return -10 * d.radius; })
3232
)
33-
.force("center", d3.forceCenter(width / 2, height / 2)),
33+
.force("center", d3.forceCenter(width / 2, height / 2))
34+
.on("tick", ticked),
3435
brusher = d3.brush()
3536
.extent([[-9999999, -9999999], [9999999, 9999999]])
3637
.on("start.brush", () => {
@@ -61,6 +62,8 @@ let svg = null,
6162
view = null;
6263

6364
function ticked () {
65+
if (!link)
66+
return;
6467
link
6568
.attr("x1", d => d.source.x)
6669
.attr("y1", d => d.source.y)
@@ -165,6 +168,17 @@ function flattenEdges (root) {
165168

166169
}
167170

171+
function resetChildrenPosition (parent, children = []) {
172+
if (!children || !children.length)
173+
return;
174+
for (let c of children) {
175+
c.x = parent.x;
176+
c.y = parent.y;
177+
if (c.children)
178+
resetChildrenPosition(c, c.children);
179+
}
180+
}
181+
168182
export function update (reset = false) {
169183

170184
let g = getGraphData().foldedTree,
@@ -195,6 +209,7 @@ export function update (reset = false) {
195209
if (d.type === "folder" && d._children && d._children.length) {
196210
let next = d._children.splice(0, 20),
197211
left = parseInt(d.label) - 20;
212+
resetChildrenPosition(d, next);
198213
d.children = d.children.concat(next);
199214
d.label = left > 0 ? `${ left } more` : `Others`;
200215
d3.select(this).select("text").text(d.label);
@@ -222,9 +237,6 @@ export function update (reset = false) {
222237

223238
simulation
224239
.nodes(graph.nodes)
225-
.on("tick", ticked);
226-
227-
simulation
228240
.force("link")
229241
.links(graph.edges);
230242

0 commit comments

Comments
 (0)