Skip to content

Commit 8d3c263

Browse files
Focusing on the node when clicking node row in the table view
1 parent 13e56f9 commit 8d3c263

File tree

3 files changed

+26
-8
lines changed

3 files changed

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

src/static/js/graph/index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,44 @@ let currentZoomLevel = 1,
5252
}),
5353
view = null;
5454

55+
window.addEventListener("resize", () => {
56+
width = window.innerWidth;
57+
height = window.innerHeight;
58+
});
59+
5560
export function translateBy (x = 0, y = 0) {
5661
svg.transition()
5762
.duration(300)
5863
.call(zoomer.translateBy, x / currentZoomLevel, y / currentZoomLevel);
5964
}
6065

66+
export function focusOn (x = 0, y = 0) {
67+
console.log(x, y);
68+
svg.transition()
69+
.duration(300)
70+
.call(
71+
zoomer.transform,
72+
d3.zoomIdentity.translate(width / 2 + getViewDX(), height / 2)
73+
.scale(currentZoomLevel).translate(-x, -y)
74+
);
75+
}
76+
6177
export function scaleBy (delta = 1) {
6278
svg.transition()
6379
.duration(300)
6480
.call(zoomer.scaleBy, delta);
6581
}
6682

83+
function getViewDX () {
84+
return uiState.tabularToggled
85+
? - document.getElementById("table").getBoundingClientRect().width / 2
86+
: 0;
87+
}
88+
6789
export function resetZoom () {
6890
svg.transition()
6991
.duration(300)
70-
.call(zoomer.transform, d3.zoomIdentity.translate(
71-
uiState.tabularToggled
72-
? - document.getElementById("table").getBoundingClientRect().width / 2
73-
: 0,
74-
0)
75-
);
92+
.call(zoomer.transform, d3.zoomIdentity.translate(getViewDX(), 0));
7693
}
7794

7895
export function updateSelected () {

src/static/js/tabular/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "../selection";
66
import { getOption } from "../settings/values";
77
import { getObjProp } from "../utils";
8-
import { translateBy } from "../graph";
8+
import { translateBy, focusOn } from "../graph";
99

1010
let sorting = {
1111
properties: ["entities", "0", "frequency"],
@@ -76,6 +76,7 @@ function insertRows (data, table, selected) {
7676
if (node.children.length) cell.appendChild(ei);
7777
row.addEventListener("mouseover", () => { node.element.classList.add("highlighted"); });
7878
row.addEventListener("mouseout", () => { node.element.classList.remove("highlighted"); });
79+
row.addEventListener("click", () => focusOn(node.x, node.y));
7980
}
8081
}
8182

0 commit comments

Comments
 (0)