Skip to content

Commit d88a920

Browse files
DHFPROD-7893: Excess white space in graph modeling view
1 parent 8279b59 commit d88a920

File tree

1 file changed

+33
-3
lines changed
  • marklogic-data-hub-central/ui/src/components/modeling/graph-view/graph-vis

1 file changed

+33
-3
lines changed

marklogic-data-hub-central/ui/src/components/modeling/graph-view/graph-vis/graph-vis.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const GraphVis: React.FC<Props> = (props) => {
8181
const initNetworkInstance = (networkInstance) => {
8282
setNetwork(networkInstance);
8383
};
84+
const [networkHeight, setNetworkHeight] = useState(graphConfig.defaultOptions.height);
8485
const vis = require("vis-network/standalone/umd/vis-network"); //eslint-disable-line @typescript-eslint/no-unused-vars
8586

8687
// Load coords *once* on init
@@ -99,6 +100,9 @@ const GraphVis: React.FC<Props> = (props) => {
99100
}
100101
setCoords(newCoords);
101102
setCoordsLoaded(true);
103+
if (network) {
104+
updateNetworkHeight();
105+
}
102106
} else {
103107
setGraphData({
104108
nodes: getNodes(),
@@ -115,6 +119,25 @@ const GraphVis: React.FC<Props> = (props) => {
115119
}
116120
}, [network, modelingOptions.view]);
117121

122+
const updateNetworkHeight = async () => {
123+
let baseHeight = Math.round(window.innerHeight-network.body.container.offsetTop);
124+
if (window.devicePixelRatio < 2) {
125+
baseHeight = Math.round(window.innerHeight-(network.body.container.offsetTop * window.devicePixelRatio));
126+
}
127+
let height = (baseHeight < 505 ? 505 : baseHeight) + "px";
128+
setNetworkHeight(height);
129+
};
130+
131+
useLayoutEffect(() => {
132+
const updateSize = _.debounce(() => {
133+
updateNetworkHeight();
134+
}, 400);
135+
if (network) {
136+
window.addEventListener("resize", updateSize);
137+
}
138+
return () => window.removeEventListener("resize", updateSize);
139+
}, [network && window.innerHeight && window.devicePixelRatio]);
140+
118141
// Initialize or update graph
119142
useEffect(() => {
120143
if (props.entityTypes) {
@@ -129,9 +152,14 @@ const GraphVis: React.FC<Props> = (props) => {
129152
edges: getEdges()
130153
});
131154

155+
const updateGraphSettings = async () => {
156+
await updateNetworkHeight();
157+
initializeScaleAndViewPosition();
158+
};
159+
132160
//Initialize graph zoom scale and view position
133161
if (network) {
134-
initializeScaleAndViewPosition();
162+
updateGraphSettings();
135163
}
136164
//setSaveAllCoords(true);
137165
return () => {
@@ -519,6 +547,7 @@ const GraphVis: React.FC<Props> = (props) => {
519547

520548
const options = {
521549
...graphConfig.defaultOptions,
550+
height: networkHeight,
522551
layout: {
523552
//hierarchical: true
524553
//randomSeed: "0.7696:1625099255200",
@@ -527,7 +556,8 @@ const GraphVis: React.FC<Props> = (props) => {
527556
enabled: physicsEnabled,
528557
barnesHut: {
529558
springLength: 160,
530-
avoidOverlap: 0.4
559+
springConstant: 1,
560+
avoidOverlap: 1
531561
},
532562
stabilization: {
533563
enabled: true,
@@ -564,7 +594,7 @@ const GraphVis: React.FC<Props> = (props) => {
564594
setContextMenuVisible(false);
565595
if (event.key === "1") {
566596
if (network) {
567-
await network.focus(clickedNode);
597+
await network.focus(clickedNode, {offset: {x: 0, y: (modelingOptions.selectedEntity ? -200 : -60)}});
568598
let viewPosition: any = await network.getViewPosition();
569599
setClickedNode(undefined);
570600
let viewPositionPayload = defaultHubCentralConfig;

0 commit comments

Comments
 (0)