Skip to content

Commit 21da56c

Browse files
Folder unfold behavior change to a single-click, folding improvements and fixes
1 parent 9998524 commit 21da56c

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
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.7.5",
3+
"version": "0.7.6",
44
"description": "Visualizer for iKnow entities",
55
"main": "gulpfile.babel.js",
66
"scripts": {

src/static/js/graph/index.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { onModelUpdate, unfold, dropNodesm, uiState } from "../model";
1+
import { onModelUpdate, unfold, dropNodes, uiState } from "../model";
22
import { updateSelection, selectAll, deselectAll } from "../selection";
33

44
let shiftKey, ctrlKey,
@@ -250,20 +250,23 @@ export function update (g = lastGraph, reset = false) {
250250
.attr("class", d => `node${ d.id === 0 ? " root" : "" } ${ d.type || "unknown" }`)
251251
.classed("selected", (p) => p.selected)
252252
.call(dragger)
253-
.on("dblclick", function (d) {
254-
if (d.type !== "folder")
253+
.on("click", function (d) {
254+
if (d.type === "folder") {
255+
d3.event.stopPropagation();
256+
let left;
257+
if (d.parent && (left = unfold(d, d.parent))) {
258+
d.fx = d.x; d.fy = d.y;
259+
if (d._clickTimeout) clearTimeout(d._clickTimeout);
260+
d._clickTimeout = setTimeout(() => {
261+
d.fx = d.fy = null;
262+
d._clickTimeout = 0;
263+
}, 1000);
264+
}
265+
if (left === 0) {
266+
dropNodes(d);
267+
}
255268
return;
256-
d3.event.stopPropagation();
257-
let left;
258-
if (d.parent && (left = unfold(d, d.parent))) {
259-
d.fx = d.x; d.fy = d.y;
260-
setTimeout(() => d.fx = d.fy = null, 1000);
261-
}
262-
if (left === 0) {
263-
dropNodes(d);
264269
}
265-
})
266-
.on("click", function (d) {
267270
if (d3.event.defaultPrevented) return;
268271
if (shiftKey) {
269272
if (d.selected)
@@ -291,7 +294,7 @@ export function update (g = lastGraph, reset = false) {
291294
.classed("tooltip", () => true)
292295
.attr("dy", "-0.7em")
293296
.attr("style", d => `font-size:${ Math.round(d.radius / 2) }px`)
294-
.text(d => `Double-click to display more`);
297+
.text(d => `Click to display more`);
295298
});
296299
node = nodeEnter.merge(node);
297300

src/static/js/model/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,23 @@ export function init () {
181181
dataUpdated(true);
182182
}
183183

184-
function resetChildrenPosition (parent, children = []) {
184+
function resetChildrenPosition (folder, children = []) {
185185
if (!children || !children.length)
186186
return;
187-
for (let c of children) {
188-
c.x = parent.x;
189-
c.y = parent.y;
187+
let xd = folder.x - folder.parent.x,
188+
yd = folder.y - folder.parent.y,
189+
angle = Math.atan2(yd, xd),
190+
d = Math.sqrt(xd * xd + yd * yd),
191+
spread = Math.PI / 2;
192+
for (let i = 0; i < children.length; i++) {
193+
let c = children[i],
194+
spd = - spread / 2 + spread * i / (children.length - 1 || 0.5),
195+
dx = Math.cos(angle + spd) * d,
196+
dy = Math.sin(angle + spd) * d;
197+
c.x = folder.parent.x + dx || 0;
198+
c.y = folder.parent.y + dy || 0;
190199
if (c.children)
191-
resetChildrenPosition(c, c.children);
200+
resetChildrenPosition({ x: c.x + dx, y: c.y + dy, parent: { x: c.x, y: c.y } }, c.children);
192201
}
193202
}
194203

@@ -266,7 +275,7 @@ export function unfold (folderNode, node, children = 20) {
266275
folderNode.id = newId;
267276
node.children = node.children.concat(next);
268277
folderNode.label = left > 0 ? `${ left } more` : `Others`;
269-
resetChildrenPosition(node, next);
278+
resetChildrenPosition(folderNode, next);
270279
dataUpdated();
271280
return {
272281
unfolded: next.length,

0 commit comments

Comments
 (0)