Skip to content

Commit e4adb3e

Browse files
committed
WIP
1 parent b7405bb commit e4adb3e

File tree

1 file changed

+20
-0
lines changed
  • scala3doc/resources/dotty_res/scripts

1 file changed

+20
-0
lines changed

scala3doc/resources/dotty_res/scripts/ux.js

+20
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ function showGraph() {
8585
});
8686
});
8787
render(inner, g);
88+
89+
// Set the 'fit to content graph' upon landing on the page
90+
91+
var bounds = svg.node().getBBox();
92+
var parent = svg.node().parentElement;
93+
var fullWidth = parent.clientWidth || parent.parentNode.clientWidth,
94+
fullHeight = parent.clientHeight || parent.parentNode.clientHeight;
95+
var width = bounds.width,
96+
height = bounds.height;
97+
var midX = bounds.x + width / 2,
98+
midY = bounds.y + height / 2;
99+
if (width == 0 || height == 0) return; // nothing to fit
100+
var scale = 0.85 / Math.max(width / fullWidth, height / fullHeight);
101+
var translate = [fullWidth / 2 - scale * midX, fullHeight / 2 - scale * midY];
102+
103+
var transform = d3.zoomIdentity
104+
.translate(translate[0], translate[1])
105+
.scale(scale);
106+
107+
svg.call(zoom.transform, transform);
88108
}
89109
}
90110
}

0 commit comments

Comments
 (0)