Skip to content

Commit afb0cdf

Browse files
authored
Merge pull request #258 from epam/power_bi_dimensions-fix
PowerBI report size fix
2 parents 4fdefaf + d5a78ed commit afb0cdf

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

modules/quanthub_core/js/qh_core-power-bi-customizer.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
const INTERVAL_TIME = 30 * 1000;
22
const TIME_TO_UPDATE = 2 * 60 * 1000;
33

4+
const debounceCallback = (callback, wait) => {
5+
let timeoutId = null;
6+
return (...args) => {
7+
window.clearTimeout(timeoutId);
8+
timeoutId = window.setTimeout(() => {
9+
callback(...args);
10+
}, wait);
11+
};
12+
}
13+
414
function applyLocaleBookmark(context) {
515
context.report.bookmarksManager.getBookmarks()
616
.then(bookmarks => bookmarks.forEach(bm => {
@@ -55,10 +65,21 @@ function powerbi_embed_customizeReport($, context, width = 0, height = 0, title
5565
}
5666
iframes[i].title = title.length > 0 ? title : 'PowerBI Embed';
5767
iframes[i].name = name.length > 0 ? name : title.length > 0 ? title : 'PowerBI Embed';
68+
69+
const containerWidth = iframes[i].parentNode.offsetWidth;
70+
const defaultAspectRatio = (19 / 32);
71+
5872
const iw = width <= 0 ? '100%' : width + 'px';
59-
const ih = height <= 0 ? iw * (19 / 32) : height;
73+
const ih = (height <= 0 || width <= 0? containerWidth * defaultAspectRatio : height) + 'px';
74+
6075
iframes[i].width = iw;
61-
iframes[i].height = ih + 'px';
76+
iframes[i].height = ih;
77+
78+
const onContainerResize = debounceCallback(() => {
79+
iframes[i].height = iframes[i].parentNode.offsetWidth * defaultAspectRatio + 'px';
80+
}, 500)
81+
82+
new ResizeObserver(onContainerResize).observe(iframes[i].parentNode);
6283
}
6384

6485
checkTokenAndUpdate($, context);

0 commit comments

Comments
 (0)